Skip to content

Commit

Permalink
Populate examples with __init__ format() args
Browse files Browse the repository at this point in the history
  • Loading branch information
lukelbd committed Oct 11, 2021
1 parent 9b1098f commit 803a889
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 158 deletions.
61 changes: 21 additions & 40 deletions docs/1dplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,24 @@
# Sample data
x = np.linspace(-5, 5, N)
y = state.rand(N, 5)
fig = pplt.figure(share=False)
fig = pplt.figure(share=False, suptitle='Standardized input demonstration')

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

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

# %%
import proplot as pplt
Expand Down Expand Up @@ -199,8 +196,7 @@

# %%
import proplot as pplt
fig = pplt.figure(share=False)
fig.format(suptitle='Automatic subplot formatting')
fig = pplt.figure(share=False, suptitle='Automatic subplot formatting')

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

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

# Vertical vs. horizontal
data = (state.rand(10, 5) - 0.5).cumsum(axis=0)
ax = fig.subplot(gs[0])
ax.format(title='Dependent x-axis')
ax = fig.subplot(gs[0], title='Dependent x-axis')
ax.line(data, lw=2.5, cycle='seaborn')
ax = fig.subplot(gs[1])
ax.format(title='Dependent y-axis')
ax = fig.subplot(gs[1], title='Dependent y-axis')
ax.linex(data, lw=2.5, cycle='seaborn')

# Vertical lines
gray = 'gray7'
data = state.rand(20) - 0.5
ax = fig.subplot(gs[2])
ax = fig.subplot(gs[2], title='Vertical lines')
ax.area(data, color=gray, alpha=0.2)
ax.vlines(data, negpos=True, lw=2)
ax.format(title='Vertical lines')

# Horizontal lines
ax = fig.subplot(gs[3])
ax = fig.subplot(gs[3], title='Horizontal lines')
ax.areax(data, color=gray, alpha=0.2)
ax.hlines(data, negpos=True, lw=2)
ax.format(title='Horizontal lines')

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

# Stems
ax = fig.subplot(gs[5])
ax = fig.subplot(gs[5], title='Stem plot')
data = state.rand(20)
ax.stem(data)
ax.format(title='Stem plot')
fig.format(suptitle='Line plots demo', xlabel='xlabel', ylabel='ylabel')


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

# Vertical vs. horizontal
ax = fig.subplot(gs[0])
ax.format(title='Dependent x-axis')
ax = fig.subplot(gs[0], title='Dependent x-axis')
ax.scatter(data, cycle='538')
ax = fig.subplot(gs[1])
ax.format(title='Dependent y-axis')
ax = fig.subplot(gs[1], title='Dependent y-axis')
ax.scatterx(data, cycle='538')

# Scatter plot with property cycler
ax = fig.subplot(gs[2])
ax.format(title='With property cycle')
ax = fig.subplot(gs[2], title='With property cycle')
obj = ax.scatter(
x, data, legend='ul', legend_kw={'ncols': 2},
cycle='Set2', cycle_kw={'m': ['x', 'o', 'x', 'o'], 'ms': [5, 10, 20, 30]}
)

# Scatter plot with colormap
ax = fig.subplot(gs[3])
ax.format(title='With colormap')
ax = fig.subplot(gs[3], title='With colormap')
data = state.rand(2, 100)
obj = ax.scatter(
*data,
Expand Down Expand Up @@ -532,18 +516,17 @@
fig = pplt.figure(refaspect=2, refwidth=4.8, share=False)

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

# Stacked bars
ax = fig.subplot(gs[1])
ax = fig.subplot(gs[1], title='Stacked')
obj = ax.barh(
data.iloc[::-1, :], cycle='Blues', edgecolor='blue9', legend='ur', stack=True,
)
ax.format(title='Stacked')
fig.format(grid=False, suptitle='Bar plot demo')
pplt.rc.reset()

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

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

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

Expand Down
22 changes: 10 additions & 12 deletions docs/2dplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,17 @@

# %%
import proplot as pplt
fig = pplt.figure(refwidth=2.5, share=False)
fig.format(suptitle='Automatic subplot formatting')
fig = pplt.figure(refwidth=2.5, share=False, suptitle='Automatic subplot formatting')

# Plot DataArray
cmap = pplt.Colormap('PuBu', left=0.05)
ax = fig.subplot(121)
ax = fig.subplot(121, yreverse=True)
ax.contourf(da, cmap=cmap, colorbar='t', lw=0.7, ec='k')
ax.format(yreverse=True)

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

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

# Cyclic colorbar with distinct end colors
ax = fig.subplot(gs[0, 1:3])
ax = fig.subplot(gs[0, 1:3], title='distinct "cyclic" end colors')
ax.pcolormesh(
data, levels=levels, cmap='phase', extend='neither',
colorbar='b', colorbar_kw={'locator': 90}
)
ax.format(title='distinct "cyclic" end colors')

# Colorbars with different extend values
for i, extend in enumerate(('min', 'max', 'neither', 'both')):
ax = fig.subplot(gs[1, i])
ax = fig.subplot(gs[1, i], title=f'extend={extend!r}')
ax.pcolormesh(
data[:, :10], levels=levels, cmap='oxy',
extend=extend, colorbar='b', colorbar_kw={'locator': 180}
)
ax.format(title=f'extend={extend!r}')

# %% [raw] raw_mimetype="text/restructuredtext" tags=[]
# .. _ug_autonorm:
Expand Down Expand Up @@ -443,8 +439,10 @@
N = 20
state = np.random.RandomState(51423)
data = N * 2 + (state.rand(N, N) - 0.45).cumsum(axis=0).cumsum(axis=1) * 10
fig, axs = pplt.subplots(nrows=2, ncols=2, refwidth=2)
fig.format(suptitle='Auto normalization demo')
fig, axs = pplt.subplots(
nrows=2, ncols=2, refwidth=2,
suptitle='Auto normalization demo'
)

# Auto diverging
pplt.rc['cmap.sequential'] = 'lapaz_r'
Expand Down
5 changes: 2 additions & 3 deletions docs/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@
import proplot as pplt
state = np.random.RandomState(51423)
data = 2 * (state.rand(100, 5) - 0.5).cumsum(axis=0)
fig = pplt.figure()
ax = fig.subplot()
fig = pplt.figure(suptitle='Single subplot')
ax = fig.subplot(xlabel='x axis', ylabel='y axis')
ax.plot(data, lw=2)
ax.format(suptitle='Single subplot', xlabel='x axis', ylabel='y axis')


# %% [raw] raw_mimetype="text/restructuredtext"
Expand Down

0 comments on commit 803a889

Please sign in to comment.