Skip to content

Commit 97f5ffd

Browse files
committed
Pep8 compliance in notebook examples
1 parent a75c624 commit 97f5ffd

12 files changed

Lines changed: 470 additions & 328 deletions

docs/1dplots.ipynb

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,18 @@
5858
"import xarray as xr\n",
5959
"import numpy as np\n",
6060
"import pandas as pd\n",
61-
"import proplot as plot\n",
6261
"# DataArray\n",
6362
"state = np.random.RandomState(51423)\n",
64-
"data = np.sin(np.linspace(0, 2*np.pi, 20))[:,None] + state.rand(20,8).cumsum(axis=1)\n",
63+
"data = np.sin(np.linspace(0, 2*np.pi, 20))[:, None] \\\n",
64+
" + state.rand(20, 8).cumsum(axis=1)\n",
6565
"da = xr.DataArray(data, dims=('x', 'cat'), coords={\n",
66-
" 'x':xr.DataArray(np.linspace(0,1,20), dims=('x',), attrs={'long_name':'distance', 'units':'km'}),\n",
67-
" 'cat':xr.DataArray(np.arange(0,80,10), dims=('cat',), attrs={'long_name':'parameter', 'units':'K'})\n",
68-
" }, name='position series')\n",
66+
" 'x': xr.DataArray(np.linspace(0, 1, 20), dims=('x',), attrs={'long_name': 'distance', 'units': 'km'}),\n",
67+
" 'cat': xr.DataArray(np.arange(0, 80, 10), dims=('cat',), attrs={'long_name': 'parameter', 'units': 'K'})\n",
68+
"}, name='position series')\n",
6969
"# DataFrame\n",
70-
"plot.rc.reset()\n",
7170
"ts = pd.date_range('1/1/2000', periods=20)\n",
72-
"data = (np.cos(np.linspace(0, 2*np.pi, 20))**4)[:,None] + state.rand(20,5)**2\n",
73-
"df = pd.DataFrame(data, index=ts, columns=['foo','bar','baz','zap','baf'])\n",
71+
"data = (np.cos(np.linspace(0, 2*np.pi, 20))**4)[:, None] + state.rand(20, 5)**2\n",
72+
"df = pd.DataFrame(data, index=ts, columns=['foo', 'bar', 'baz', 'zap', 'baf'])\n",
7473
"df.name = 'time series'\n",
7574
"df.index.name = 'time (s)'\n",
7675
"df.columns.name = 'columns'"
@@ -82,12 +81,12 @@
8281
"metadata": {},
8382
"outputs": [],
8483
"source": [
85-
"# Figure\n",
84+
"import proplot as plot\n",
8685
"f, axs = plot.subplots(ncols=2, axwidth=2.2, share=0)\n",
8786
"axs.format(suptitle='Automatic subplot formatting')\n",
8887
"# Plot DataArray\n",
8988
"cycle = plot.Cycle(plot.shade('light blue', 0.4), fade=90, space='hpl')\n",
90-
"axs[0].plot(da, cycle=cycle, lw=3, colorbar='ul', colorbar_kw={'locator':20})\n",
89+
"axs[0].plot(da, cycle=cycle, lw=3, colorbar='ul', colorbar_kw={'locator': 20})\n",
9190
"# Plot Dataframe\n",
9291
"cycle = plot.Cycle(plot.shade('jade', 0.4), fade=90, space='hpl')\n",
9392
"axs[1].plot(df, cycle=cycle, lw=3, legend='uc')"
@@ -137,8 +136,10 @@
137136
"plot.rc['title.loc'] = 'uc'\n",
138137
"plot.rc['axes.ymargin'] = plot.rc['axes.xmargin'] = 0.05\n",
139138
"state = np.random.RandomState(51423)\n",
140-
"data = state.rand(20,8).cumsum(axis=0).cumsum(axis=1)[:,::-1] + 20*state.normal(size=(20,8)) + 30\n",
141-
"f, axs = plot.subplots(nrows=3, aspect=1.5, axwidth=3, share=0, hratios=(2,1,1))\n",
139+
"data = state.rand(20, 8).cumsum(axis=0).cumsum(axis=1)[:, ::-1] \\\n",
140+
" + 20*state.normal(size=(20, 8)) + 30\n",
141+
"f, axs = plot.subplots(nrows=3, aspect=1.5, axwidth=3,\n",
142+
" share=0, hratios=(2, 1, 1))\n",
142143
"axs.format(suptitle='Error bars with various plotting commands')\n",
143144
"# Asking add_errorbars to calculate bars\n",
144145
"ax = axs[0]\n",
@@ -147,11 +148,11 @@
147148
"# Showing a standard deviation range instead of percentile range\n",
148149
"ax = axs[1]\n",
149150
"ax.scatter(data, color='k', marker='x', markersize=50, barcolor='gray5',\n",
150-
" medians=True, barstd=True, barrange=(-1,1), barzorder=0, boxes=False, capsize=2)\n",
151+
" medians=True, barstd=True, barrange=(-1, 1), barzorder=0, boxes=False, capsize=2)\n",
151152
"# Supplying error bar data manually\n",
152153
"ax = axs[2]\n",
153-
"boxdata = np.percentile(data, (25,75), axis=0)\n",
154-
"bardata = np.percentile(data, (5,95), axis=0)\n",
154+
"boxdata = np.percentile(data, (25, 75), axis=0)\n",
155+
"bardata = np.percentile(data, (5, 95), axis=0)\n",
155156
"ax.plot(data.mean(axis=0), boxes=False, marker='o', markersize=5,\n",
156157
" edgecolor='k', color='cerulean', boxdata=boxdata, bardata=bardata)\n",
157158
"# Formatting\n",
@@ -189,15 +190,20 @@
189190
"import pandas as pd\n",
190191
"plot.rc.titleloc = 'uc'\n",
191192
"plot.rc.margin = 0.05\n",
192-
"f, axs = plot.subplots(nrows=2, aspect=2, axwidth=3.5, share=0, hratios=(3,2))\n",
193+
"f, axs = plot.subplots(nrows=2, aspect=2, axwidth=3.5, share=0, hratios=(3, 2))\n",
193194
"state = np.random.RandomState(51423)\n",
194-
"data = state.rand(5,5).cumsum(axis=0).cumsum(axis=1)[:,::-1]\n",
195-
"data = pd.DataFrame(data, columns=pd.Index(np.arange(1,6), name='column'), index=pd.Index(['a','b','c','d','e'], name='row idx'))\n",
195+
"data = state.rand(5, 5).cumsum(axis=0).cumsum(axis=1)[:, ::-1]\n",
196+
"data = pd.DataFrame(data,\n",
197+
" columns=pd.Index(np.arange(1, 6), name='column'),\n",
198+
" index=pd.Index(['a', 'b', 'c', 'd', 'e'], name='row idx'))\n",
196199
"ax = axs[0]\n",
197-
"obj = ax.bar(data, cycle='Reds', colorbar='ul', edgecolor='red9', colorbar_kw={'frameon':False})\n",
198-
"ax.format(xlocator=1, xminorlocator=0.5, ytickminor=False, title='Side-by-side', suptitle='Bar plot wrapper demo')\n",
200+
"obj = ax.bar(data, cycle='Reds', colorbar='ul',\n",
201+
" edgecolor='red9', colorbar_kw={'frameon': False})\n",
202+
"ax.format(xlocator=1, xminorlocator=0.5, ytickminor=False,\n",
203+
" title='Side-by-side', suptitle='Bar plot wrapper demo')\n",
199204
"ax = axs[1]\n",
200-
"obj = ax.barh(data.iloc[::-1,:], cycle='Blues', legend='ur', edgecolor='blue9', stacked=True)\n",
205+
"obj = ax.barh(data.iloc[::-1, :], cycle='Blues',\n",
206+
" legend='ur', edgecolor='blue9', stacked=True)\n",
201207
"ax.format(title='Stacked')\n",
202208
"axs.format(grid=False)\n",
203209
"plot.rc.reset()"
@@ -230,21 +236,23 @@
230236
"import proplot as plot\n",
231237
"import numpy as np\n",
232238
"plot.rc.margin = 0\n",
233-
"f, axs = plot.subplots(array=[[1,2],[3,3]], hratios=(1,0.8), share=0)\n",
239+
"f, axs = plot.subplots(array=[[1, 2], [3, 3]], hratios=(1, 0.8), share=0)\n",
234240
"axs.format(xlabel='xlabel', ylabel='ylabel', suptitle='Area plot demo')\n",
235241
"state = np.random.RandomState(51423)\n",
236-
"data = state.rand(5,3).cumsum(axis=0)\n",
242+
"data = state.rand(5, 3).cumsum(axis=0)\n",
237243
"cycle = ('gray3', 'gray5', 'gray7')\n",
244+
"# 2D arrays\n",
238245
"ax = axs[0]\n",
239-
"ax.areax(np.arange(5), data, data + state.rand(5)[:,None], cycle=cycle, alpha=0.5,\n",
240-
" legend='uc', legend_kw={'center':True, 'ncols':2, 'labels':['z','y','qqqq']},\n",
241-
" )\n",
246+
"ax.areax(np.arange(5), data, data + state.rand(5)[:, None], cycle=cycle, alpha=0.5,\n",
247+
" legend='uc', legend_kw={'center': True, 'ncols': 2, 'labels': ['z', 'y', 'qqqq']},\n",
248+
" )\n",
242249
"ax.format(title='Fill between columns')\n",
243250
"ax = axs[1]\n",
244251
"ax.area(np.arange(5), data, stacked=True, cycle=cycle, alpha=0.8,\n",
245-
" legend='ul', legend_kw={'center':True, 'ncols':2, 'labels':['z','y','qqqq']},\n",
252+
" legend='ul', legend_kw={'center': True, 'ncols': 2, 'labels': ['z', 'y', 'qqqq']},\n",
246253
" )\n",
247254
"ax.format(title='Stack between columns')\n",
255+
"# Positive and negative colors\n",
248256
"ax = axs[2]\n",
249257
"data = 5*(state.rand(20)-0.5)\n",
250258
"ax.area(data, negpos=True, negcolor='blue7', poscolor='red7')\n",
@@ -281,15 +289,20 @@
281289
"N = 500\n",
282290
"state = np.random.RandomState(51423)\n",
283291
"f, axs = plot.subplots(ncols=2)\n",
284-
"data = state.normal(size=(N,5)) + 2*(state.rand(N,5)-0.5)*np.arange(5)\n",
285-
"data = pd.DataFrame(data, columns=pd.Index(['a','b','c','d','e'], name='xlabel'))\n",
292+
"data = state.normal(size=(N, 5)) + 2*(state.rand(N, 5)-0.5)*np.arange(5)\n",
293+
"data = pd.DataFrame(data, columns=pd.Index(\n",
294+
" ['a', 'b', 'c', 'd', 'e'], name='xlabel'))\n",
286295
"ax = axs[0]\n",
287-
"obj1 = ax.boxplot(data, lw=0.7, marker='x', fillcolor='gray5', medianlw=1, mediancolor='k')#, boxprops={'color':'C0'})#, labels=data.columns)\n",
296+
"# , boxprops={'color':'C0'})#, labels=data.columns)\n",
297+
"obj1 = ax.boxplot(data, lw=0.7, marker='x', fillcolor='gray5',\n",
298+
" medianlw=1, mediancolor='k')\n",
288299
"ax.format(title='Box plots', titleloc='uc')\n",
289300
"ax = axs[1]\n",
290-
"obj2 = ax.violinplot(data, lw=0.7, fillcolor='gray7', points=500, bw_method=0.3, means=True)\n",
301+
"obj2 = ax.violinplot(data, lw=0.7, fillcolor='gray7',\n",
302+
" points=500, bw_method=0.3, means=True)\n",
291303
"ax.format(title='Violin plots', titleloc='uc')\n",
292-
"axs.format(ymargin=0.1, xmargin=0.1, grid=False, suptitle='Boxes and violins demo')"
304+
"axs.format(ymargin=0.1, xmargin=0.1, grid=False,\n",
305+
" suptitle='Boxes and violins demo')"
293306
]
294307
},
295308
{
@@ -320,22 +333,26 @@
320333
"N = 50\n",
321334
"cmap = 'IceFire'\n",
322335
"values = np.linspace(-N/2, N/2, N)\n",
323-
"f, axs = plot.subplots(share=0, ncols=2, wratios=(2,1), axwidth='6cm', aspect=(2,1))\n",
336+
"f, axs = plot.subplots(share=0, ncols=2, wratios=(2, 1),\n",
337+
" axwidth='6cm', aspect=(2, 1))\n",
324338
"ax = axs[0]\n",
325339
"state = np.random.RandomState(51423)\n",
326-
"m = ax.plot((state.rand(N)-0.5).cumsum(), state.rand(N), cmap=cmap, values=values, lw=7, extend='both')\n",
327-
"ax.format(xlabel='xlabel', ylabel='ylabel', title='Line with smooth color gradations', titleweight='bold')\n",
328-
"ax.format(xlim=(-1,5), ylim=(-0.2,1.2))\n",
340+
"m = ax.plot((state.rand(N) - 0.5).cumsum(), state.rand(N),\n",
341+
" cmap=cmap, values=values, lw=7, extend='both')\n",
342+
"ax.format(xlabel='xlabel', ylabel='ylabel',\n",
343+
" title='Line with smooth color gradations', titleweight='bold')\n",
344+
"ax.format(xlim=(-1, 5), ylim=(-0.2, 1.2))\n",
329345
"ax.colorbar(m, loc='b', label='parametric coordinate', locator=5)\n",
330346
"N = 12\n",
331347
"ax = axs[1]\n",
332348
"values = np.linspace(-N/2, N/2 - 1, N)\n",
333-
"radii = np.linspace(1,0.2,N)\n",
334-
"angles = np.linspace(0,4*np.pi,N)\n",
349+
"radii = np.linspace(1, 0.2, N)\n",
350+
"angles = np.linspace(0, 4*np.pi, N)\n",
335351
"x = radii*np.cos(1.4*angles)\n",
336352
"y = radii*np.sin(1.4*angles)\n",
337353
"m = ax.plot(x, y, values=values, linewidth=15, interp=False, cmap=cmap)\n",
338-
"ax.format(xlim=(-1,1), ylim=(-1,1), title='Step gradations', titleweight='bold', xlabel='cosine angle', ylabel='sine angle')\n",
354+
"ax.format(xlim=(-1, 1), ylim=(-1, 1), title='Step gradations',\n",
355+
" titleweight='bold', xlabel='cosine angle', ylabel='sine angle')\n",
339356
"ax.colorbar(m, loc='b', maxn=10, label=f'parametric coordinate')"
340357
]
341358
},
@@ -369,18 +386,19 @@
369386
"f, axs = plot.subplots(ncols=2, share=1)\n",
370387
"state = np.random.RandomState(51423)\n",
371388
"x = (state.rand(20)-0).cumsum()\n",
372-
"data = (state.rand(20,4)-0.5).cumsum(axis=0)\n",
373-
"data = pd.DataFrame(data, columns=pd.Index(['a','b','c','d'], name='label'))\n",
389+
"data = (state.rand(20, 4)-0.5).cumsum(axis=0)\n",
390+
"data = pd.DataFrame(data, columns=pd.Index(['a', 'b', 'c', 'd'], name='label'))\n",
374391
"# Scatter demo\n",
375392
"ax = axs[0]\n",
376393
"ax.format(title='Extra prop cycle properties', suptitle='Scatter plot demo')\n",
377-
"obj = ax.scatter(x, data, legend='ul', cycle='warm', legend_kw={'ncols':2},\n",
378-
" cycle_kw={'marker':['x','o','x','o'], 'markersize':[5,10,20,30]})\n",
394+
"obj = ax.scatter(x, data, legend='ul', cycle='warm', legend_kw={'ncols': 2},\n",
395+
" cycle_kw={'marker': ['x', 'o', 'x', 'o'], 'markersize': [5, 10, 20, 30]})\n",
379396
"ax = axs[1]\n",
380397
"ax.format(title='Scatter plot with cmap')\n",
381-
"data = (state.rand(2,100) - 0.5)\n",
398+
"data = (state.rand(2, 100) - 0.5)\n",
382399
"obj = ax.scatter(*data, color=data.sum(axis=0), size=state.rand(100), smin=3, smax=30,\n",
383-
" marker='o', cmap='dusk', colorbar='lr', colorbar_kw={'locator':0.5, 'label':'label'})\n",
400+
" marker='o', cmap='dusk', colorbar='lr',\n",
401+
" colorbar_kw={'locator': 0.5, 'label': 'label'})\n",
384402
"axs.format(xlabel='xlabel', ylabel='ylabel')"
385403
]
386404
}

0 commit comments

Comments
 (0)