|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "f2e5a85d-c710-492b-a4fc-09b45ae26471", |
| 7 | + "metadata": { |
| 8 | + "tags": [ |
| 9 | + "hide" |
| 10 | + ] |
| 11 | + }, |
| 12 | + "outputs": [], |
| 13 | + "source": [ |
| 14 | + "import seaborn.objects as so\n", |
| 15 | + "from seaborn import load_dataset\n", |
| 16 | + "penguins = load_dataset(\"penguins\")" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "raw", |
| 21 | + "id": "14b5927c-42f1-4934-adee-3d380b8b3228", |
| 22 | + "metadata": {}, |
| 23 | + "source": [ |
| 24 | + "When used without any arguments, a small amount of jitter will be applied along the orientation axis:" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "code", |
| 29 | + "execution_count": null, |
| 30 | + "id": "bc1b4941-bbe6-4afc-b51a-0ac67cbe417d", |
| 31 | + "metadata": {}, |
| 32 | + "outputs": [], |
| 33 | + "source": [ |
| 34 | + "(\n", |
| 35 | + " so.Plot(penguins, \"species\", \"body_mass_g\")\n", |
| 36 | + " .add(so.Dots(), so.Jitter())\n", |
| 37 | + ")" |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "cell_type": "raw", |
| 42 | + "id": "1101690e-6c19-4219-aa4e-180798454df1", |
| 43 | + "metadata": {}, |
| 44 | + "source": [ |
| 45 | + "The `width` parameter controls the amount of jitter relative to the spacing between the marks:" |
| 46 | + ] |
| 47 | + }, |
| 48 | + { |
| 49 | + "cell_type": "code", |
| 50 | + "execution_count": null, |
| 51 | + "id": "c4251b9d-8b11-4c2c-905c-2f3b523dee70", |
| 52 | + "metadata": {}, |
| 53 | + "outputs": [], |
| 54 | + "source": [ |
| 55 | + "(\n", |
| 56 | + " so.Plot(penguins, \"species\", \"body_mass_g\")\n", |
| 57 | + " .add(so.Dots(), so.Jitter(.5))\n", |
| 58 | + ")" |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + "cell_type": "raw", |
| 63 | + "id": "38aa639a-356e-4674-970b-53d55379b2b7", |
| 64 | + "metadata": {}, |
| 65 | + "source": [ |
| 66 | + "The `width` parameter always applies to the orientation axis, so the direction of jitter will adapt along with the orientation:" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": null, |
| 72 | + "id": "1cfe1c07-7e81-45a0-a989-240503046133", |
| 73 | + "metadata": {}, |
| 74 | + "outputs": [], |
| 75 | + "source": [ |
| 76 | + "(\n", |
| 77 | + " so.Plot(penguins, \"body_mass_g\", \"species\")\n", |
| 78 | + " .add(so.Dots(), so.Jitter(.5))\n", |
| 79 | + ")" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "raw", |
| 84 | + "id": "0f5de4cc-3383-4503-8b59-9c48230a12a5", |
| 85 | + "metadata": {}, |
| 86 | + "source": [ |
| 87 | + "Because the `width` jitter is relative, it can be used when the orientation axis is numeric without further tweaking:" |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + "cell_type": "code", |
| 92 | + "execution_count": null, |
| 93 | + "id": "c94c41e8-29c4-4439-a5d1-0b8ffb244890", |
| 94 | + "metadata": {}, |
| 95 | + "outputs": [], |
| 96 | + "source": [ |
| 97 | + "(\n", |
| 98 | + " so.Plot(penguins[\"body_mass_g\"].round(-3), penguins[\"flipper_length_mm\"])\n", |
| 99 | + " .add(so.Dots(), so.Jitter())\n", |
| 100 | + ")" |
| 101 | + ] |
| 102 | + }, |
| 103 | + { |
| 104 | + "cell_type": "raw", |
| 105 | + "id": "dd982dfa-fd9f-4edc-8190-18f0e101ae1a", |
| 106 | + "metadata": {}, |
| 107 | + "source": [ |
| 108 | + "In contrast to `width`, the `x` and `y` parameters always refer to specific axes and control the jitter in data units:" |
| 109 | + ] |
| 110 | + }, |
| 111 | + { |
| 112 | + "cell_type": "code", |
| 113 | + "execution_count": null, |
| 114 | + "id": "b0f2e5ca-68ad-4439-a4ee-f32f65682e95", |
| 115 | + "metadata": {}, |
| 116 | + "outputs": [], |
| 117 | + "source": [ |
| 118 | + "(\n", |
| 119 | + " so.Plot(penguins[\"body_mass_g\"].round(-3), penguins[\"flipper_length_mm\"])\n", |
| 120 | + " .add(so.Dots(), so.Jitter(x=100))\n", |
| 121 | + ")" |
| 122 | + ] |
| 123 | + }, |
| 124 | + { |
| 125 | + "cell_type": "raw", |
| 126 | + "id": "a90ba526-8043-42ed-8f57-36445c163c0d", |
| 127 | + "metadata": {}, |
| 128 | + "source": [ |
| 129 | + "Both `x` and `y` can be used in a single transform:" |
| 130 | + ] |
| 131 | + }, |
| 132 | + { |
| 133 | + "cell_type": "code", |
| 134 | + "execution_count": null, |
| 135 | + "id": "6c07ed1d-ac77-4b30-90a8-e1b8760f9fad", |
| 136 | + "metadata": {}, |
| 137 | + "outputs": [], |
| 138 | + "source": [ |
| 139 | + "(\n", |
| 140 | + " so.Plot(\n", |
| 141 | + " penguins[\"body_mass_g\"].round(-3),\n", |
| 142 | + " penguins[\"flipper_length_mm\"].round(-1),\n", |
| 143 | + " )\n", |
| 144 | + " .add(so.Dots(), so.Jitter(x=200, y=5))\n", |
| 145 | + ")" |
| 146 | + ] |
| 147 | + }, |
| 148 | + { |
| 149 | + "cell_type": "code", |
| 150 | + "execution_count": null, |
| 151 | + "id": "bb04c7a2-93f0-44cf-aacf-0eb436d0f14b", |
| 152 | + "metadata": {}, |
| 153 | + "outputs": [], |
| 154 | + "source": [] |
| 155 | + } |
| 156 | + ], |
| 157 | + "metadata": { |
| 158 | + "kernelspec": { |
| 159 | + "display_name": "py310", |
| 160 | + "language": "python", |
| 161 | + "name": "py310" |
| 162 | + }, |
| 163 | + "language_info": { |
| 164 | + "codemirror_mode": { |
| 165 | + "name": "ipython", |
| 166 | + "version": 3 |
| 167 | + }, |
| 168 | + "file_extension": ".py", |
| 169 | + "mimetype": "text/x-python", |
| 170 | + "name": "python", |
| 171 | + "nbconvert_exporter": "python", |
| 172 | + "pygments_lexer": "ipython3", |
| 173 | + "version": "3.10.0" |
| 174 | + } |
| 175 | + }, |
| 176 | + "nbformat": 4, |
| 177 | + "nbformat_minor": 5 |
| 178 | +} |
0 commit comments