Skip to content

Commit 803a889

Browse files
committed
Populate examples with __init__ format() args
1 parent 9b1098f commit 803a889

9 files changed

Lines changed: 95 additions & 158 deletions

File tree

docs/1dplots.py

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,24 @@
7272
# Sample data
7373
x = np.linspace(-5, 5, N)
7474
y = state.rand(N, 5)
75-
fig = pplt.figure(share=False)
75+
fig = pplt.figure(share=False, suptitle='Standardized input demonstration')
7676

7777
# Plot by passing both x and y coordinates
78-
ax = fig.subplot(121)
78+
ax = fig.subplot(121, title='Manual x coordinates')
7979
ax.area(x, -1 * y / N, stack=True)
8080
ax.bar(x, y, linewidth=0, alpha=1, width=0.8)
8181
ax.plot(x, y + 1, linewidth=2)
8282
ax.scatter(x, y + 2, marker='s', markersize=5**2)
83-
ax.format(title='Manual x coordinates')
8483

8584
# Plot by passing just y coordinates
8685
# Default x coordinates are inferred from DataFrame,
8786
# inferred from DataArray, or set to np.arange(0, y.shape[0])
88-
ax = fig.subplot(122)
87+
ax = fig.subplot(122, title='Auto x coordinates')
8988
ax.area(-1 * y / N, stack=True)
9089
ax.bar(y, linewidth=0, alpha=1)
9190
ax.plot(y + 1, linewidth=2)
9291
ax.scatter(y + 2, marker='s', markersize=5**2)
93-
ax.format(title='Auto x coordinates')
9492
fig.format(xlabel='xlabel', ylabel='ylabel')
95-
fig.format(suptitle='Standardized input demonstration')
9693

9794
# %%
9895
import proplot as pplt
@@ -199,8 +196,7 @@
199196

200197
# %%
201198
import proplot as pplt
202-
fig = pplt.figure(share=False)
203-
fig.format(suptitle='Automatic subplot formatting')
199+
fig = pplt.figure(share=False, suptitle='Automatic subplot formatting')
204200

205201
# Plot DataArray
206202
cycle = pplt.Cycle('dark blue', space='hpl', N=da.shape[1])
@@ -251,17 +247,15 @@
251247
with pplt.rc.context({'lines.linewidth': 3}):
252248
# Use property cycle for columns of 2D input data
253249
fig = pplt.figure(share=False)
254-
ax = fig.subplot(121)
255-
ax.format(title='Single plot call')
250+
ax = fig.subplot(121, title='Single plot call')
256251
ax.plot(
257252
2 * data1 + data2,
258253
cycle='black', # cycle from monochromatic colormap
259254
cycle_kw={'ls': ('-', '--', '-.', ':')}
260255
)
261256

262257
# Use property cycle with successive plot() calls
263-
ax = fig.subplot(122)
264-
ax.format(title='Multiple plot calls')
258+
ax = fig.subplot(122, title='Multiple plot calls')
265259
for i in range(data1.shape[1]):
266260
ax.plot(data1[:, i], cycle='Reds', cycle_kw={'N': N, 'left': 0.3})
267261
for i in range(data1.shape[1]):
@@ -302,39 +296,33 @@
302296

303297
# Vertical vs. horizontal
304298
data = (state.rand(10, 5) - 0.5).cumsum(axis=0)
305-
ax = fig.subplot(gs[0])
306-
ax.format(title='Dependent x-axis')
299+
ax = fig.subplot(gs[0], title='Dependent x-axis')
307300
ax.line(data, lw=2.5, cycle='seaborn')
308-
ax = fig.subplot(gs[1])
309-
ax.format(title='Dependent y-axis')
301+
ax = fig.subplot(gs[1], title='Dependent y-axis')
310302
ax.linex(data, lw=2.5, cycle='seaborn')
311303

312304
# Vertical lines
313305
gray = 'gray7'
314306
data = state.rand(20) - 0.5
315-
ax = fig.subplot(gs[2])
307+
ax = fig.subplot(gs[2], title='Vertical lines')
316308
ax.area(data, color=gray, alpha=0.2)
317309
ax.vlines(data, negpos=True, lw=2)
318-
ax.format(title='Vertical lines')
319310

