|
31 | 31 | # These features are *optional*. Installation of cartopy or basemap is not required. |
32 | 32 | # |
33 | 33 | # 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. |
96 | 41 |
|
97 | 42 |
|
98 | 43 | # %% [raw] raw_mimetype="text/restructuredtext" |
|
177 | 122 | # Basemap is `no longer maintained \ |
178 | 123 | # <https://matplotlib.org/basemap/users/intro.html#cartopy-new-management-and-eol-announcement>`__ |
179 | 124 | # 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. |
184 | 129 |
|
185 | 130 | # %% |
186 | | -# Simple figure with just one projection |
187 | | - |
188 | 131 | # Option 1: Create a projection manually with pplt.Proj() |
189 | 132 | # immport proplot as plot |
190 | 133 | # proj = pplt.Proj('robin', lon_0=180) |
|
233 | 176 | # just like cartopy. When using basemap as the "backend", you should not have to work |
234 | 177 | # with the `~mpl_toolkits.basemap.Basemap` instance directly. |
235 | 178 | # |
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 |
237 | 180 | # `~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 |
240 | 183 | # cartopy's `~cartopy.util.add_cyclic_point` and basemap's |
241 | 184 | # `~mpl_toolkits.basemap.addcyclic`. |
242 | 185 | # |
|
479 | 422 | ) |
480 | 423 | for proj, ax in zip(projs, axs): |
481 | 424 | 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 | +) |
0 commit comments