|
30 | 30 | # Tick locations |
31 | 31 | # -------------- |
32 | 32 | # |
33 | | -# `Tick locators |
| 33 | +# Matplotlib `tick locators |
34 | 34 | # <https://matplotlib.org/stable/gallery/ticks_and_spines/tick-locators.html>`__ |
35 | | -# are used to automatically select sensible tick locations |
36 | | -# based on the axis data limits. In ProPlot, you can change the tick locator |
37 | | -# using the `~proplot.axes.Axes.format` keyword arguments `xlocator`, |
38 | | -# `ylocator`, `xminorlocator`, and `yminorlocator` (or their aliases, |
39 | | -# `xticks`, `yticks`, `xminorticks`, and `yminorticks`). This is powered by |
| 35 | +# select sensible tick locations based on the axis data limits. In ProPlot, you can |
| 36 | +# change the tick locator using the `~proplot.axes.CartesianAxes.format` keyword |
| 37 | +# arguments `xlocator`, `ylocator`, `xminorlocator`, and `yminorlocator` (or their |
| 38 | +# aliases, `xticks`, `yticks`, `xminorticks`, and `yminorticks`). This is powered by |
40 | 39 | # the `~proplot.constructor.Locator` :ref:`constructor function <why_constructor>`. |
41 | 40 | # |
42 | 41 | # These keyword arguments can be used to apply built-in matplotlib |
|
122 | 121 | # %% [raw] raw_mimetype="text/restructuredtext" |
123 | 122 | # .. _ug_formatters: |
124 | 123 | # |
125 | | -# Tick labels |
126 | | -# ----------- |
| 124 | +# Tick formatting |
| 125 | +# --------------- |
127 | 126 | # |
128 | | -# `Tick formatters |
| 127 | +# Matplotlib `tick formatters |
129 | 128 | # <https://matplotlib.org/stable/gallery/ticks_and_spines/tick-formatters.html>`__ |
130 | | -# are used to convert floating point numbers to |
131 | | -# nicely-formatted tick labels. In ProPlot, you can change the tick formatter |
132 | | -# using the `~proplot.axes.Axes.format` keyword arguments `xformatter` and |
133 | | -# `yformatter` (or their aliases, `xticklabels` and `yticklabels`). This is |
134 | | -# powered by the `~proplot.constructor.Formatter` |
| 129 | +# convert floating point numbers to nicely-formatted tick labels. In ProPlot, you can |
| 130 | +# change the tick formatter using the `~proplot.axes.CartesianAxes.format` keyword |
| 131 | +# arguments `xformatter` and `yformatter` (or their aliases, `xticklabels` and |
| 132 | +# `yticklabels`). This is powered by the `~proplot.constructor.Formatter` |
135 | 133 | # :ref:`constructor function <why_constructor>`. |
136 | 134 | # |
137 | 135 | # These keyword arguments can be used to apply built-in matplotlib |
|
155 | 153 | # `~proplot.ticker.AutoFormatter` for details. To disable the trailing |
156 | 154 | # zero-trimming feature, set :rcraw:`formatter.zerotrim` to ``False``. |
157 | 155 |
|
| 156 | +# %% |
| 157 | +import proplot as pplt |
| 158 | +pplt.rc.linewidth = 2 |
| 159 | +pplt.rc.fontsize = 11 |
| 160 | +locator = [0, 0.25, 0.5, 0.75, 1] |
| 161 | +fig, axs = pplt.subplots(ncols=2, nrows=2, refwidth=1.5, share=0) |
| 162 | + |
| 163 | +# Formatter comparison |
| 164 | +axs[0].format( |
| 165 | + xformatter='scalar', yformatter='scalar', title='Matplotlib formatter' |
| 166 | +) |
| 167 | +axs[1].format(yticklabelloc='both', title='ProPlot formatter') |
| 168 | +axs[:2].format(xlocator=locator, ylocator=locator) |
| 169 | + |
| 170 | +# Limiting the tick range |
| 171 | +axs[2].format( |
| 172 | + title='Omitting tick labels', ticklen=5, xlim=(0, 5), ylim=(0, 5), |
| 173 | + xtickrange=(0, 2), ytickrange=(0, 2), xlocator=1, ylocator=1 |
| 174 | +) |
| 175 | + |
| 176 | +# Setting the wrap range |
| 177 | +axs[3].format( |
| 178 | + title='Wrapping the tick range', ticklen=5, xlim=(0, 7), ylim=(0, 6), |
| 179 | + xwraprange=(0, 5), ywraprange=(0, 3), xlocator=1, ylocator=1 |
| 180 | +) |
| 181 | +axs.format( |
| 182 | + ytickloc='both', yticklabelloc='both', |
| 183 | + titlepad='0.5em', suptitle='Default formatters demo' |
| 184 | +) |
| 185 | +pplt.rc.reset() |
| 186 | + |
| 187 | + |
158 | 188 | # %% |
159 | 189 | import proplot as pplt |
160 | 190 | import numpy as np |
|
207 | 237 | axs.format(ylocator='null', suptitle='Tick formatters demo') |
208 | 238 | pplt.rc.reset() |
209 | 239 |
|
210 | | -# %% |
211 | | -import proplot as pplt |
212 | | -pplt.rc.linewidth = 2 |
213 | | -pplt.rc.fontsize = 11 |
214 | | -locator = [0, 0.25, 0.5, 0.75, 1] |
215 | | -fig, axs = pplt.subplots(ncols=2, nrows=2, refwidth=1.5, share=0) |
216 | | - |
217 | | -# Formatter comparison |
218 | | -axs[0].format( |
219 | | - xformatter='scalar', yformatter='scalar', title='Matplotlib formatter' |
220 | | -) |
221 | | -axs[1].format(yticklabelloc='both', title='ProPlot formatter') |
222 | | -axs[:2].format(xlocator=locator, ylocator=locator) |
223 | | - |
224 | | -# Limiting the tick range |
225 | | -axs[2].format( |
226 | | - title='Omitting tick labels', ticklen=5, xlim=(0, 5), ylim=(0, 5), |
227 | | - xtickrange=(0, 2), ytickrange=(0, 2), xlocator=1, ylocator=1 |
228 | | -) |
229 | | - |
230 | | -# Setting the wrap range |
231 | | -axs[3].format( |
232 | | - title='Wrapping the tick range', ticklen=5, xlim=(0, 7), ylim=(0, 6), |
233 | | - xwraprange=(0, 5), ywraprange=(0, 3), xlocator=1, ylocator=1 |
234 | | -) |
235 | | -axs.format( |
236 | | - ytickloc='both', yticklabelloc='both', |
237 | | - titlepad='0.5em', suptitle='Default formatters demo' |
238 | | -) |
239 | | -pplt.rc.reset() |
240 | | - |
241 | | - |
242 | 240 | # %% [raw] raw_mimetype="text/restructuredtext" |
243 | 241 | # .. _ug_datetime: |
244 | 242 | # |
245 | 243 | # Datetime ticks |
246 | 244 | # -------------- |
247 | 245 | # |
248 | 246 | # ProPlot can also be used to customize the tick locations and tick label |
249 | | -# format of "datetime" axes. To draw ticks on some particular time unit, just |
250 | | -# use a unit string (e.g., ``xlocator='month'``). To draw ticks every ``N`` |
251 | | -# time units, just use a (unit, N) tuple (e.g., ``xlocator=('day', 5)``). For |
252 | | -# `% style formatting |
| 247 | +# format of "datetime" axes. |
| 248 | +# To draw ticks on some particular time unit, just use a unit string (e.g., |
| 249 | +# ``xlocator='month'``). To draw ticks every ``N`` time units, just use a (unit, N) |
| 250 | +# tuple (e.g., ``xlocator=('day', 5)``). For `% style formatting |
253 | 251 | # <https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior>`__ |
254 | 252 | # of datetime tick labels, just use a string containing ``'%'`` (e.g. |
255 | | -# ``xformatter='%Y-%m-%d'``). See `~proplot.axes.CartesianAxes.format`, |
256 | | -# `~proplot.constructor.Locator`, and `~proplot.constructor.Formatter` for |
257 | | -# details. |
| 253 | +# ``xformatter='%Y-%m-%d'``). |
| 254 | +# See `~proplot.axes.CartesianAxes.format`, `~proplot.constructor.Locator`, |
| 255 | +# and `~proplot.constructor.Formatter` for details. |
258 | 256 |
|
259 | 257 | # %% |
260 | 258 | import proplot as pplt |
|
308 | 306 | # %% [raw] raw_mimetype="text/restructuredtext" |
309 | 307 | # .. _ug_scales: |
310 | 308 | # |
311 | | -# Changing the axis scale |
312 | | -# ----------------------- |
| 309 | +# Axis scale changes |
| 310 | +# ------------------ |
313 | 311 | # |
314 | 312 | # "Axis scales" like ``'linear'`` and ``'log'`` control the *x* and *y* axis |
315 | 313 | # coordinate system. To change the axis scale, simply pass e.g. |
|
319 | 317 | # |
320 | 318 | # ProPlot also makes several changes to the axis scale API: |
321 | 319 | # |
322 | | -# * By default, the `~proplot.ticker.AutoFormatter` formatter is used for all |
323 | | -# axis scales instead of e.g. `~matplotlib.ticker.LogFormatter` for |
324 | | -# `~matplotlib.scale.LogScale` scales. This can be changed e.g. by passing |
325 | | -# ``xformatter='log'`` or ``yformatter='log'`` to |
| 320 | +# * The `~proplot.ticker.AutoFormatter` formatter is now used for all axis scales |
| 321 | +# by default, including ``'log'`` and ``'symlog'``. Matplotlib's behavior can |
| 322 | +# be restored by passing e.g. ``xformatter='log'`` or ``yformatter='log'`` to |
326 | 323 | # `~proplot.axes.CartesianAxes.format`. |
327 | 324 | # * To make its behavior consistent with `~proplot.constructor.Locator` and |
328 | 325 | # `~proplot.constructor.Formatter`, the `~proplot.constructor.Scale` |
329 | 326 | # constructor function returns instances of `~matplotlib.scale.ScaleBase`, |
330 | 327 | # and `~matplotlib.axes.Axes.set_xscale` and |
331 | 328 | # `~matplotlib.axes.Axes.set_yscale` now accept these class instances in |
332 | | -# addition to string names like ``'log'``. |
| 329 | +# addition to "registered" names like ``'log'``. |
333 | 330 | # * While matplotlib axis scales must be instantiated with an |
334 | | -# `~matplotlib.axis.Axis` instance (for backward compatibility reasons), |
335 | | -# ProPlot axis scales can be instantiated without the axis instance (e.g. |
336 | | -# ``pplt.LogScale()`` instead of ``pplt.LogScale(ax.xaxis)``). |
| 331 | +# `~matplotlib.axis.Axis` instance (for backwards compatibility reasons), |
| 332 | +# ProPlot axis scales can be instantiated without the axis instance |
| 333 | +# (e.g., ``pplt.LogScale()`` instead of ``pplt.LogScale(ax.xaxis)``). |
337 | 334 | # * The default `subs` for the ``'symlog'`` axis scale is now ``np.arange(1, 10)``, |
338 | 335 | # and the default `linthresh` is now ``1``. Also the ``'log'`` and ``'symlog'`` |
339 | 336 | # axis scales now accept the keywords `base`, `linthresh`, `linscale`, and |
|
474 | 471 | # %% [raw] raw_mimetype="text/restructuredtext" |
475 | 472 | # .. _ug_dual: |
476 | 473 | # |
477 | | -# Dual unit axes |
478 | | -# -------------- |
| 474 | +# Dual unit scales |
| 475 | +# ---------------- |
479 | 476 | # |
480 | 477 | # The `~proplot.axes.CartesianAxes.dualx` and |
481 | 478 | # `~proplot.axes.CartesianAxes.dualy` methods can be used to draw duplicate |
|
0 commit comments