320311
# Horizontal lines
321-
ax = fig.subplot(gs[3])
312+
ax = fig.subplot(gs[3], title='Horizontal lines')
322313
ax.areax(data, color=gray, alpha=0.2)
323314
ax.hlines(data, negpos=True, lw=2)
324-
ax.format(title='Horizontal lines')
325315

326316
# Step
327-
ax = fig.subplot(gs[4])
317+
ax = fig.subplot(gs[4], title='Step plot')
328318
data = state.rand(20, 4).cumsum(axis=1).cumsum(axis=0)
329319
cycle = ('gray6', 'blue7', 'red7', 'gray4')
330320
ax.step(data, cycle=cycle, labels=list('ABCD'), legend='ul', legend_kw={'ncol': 2})
331-
ax.format(title='Step plot')
332321

333322
# Stems
334-
ax = fig.subplot(gs[5])
323+
ax = fig.subplot(gs[5], title='Stem plot')
335324
data = state.rand(20)
336325
ax.stem(data)
337-
ax.format(title='Stem plot')
338326
fig.format(suptitle='Line plots demo', xlabel='xlabel', ylabel='ylabel')
339327

340328

@@ -390,24 +378,20 @@
390378
fig = pplt.figure(refwidth=2.2, share='labels', span=False)
391379

392380
# Vertical vs. horizontal
393-
ax = fig.subplot(gs[0])
394-
ax.format(title='Dependent x-axis')
381+
ax = fig.subplot(gs[0], title='Dependent x-axis')
395382
ax.scatter(data, cycle='538')
396-
ax = fig.subplot(gs[1])
397-
ax.format(title='Dependent y-axis')
383+
ax = fig.subplot(gs[1], title='Dependent y-axis')
398384
ax.scatterx(data, cycle='538')
399385

400386
# Scatter plot with property cycler
401-
ax = fig.subplot(gs[2])
402-
ax.format(title='With property cycle')
387+
ax = fig.subplot(gs[2], title='With property cycle')
403388
obj = ax.scatter(
404389
x, data, legend='ul', legend_kw={'ncols': 2},
405390
cycle='Set2', cycle_kw={'m': ['x', 'o', 'x', 'o'], 'ms': [5, 10, 20, 30]}
406391
)
407392

