Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run black on Notebook examples #1418

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 42 additions & 31 deletions examples/Advanced Plotting/Advanced Plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(title='Multiple Marks')\n",
"fig = plt.figure(title=\"Multiple Marks\")\n",
"\n",
"# create multiple marks. they'll be added to the same figure\n",
"bar_chart = plt.bar([1, 2, 3, 4, 5], [2, 9, 10, 40, 40])\n",
"line_chart = plt.plot([1, 2, 3, 4, 5], [10, 5, 30, 60, 20], 'rs-')\n",
"line_chart = plt.plot([1, 2, 3, 4, 5], [10, 5, 30, 60, 20], \"rs-\")\n",
"\n",
"fig"
]
Expand All @@ -48,8 +48,8 @@
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(title='Histogram')\n",
"hist = plt.hist(sample=np.random.randn(100), bins=10, colors=['orange'])\n",
"fig = plt.figure(title=\"Histogram\")\n",
"hist = plt.hist(sample=np.random.randn(100), bins=10, colors=[\"orange\"])\n",
"fig"
]
},
Expand All @@ -59,7 +59,7 @@
"metadata": {},
"outputs": [],
"source": [
"x_axis = plt.axes()['sample']\n",
"x_axis = plt.axes()[\"sample\"]\n",
"\n",
"# Set the tick values to be the mid points of the bins\n",
"x_axis.tick_values = hist.midpoints"
Expand All @@ -78,7 +78,7 @@
"metadata": {},
"outputs": [],
"source": [
"dates = np.arange('2005-02', '2005-03', dtype='datetime64[D]')\n",
"dates = np.arange(\"2005-02\", \"2005-03\", dtype=\"datetime64[D]\")\n",
"size = len(dates)\n",
"prices = 100 + 5 * np.cumsum(np.random.randn(size))"
]
Expand All @@ -90,10 +90,12 @@
"outputs": [],
"source": [
"fig = plt.figure()\n",
"plt.scales(scales={'y': LogScale()})\n",
"axes_options = {'x': dict(label='Date', grid_lines='dashed', num_ticks=4),\n",
" 'y': dict(label='Log Price', tick_format='0.1f')}\n",
"logline = plt.plot(dates, prices, 'm', axes_options=axes_options)\n",
"plt.scales(scales={\"y\": LogScale()})\n",
"axes_options = {\n",
" \"x\": dict(label=\"Date\", grid_lines=\"dashed\", num_ticks=4),\n",
" \"y\": dict(label=\"Log Price\", tick_format=\"0.1f\"),\n",
"}\n",
"logline = plt.plot(dates, prices, \"m\", axes_options=axes_options)\n",
"fig"
]
},
Expand All @@ -111,7 +113,7 @@
"outputs": [],
"source": [
"fig = plt.figure()\n",
"line = plt.plot(np.arange(100), np.random.randn(100).cumsum(), 'r')\n",
"line = plt.plot(np.arange(100), np.random.randn(100).cumsum(), \"r\")\n",
"fig"
]
},
Expand All @@ -122,8 +124,8 @@
"outputs": [],
"source": [
"## changing the min/max od x scale\n",
"line.scales['x'].min = -10\n",
"line.scales['x'].max = 110"
"line.scales[\"x\"].min = -10\n",
"line.scales[\"x\"].max = 110"
]
},
{
Expand All @@ -142,8 +144,8 @@
"fig = plt.figure()\n",
"x = np.arange(50)\n",
"y = np.cumsum(np.random.randn(50) * 100.0)\n",
"line1 = plt.plot(x, y, 'b')\n",
"line2 = plt.plot(x, y * 2, 'r', preserve_domain={'y': True})\n",
"line1 = plt.plot(x, y, \"b\")\n",
"line2 = plt.plot(x, y * 2, \"r\", preserve_domain={\"y\": True})\n",
"fig"
]
},
Expand All @@ -153,7 +155,7 @@
"metadata": {},
"outputs": [],
"source": [
"line2.preserve_domain={}"
"line2.preserve_domain = {}"
]
},
{
Expand All @@ -173,9 +175,11 @@
"y = np.cumsum(np.random.randn(50) * 100.0)\n",
"\n",
"fig = plt.figure()\n",
"plt.scales(scales={'color': ColorScale(colors=['red', 'white', 'green'], mid=0.0)})\n",
"plt.scales(scales={\"color\": ColorScale(colors=[\"red\", \"white\", \"green\"], mid=0.0)})\n",
"scat1 = plt.scatter(x, y, color=y)\n",
"scat2 = plt.scatter(x, y * 2, color=y * 2, preserve_domain={'color': True}, marker='cross')\n",
"scat2 = plt.scatter(\n",
" x, y * 2, color=y * 2, preserve_domain={\"color\": True}, marker=\"cross\"\n",
")\n",
"fig"
]
},
Expand All @@ -196,8 +200,8 @@
"y = np.cumsum(np.random.randn(50) * 100.0)\n",
"\n",
"fig = plt.figure()\n",
"plt.scales(scales={'x': LinearScale(reverse=True)})\n",
"line = plt.plot(x, y, 'b')\n",
"plt.scales(scales={\"x\": LinearScale(reverse=True)})\n",
"line = plt.plot(x, y, \"b\")\n",
"fig"
]
},
Expand All @@ -218,14 +222,19 @@
"y = np.cumsum(np.random.randn(3, 10), axis=1)\n",
"\n",
"fig = plt.figure()\n",
"axes_options = {'x': dict(set_ticks=True, grid_lines='none'),\n",
" 'y': dict(grid_lines='none')}\n",
"plt.scales(scales={'x': OrdinalScale(domain=list(range(20)))})\n",
"bar_chart = plt.bar(x, y=y, \n",
" colors=['hotpink', 'orange', 'green'],\n",
" labels=['One', 'Two', 'Three'],\n",
" axes_options=axes_options,\n",
" display_legend=True)\n",
"axes_options = {\n",
" \"x\": dict(set_ticks=True, grid_lines=\"none\"),\n",
" \"y\": dict(grid_lines=\"none\"),\n",
"}\n",
"plt.scales(scales={\"x\": OrdinalScale(domain=list(range(20)))})\n",
"bar_chart = plt.bar(\n",
" x,\n",
" y=y,\n",
" colors=[\"hotpink\", \"orange\", \"green\"],\n",
" labels=[\"One\", \"Two\", \"Three\"],\n",
" axes_options=axes_options,\n",
" display_legend=True,\n",
")\n",
"fig"
]
},
Expand All @@ -246,9 +255,11 @@
"y1, y2 = np.random.randn(2, 100).cumsum(axis=1)\n",
"\n",
"fig = plt.figure()\n",
"plt.scales(scales={'x': LinearScale(min=10, max=90)})\n",
"line1 = plt.plot(x, y1, 'r', labels=['Clipped Line'], display_legend=True)\n",
"line2 = plt.plot(x, y2, 'g', apply_clip=False, labels=['Non clipped line'], display_legend=True)\n",
"plt.scales(scales={\"x\": LinearScale(min=10, max=90)})\n",
"line1 = plt.plot(x, y1, \"r\", labels=[\"Clipped Line\"], display_legend=True)\n",
"line2 = plt.plot(\n",
" x, y2, \"g\", apply_clip=False, labels=[\"Non clipped line\"], display_legend=True\n",
")\n",
"fig"
]
}
Expand Down
48 changes: 33 additions & 15 deletions examples/Advanced Plotting/Animations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"metadata": {},
"outputs": [],
"source": [
"axes_options = {'x': {'label': 'x'}, 'y': {'label': 'y'}}"
"axes_options = {\"x\": {\"label\": \"x\"}, \"y\": {\"label\": \"y\"}}"
]
},
{
Expand All @@ -41,10 +41,10 @@
"outputs": [],
"source": [
"x = np.arange(100)\n",
"y = np.cumsum(np.random.randn(2, 100), axis=1) #two random walks\n",
"y = np.cumsum(np.random.randn(2, 100), axis=1) # two random walks\n",
"\n",
"fig = plt.figure(animation_duration=1000)\n",
"lines = plt.plot(x=x, y=y, colors=['red', 'green'], axes_options=axes_options)\n",
"lines = plt.plot(x=x, y=y, colors=[\"red\", \"green\"], axes_options=axes_options)\n",
"fig"
]
},
Expand Down Expand Up @@ -73,7 +73,7 @@
"source": [
"fig = plt.figure(animation_duration=1000)\n",
"x, y = np.random.rand(2, 20)\n",
"scatt = plt.scatter(x, y, colors=['blue'], axes_options=axes_options)\n",
"scatt = plt.scatter(x, y, colors=[\"blue\"], axes_options=axes_options)\n",
"fig"
]
},
Expand All @@ -83,7 +83,7 @@
"metadata": {},
"outputs": [],
"source": [
"#data updates\n",
"# data updates\n",
"scatt.x = np.random.rand(20) * 10\n",
"scatt.y = np.random.rand(20)"
]
Expand All @@ -106,8 +106,15 @@
"data = np.random.rand(6)\n",
"\n",
"fig = plt.figure(animation_duration=1000)\n",
"pie = plt.pie(data, radius=180, sort=False, display_labels='outside', display_values=True,\n",
" values_format='.0%', labels=list('ABCDEFGHIJ'))\n",
"pie = plt.pie(\n",
" data,\n",
" radius=180,\n",
" sort=False,\n",
" display_labels=\"outside\",\n",
" display_values=True,\n",
" values_format=\".0%\",\n",
" labels=list(\"ABCDEFGHIJ\"),\n",
")\n",
"fig"
]
},
Expand Down Expand Up @@ -135,7 +142,7 @@
"metadata": {},
"outputs": [],
"source": [
"#make pie a donut\n",
"# make pie a donut\n",
"with pie.hold_sync():\n",
" pie.radius = 180\n",
" pie.inner_radius = 120"
Expand All @@ -155,7 +162,7 @@
"outputs": [],
"source": [
"n = 10\n",
"x = list('ABCDEFGHIJ')\n",
"x = list(\"ABCDEFGHIJ\")\n",
"y1, y2 = np.random.rand(2, n)"
]
},
Expand All @@ -166,7 +173,7 @@
"outputs": [],
"source": [
"fig = plt.figure(animation_duration=1000)\n",
"bar = plt.bar(x, [y1, y2], padding=0.2, type='grouped')\n",
"bar = plt.bar(x, [y1, y2], padding=0.2, type=\"grouped\")\n",
"fig"
]
},
Expand Down Expand Up @@ -201,12 +208,23 @@
"y = np.cumsum(np.random.randn(20))\n",
"y1 = np.random.rand(20)\n",
"\n",
"line = Lines(x=x, y=y, scales={'x': xs, 'y': ys1}, colors=['magenta'], marker='square')\n",
"bar = Bars(x=x, y=y1, scales={'x': xs, 'y': ys2}, colorpadding=0.2, colors=['steelblue'])\n",
"line = Lines(x=x, y=y, scales={\"x\": xs, \"y\": ys1}, colors=[\"magenta\"], marker=\"square\")\n",
"bar = Bars(\n",
" x=x, y=y1, scales={\"x\": xs, \"y\": ys2}, colorpadding=0.2, colors=[\"steelblue\"]\n",
")\n",
"\n",
"xax = Axis(scale=xs, label='x', grid_lines='solid')\n",
"yax1 = Axis(scale=ys1, orientation='vertical', tick_format='0.1f', label='y', grid_lines='solid')\n",
"yax2 = Axis(scale=ys2, orientation='vertical', side='right', tick_format='0.0%', label='y1', grid_lines='none')\n",
"xax = Axis(scale=xs, label=\"x\", grid_lines=\"solid\")\n",
"yax1 = Axis(\n",
" scale=ys1, orientation=\"vertical\", tick_format=\"0.1f\", label=\"y\", grid_lines=\"solid\"\n",
")\n",
"yax2 = Axis(\n",
" scale=ys2,\n",
" orientation=\"vertical\",\n",
" side=\"right\",\n",
" tick_format=\"0.0%\",\n",
" label=\"y1\",\n",
" grid_lines=\"none\",\n",
")\n",
"\n",
"Figure(marks=[bar, line], axes=[xax, yax1, yax2], animation_duration=1000)"
]
Expand Down