Skip to content

Commit 4945474

Browse files
committed
Update docs
1 parent b62450a commit 4945474

File tree

9 files changed

+143
-123
lines changed

9 files changed

+143
-123
lines changed

WHATSNEW.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ProPlot v0.7.1 (2021-##-##)
7979
* Fix issue where deprecated `aspect` `~proplot.ui.subplots` argument
8080
is ignored (:commit:`70a8b87d`).
8181
* Fix issue where `~proplot.axes.Axes.parametric` ignores `interp` when
82-
selecting default colormap levels (:commit:`152a3a81`).
82+
selecting `DiscreteNorm` colormap levels (:commit:`152a3a81`).
8383
* Fix issue where a-b-c labels are removed in presence of ``'top'`` panels
8484
with ``titleabove=True`` (:commit:`7873d5e0`).
8585
* Ensure `plot` returns tuples of handles instead of lists, and ensure `indicate_error`
@@ -94,6 +94,20 @@ ProPlot v0.7.1 (2021-##-##)
9494
default row label rotation match default y label rotation (:commit:`bae85113`).
9595
* Make `~proplot.axes.colorbar_extras` capture matplotlib-native `format` keyword
9696
as alias for `formatter` and `ticklabels` (:issue:`262`).
97+
* Permit legends from mappables using ``ContourSet.legend_elements``
98+
and ``Collection.legend_elements`` (:pr:`264`).
99+
* Add `stepx` command analogous to `plotx` and `histh`, `boxploth`, and `violinploth`
100+
commands analogous to `barh` (:pr:`264`). Also add aliases.
101+
102+
.. rubric:: Internals
103+
104+
* Convert all plotting wrappers to dedicated overrides of individual functions
105+
(:pr:`264`). This massively simplifies the internals and makes learning
106+
and adopting proplot much easier for new users.
107+
* Use metaclasses to redirect internal plotting calls to native matplotlib
108+
methods (:pr:`264`). Much safer/more stable this way.
109+
* Use metaclasses to efficiently impose defaults ``latlon=True`` and
110+
``transform=PlateCarree()`` in 90% fewer lines (:pr:`264`).
97111

98112

99113
ProPlot v0.7.0 (2021-07-11)

docs/api.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Axes classes
3131

3232
.. automodsumm:: proplot.axes
3333
:toctree: api
34-
:classes-only:
3534

3635

3736
Constructor functions
@@ -52,16 +51,6 @@ Configuration tools
5251
:skip: inline_backend_fmt
5352

5453

55-
Plotting wrappers
56-
=================
57-
58-
.. automodule:: proplot.axes.plot
59-
60-
.. automodsumm:: proplot.axes
61-
:toctree: api
62-
:functions-only:
63-
64-
6554
Demo functions
6655
==============
6756

docs/basics.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@
276276
# %% [raw] raw_mimetype="text/restructuredtext"
277277
# .. _ug_container:
278278
#
279-
# Subplot containers
280-
# ------------------
279+
# Multiple axes
280+
# -------------
281281
#
282282
# `matplotlib.pyplot.subplots` returns a 2D `~numpy.ndarray` for figures with more
283283
# than one column and row, a 1D `~numpy.ndarray` for single-column or row figures,
@@ -306,13 +306,15 @@
306306
import proplot as pplt
307307
import numpy as np
308308
state = np.random.RandomState(51423)
309+
310+
# Format all subplots at once
309311
fig, axs = pplt.subplots(ncols=4, nrows=4, refwidth=1.2)
310312
axs.format(
311313
xlabel='xlabel', ylabel='ylabel', suptitle='SubplotsContainer demo',
312314
grid=False, xlim=(0, 50), ylim=(-4, 4)
313315
)
314316

315-
# Various ways to select subplots in the container
317+
# Format selected subplots in the container
316318
axs[:, 0].format(facecolor='blush', color='gray7', linewidth=1)
317319
axs[0, :].format(facecolor='sky blue', color='gray7', linewidth=1)
318320
axs[0].format(color='black', facecolor='gray5', linewidth=1.4)

docs/colormaps.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,15 @@
188188
# ``'hpl'`` colorspaces.
189189

190190
# %%
191+
# Sample data
191192
import proplot as pplt
192193
import numpy as np
193194
state = np.random.RandomState(51423)
194195
data = state.rand(30, 30).cumsum(axis=1)
195196

196-
# Initialize figure
197-
fig, axs = pplt.subplots(ncols=2, nrows=2, refwidth=2, span=0)
197+
# %%
198+
# Create figure
199+
fig, axs = pplt.subplots(ncols=2, refwidth=2, span=0)
198200
axs.format(
199201
xticklabels='none',
200202
yticklabels='none',
@@ -216,11 +218,23 @@
216218
m = ax.contourf(data, cmap=cmap2)
217219
ax.colorbar(m, loc='b', ticks='none', label=cmap2.name)
218220

221+
# Display the channels
222+
fig, axs = pplt.show_channels(cmap1, cmap2, refwidth=1.5, rgb=False)
223+
224+
# %%
225+
# Create figure
226+
fig, axs = pplt.subplots(ncols=2, refwidth=2, span=0)
227+
axs.format(
228+
xticklabels='none',
229+
yticklabels='none',
230+
suptitle='Making PerceptuallyUniformColormaps'
231+
)
232+
219233
# Sequential colormap from channel values
220234
cmap3 = pplt.Colormap(
221235
h=('red', 'red-720'), s=(80, 20), l=(20, 100), space='hpl', name='CubeHelix'
222236
)
223-
ax = axs[2]
237+
ax = axs[0]
224238
ax.format(title='Sequential from channel values')
225239
m = ax.contourf(data, cmap=cmap3)
226240
ax.colorbar(m, loc='b', ticks='none', label=cmap3.name)
@@ -229,13 +243,12 @@
229243
cmap4 = pplt.Colormap(
230244
h=(0, 360), c=50, l=70, space='hcl', cyclic=True, name='Spectrum'
231245
)
232-
ax = axs[3]
246+
ax = axs[1]
233247
ax.format(title='Cyclic from channel values')
234248
m = ax.contourf(data, cmap=cmap4)
235249
ax.colorbar(m, loc='b', ticks='none', label=cmap4.name)
236250

237251
# Display the channels
238-
fig, axs = pplt.show_channels(cmap1, cmap2, refwidth=1.5, rgb=False)
239252
fig, axs = pplt.show_channels(cmap3, cmap4, refwidth=1.5, rgb=False)
240253

241254

@@ -376,7 +389,7 @@
376389
state = np.random.RandomState(51423)
377390
data = (state.rand(40, 40) - 0.5).cumsum(axis=0).cumsum(axis=1)
378391

379-
# Generate figure
392+
# Create figure
380393
fig, axs = pplt.subplots(ncols=2, nrows=2, refwidth=1.7, span=False)
381394
axs.format(
382395
xlabel='x axis', ylabel='y axis', xticklabels='none',

docs/projections.py

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -31,68 +31,13 @@
3131
# These features are *optional*. Installation of cartopy or basemap is not required.
3232
#
3333
# To change the axes projection, pass ``proj='name'`` to `~proplot.ui.subplots`. To use
34-
# different projections for different subplots, pass a dictionary of projection names
35-
# with the subplot number as the key -- for example, ``proj={1: 'name'}``. The *default*
36-
# projection is always `~proplot.axes.CartesianAxes` (it can be explicitly specified
37-
# with ``proj='cartesian'``).
38-
39-
# %% [raw] raw_mimetype="text/restructuredtext"
40-
# .. _ug_polar:
41-
#
42-
# Polar axes
43-
# ----------
44-
#
45-
# To draw `polar axes <polar_>`_, pass ``proj='polar'`` or e.g. ``proj={1: 'polar'}``
46-
# to `~proplot.ui.subplots`. This generates a `proplot.axes.PolarAxes` instance with
47-
# its own `~proplot.axes.PolarAxes.format` method.
48-
#
49-
# The `proplot.axes.PolarAxes.format` method facilitates polar-specific axes
50-
# modifications like changing the central radius `r0`, the zero azimuth location
51-
# `theta0`, and the positive azimuthal direction `thetadir`. It also supports
52-
# changing gridline locations with `rlocator` and `thetalocator` (analogous to
53-
# `ylocator` and `xlocator` used by `~proplot.axes.CartesianAxes.format`) and
54-
# turning your polar plot into an "annular" or "sector" plot by changing the radial
55-
# limits `rlim` or the azimuthal limits `thetalim`. Finally, since
56-
# `proplot.axes.PolarAxes.format` calls `proplot.axes.Axes.format`, it can be used to
57-
# add axes titles, a-b-c labels, and figure titles, just like
58-
# `~proplot.axes.CartesianAxes`.
59-
#
60-
# For details, see `proplot.axes.PolarAxes.format`.
61-
62-
# %%
63-
import proplot as pplt
64-
import numpy as np
65-
N = 200
66-
state = np.random.RandomState(51423)
67-
x = np.linspace(0, 2 * np.pi, N)
68-
y = 100 * (state.rand(N, 5) - 0.3).cumsum(axis=0) / N
69-
fig, axs = pplt.subplots([[1, 1, 2, 2], [0, 3, 3, 0]], proj='polar')
70-
axs.format(
71-
suptitle='Polar axes demo', linewidth=1, titlepad='1em',
72-
ticklabelsize=9, rlines=0.5, rlim=(0, 19),
73-
)
74-
for i in range(5):
75-
xi = x + i * 2 * np.pi / 5
76-
axs.plot(xi, y[:, i], cycle='FlatUI', zorder=0, lw=3)
77-
78-
# Standard polar plot
79-
axs[0].format(
80-
title='Normal plot', thetaformatter='tau',
81-
rlabelpos=225, rlines=pplt.arange(5, 30, 5),
82-
color='red8', tickpad='1em',
83-
)
84-
85-
# Sector plot
86-
axs[1].format(
87-
title='Sector plot', thetadir=-1, thetalines=90, thetalim=(0, 270), theta0='N',
88-
rlim=(0, 22), rlines=pplt.arange(5, 30, 5),
89-
)
90-
91-
# Annular plot
92-
axs[2].format(
93-
title='Annular plot', thetadir=-1, thetalines=20, gridcolor='red',
94-
r0=-20, rlim=(0, 22), rformatter='null', rlocator=2
95-
)
34+
# different projections for different subplots, pass a list of projection names or
35+
# a dictionary of projection names with the subplot number as the key -- for example,
36+
# a 2-column figure with a Cartesian axes on the left and a Plate Carrée projection
37+
# on the right can be built with either ``proj=('cartesian', 'pcarree')`` or
38+
# ``proj={2: 'pcarree'}``. The *default* projection is always
39+
# `~proplot.axes.CartesianAxes` and can be explicitly specified with
40+
# the ``'cartesian'`` key.
9641

9742

9843
# %% [raw] raw_mimetype="text/restructuredtext"
@@ -177,14 +122,12 @@
177122
# Basemap is `no longer maintained \
178123
# <https://matplotlib.org/basemap/users/intro.html#cartopy-new-management-and-eol-announcement>`__
179124
# and will not work with matplotlib versions more recent than 3.2.2. However, as
180-
# shown below, gridline labels tend to look nicer in basemap
181-
# than in cartopy -- especially when "inline" cartopy labels are disabled.
182-
# This is the main reason ProPlot continues to support both basemap and cartopy.
183-
# When cartopy's gridline labels improve, basemap support may be deprecated.
125+
# shown below, gridline labels often look nicer in basemap than cartopy --
126+
# especially when "inline" cartopy labels are disabled. This is the main reason
127+
# ProPlot supports both basemap and cartopy. When cartopy gridline labels
128+
# improve, basemap support may be deprecated.
184129

185130
# %%
186-
# Simple figure with just one projection
187-
188131
# Option 1: Create a projection manually with pplt.Proj()
189132
# immport proplot as plot
190133
# proj = pplt.Proj('robin', lon_0=180)
@@ -233,10 +176,10 @@
233176
# just like cartopy. When using basemap as the "backend", you should not have to work
234177
# with the `~mpl_toolkits.basemap.Basemap` instance directly.
235178
#
236-
# To ensure the graphics generated by :ref:`2D plotting commands <ug_2dplots>` like
179+
# To ensure the graphics generated by :ref:`plotting commands <ug_2dplots>` like
237180
# `~matplotlib.axes.Axes.contour` fill the entire globe, simply pass ``globe=True`` to
238-
# the plotting command. This interpolates your data to the poles and across the
239-
# longitude seam before plotting the data. This is a convenient alternative to
181+
# the plotting command. This interpolates the data to the poles and across the
182+
# longitude seam before plotting. This is a convenient alternative to
240183
# cartopy's `~cartopy.util.add_cyclic_point` and basemap's
241184
# `~mpl_toolkits.basemap.addcyclic`.
242185
#
@@ -479,3 +422,62 @@
479422
)
480423
for proj, ax in zip(projs, axs):
481424
ax.format(title=proj, titleweight='bold', labels=False)
425+
426+
427+
# %% [raw] raw_mimetype="text/restructuredtext"
428+
# .. _ug_polar:
429+
#
430+
# Polar axes
431+
# ----------
432+
#
433+
# To draw `polar axes <polar_>`_, pass ``proj='polar'`` or e.g. ``proj={1: 'polar'}``
434+
# to `~proplot.ui.subplots`. This generates a `proplot.axes.PolarAxes` instance with
435+
# its own `~proplot.axes.PolarAxes.format` method.
436+
#
437+
# The `proplot.axes.PolarAxes.format` method facilitates polar-specific axes
438+
# modifications like changing the central radius `r0`, the zero azimuth location
439+
# `theta0`, and the positive azimuthal direction `thetadir`. It also supports
440+
# changing gridline locations with `rlocator` and `thetalocator` (analogous to
441+
# `ylocator` and `xlocator` used by `~proplot.axes.CartesianAxes.format`) and
442+
# turning your polar plot into an "annular" or "sector" plot by changing the radial
443+
# limits `rlim` or the azimuthal limits `thetalim`. Finally, since
444+
# `proplot.axes.PolarAxes.format` calls `proplot.axes.Axes.format`, it can be used to
445+
# add axes titles, a-b-c labels, and figure titles, just like
446+
# `~proplot.axes.CartesianAxes`.
447+
#
448+
# For details, see `proplot.axes.PolarAxes.format`.
449+
450+
# %%
451+
import proplot as pplt
452+
import numpy as np
453+
N = 200
454+
state = np.random.RandomState(51423)
455+
x = np.linspace(0, 2 * np.pi, N)
456+
y = 100 * (state.rand(N, 5) - 0.3).cumsum(axis=0) / N
457+
fig, axs = pplt.subplots([[1, 1, 2, 2], [0, 3, 3, 0]], proj='polar')
458+
axs.format(
459+
suptitle='Polar axes demo', linewidth=1, titlepad='1em',
460+
ticklabelsize=9, rlines=0.5, rlim=(0, 19),
461+
)
462+
for i in range(5):
463+
xi = x + i * 2 * np.pi / 5
464+
axs.plot(xi, y[:, i], cycle='FlatUI', zorder=0, lw=3)
465+
466+
# Standard polar plot
467+
axs[0].format(
468+
title='Normal plot', thetaformatter='tau',
469+
rlabelpos=225, rlines=pplt.arange(5, 30, 5),
470+
color='red8', tickpad='1em',
471+
)
472+
473+
# Sector plot
474+
axs[1].format(
475+
title='Sector plot', thetadir=-1, thetalines=90, thetalim=(0, 270), theta0='N',
476+
rlim=(0, 22), rlines=pplt.arange(5, 30, 5),
477+
)
478+
479+
# Annular plot
480+
axs[2].format(
481+
title='Annular plot', thetadir=-1, thetalines=20, gridcolor='red',
482+
r0=-20, rlim=(0, 22), rformatter='null', rlocator=2
483+
)

docs/subplots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
# Automatic sizing
8686
# ----------------
8787
#
88-
# By default, ProPlot determines the suitable figure size given
88+
# ProPlot by default determines the suitable figure size given
8989
# the geometry of your subplot grid and the size of a "reference"
9090
# subplot. ProPlot can also determine the suitable figure height given a
9191
# fixed *figure* width, and figure width given a fixed *figure* height.

0 commit comments

Comments
 (0)