408393
# Scatter plot with colormap
409-
ax = fig.subplot(gs[3])
410-
ax.format(title='With colormap')
394+
ax = fig.subplot(gs[3], title='With colormap')
411395
data = state.rand(2, 100)
412396
obj = ax.scatter(
413397
*data,
@@ -532,18 +516,17 @@
532516
fig = pplt.figure(refaspect=2, refwidth=4.8, share=False)
533517

534518
# Side-by-side bars
535-
ax = fig.subplot(gs[0])
519+
ax = fig.subplot(gs[0], title='Side-by-side')
536520
obj = ax.bar(
537521
data, cycle='Reds', edgecolor='red9', colorbar='ul', colorbar_kw={'frameon': False}
538522
)
539-
ax.format(xlocator=1, xminorlocator=0.5, ytickminor=False, title='Side-by-side')
523+
ax.format(xlocator=1, xminorlocator=0.5, ytickminor=False)
540524

541525
# Stacked bars
542-
ax = fig.subplot(gs[1])
526+
ax = fig.subplot(gs[1], title='Stacked')
543527
obj = ax.barh(
544528
data.iloc[::-1, :], cycle='Blues', edgecolor='blue9', legend='ur', stack=True,
545529
)
546-
ax.format(title='Stacked')
547530
fig.format(grid=False, suptitle='Bar plot demo')
548531
pplt.rc.reset()
549532

@@ -562,20 +545,18 @@
562545
fig = pplt.figure(refwidth=2.3, share=False)
563546

564547
# Overlaid area patches
565-
ax = fig.subplot(121)
548+
ax = fig.subplot(121, title='Fill between columns')
566549
ax.area(
567550
np.arange(5), data, data + state.rand(5)[:, None], cycle=cycle, alpha=0.7,
568551
legend='uc', legend_kw={'center': True, 'ncols': 2, 'labels': ['z', 'y', 'qqqq']},
569552
)
570-
ax.format(title='Fill between columns')
571553

572554
# Stacked area patches
573-
ax = fig.subplot(122)
555+
ax = fig.subplot(122, title='Stack between columns')
574556
ax.area(
575557
np.arange(5), data, stack=True, cycle=cycle, alpha=0.8,
576558
legend='ul', legend_kw={'center': True, 'ncols': 2, 'labels': ['z', 'y', 'qqqq']},
577559
)
578-
ax.format(title='Stack between columns')
579560
fig.format(grid=False, xlabel='xlabel', ylabel='ylabel', suptitle='Area plot demo')
580561
pplt.rc.reset()
581562

docs/2dplots.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,17 @@
203203

204204
# %%
205205
import proplot as pplt
206-
fig = pplt.figure(refwidth=2.5, share=False)
207-
fig.format(suptitle='Automatic subplot formatting')
206+
fig = pplt.figure(refwidth=2.5, share=False, suptitle='Automatic subplot formatting')
208207

209208
# Plot DataArray
210209
cmap = pplt.Colormap('PuBu', left=0.05)
211-
ax = fig.subplot(121)
210+
ax = fig.subplot(121, yreverse=True)
212211
ax.contourf(da, cmap=cmap, colorbar='t', lw=0.7, ec='k')
213-
ax.format(yreverse=True)
214212

215213
# Plot DataFrame
216-
ax = fig.subplot(122)
214+
ax = fig.subplot(122, yreverse=True)
217215
ax.contourf(df, cmap='YlOrRd', colorbar='t', lw=0.7, ec='k')
218-
ax.format(xtickminor=False, yreverse=True, yformatter='%b', ytickminor=False)
216+
ax.format(xtickminor=False, yformatter='%b', ytickminor=False)
219217

220218
# %% [raw] raw_mimetype="text/restructuredtext"
221219
# .. _ug_apply_cmap:
@@ -383,21 +381,19 @@
383381
fig.format(suptitle='DiscreteNorm end-color standardization')
384382

385383
# Cyclic colorbar with distinct end colors
386-
ax = fig.subplot(gs[0, 1:3])
384+
ax = fig.subplot(gs[0, 1:3], title='distinct "cyclic" end colors')
387385
ax.pcolormesh(
388386
data, levels=levels, cmap='phase', extend='neither',
389387
colorbar='b', colorbar_kw={'locator': 90}
390388
)
391-
ax.format(title='distinct "cyclic" end colors')
392389

393390
# Colorbars with different extend values
394391
for i, extend in enumerate(('min', 'max', 'neither', 'both')):
395-
ax = fig.subplot(gs[1, i])
392+
ax = fig.subplot(gs[1, i], title=f'extend={extend!r}')
396393
ax.pcolormesh(
397394
data[:, :10], levels=levels, cmap='oxy',
398395
extend=extend, colorbar='b', colorbar_kw={'locator': 180}
399396
)
400-
ax.format(title=f'extend={extend!r}')
401397

402398
# %% [raw] raw_mimetype="text/restructuredtext" tags=[]
403399
# .. _ug_autonorm:
@@ -443,8 +439,10 @@
443439
N = 20
444440
state = np.random.RandomState(51423)
445441
data = N * 2 + (state.rand(N, N) - 0.45).cumsum(axis=0).cumsum(axis=1) * 10
446-
fig, axs = pplt.subplots(nrows=2, ncols=2, refwidth=2)
447-
fig.format(suptitle='Auto normalization demo')
442+
fig, axs = pplt.subplots(
443+
nrows=2, ncols=2, refwidth=2,
444+
suptitle='Auto normalization demo'
445+
)
448446

449447
# Auto diverging
450448
pplt.rc['cmap.sequential'] = 'lapaz_r'

docs/basics.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@
7979
import proplot as pplt
8080
state = np.random.RandomState(51423)
8181
data = 2 * (state.rand(100, 5) - 0.5).cumsum(axis=0)
82-
fig = pplt.figure()
83-
ax = fig.subplot()
82+
fig = pplt.figure(suptitle='Single subplot')
83+
ax = fig.subplot(xlabel='x axis', ylabel='y axis')
8484
ax.plot(data, lw=2)
85-
ax.format(suptitle='Single subplot', xlabel='x axis', ylabel='y axis')
8685

8786

8887
# %% [raw] raw_mimetype="text/restructuredtext"

0 commit comments

Comments
 (0)