matplotlib-rs 0.0.8__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docs/releases/0.0.1.md +268 -0
- docs/releases/0.0.2.md +69 -0
- docs/releases/0.0.3.md +80 -0
- docs/releases/0.0.4.md +73 -0
- docs/releases/0.0.5.md +24 -0
- docs/releases/0.0.6.md +24 -0
- docs/releases/0.0.7.md +24 -0
- docs/releases/0.0.8.md +16 -0
- licenses/LICENSE_CONTOURPY +29 -0
- licenses/LICENSE_CYCLER +27 -0
- licenses/LICENSE_DATEUTIL +54 -0
- licenses/LICENSE_KIWISOLVER +71 -0
- licenses/LICENSE_LIBWEBP +56 -0
- licenses/LICENSE_MATPLOTLIB +1253 -0
- licenses/LICENSE_PYPARSING +20 -0
- licenses/LICENSE_QHULL +39 -0
- licenses/LICENSE_SIX +18 -0
- matplotlib_rs/__init__.py +1683 -0
- matplotlib_rs/__main__.py +27 -0
- matplotlib_rs/_afm.py +500 -0
- matplotlib_rs/_animation_data.py +263 -0
- matplotlib_rs/_api/__init__.py +495 -0
- matplotlib_rs/_api/deprecation.py +534 -0
- matplotlib_rs/_axis_py.py +2991 -0
- matplotlib_rs/_blocking_input.py +31 -0
- matplotlib_rs/_cm.py +1500 -0
- matplotlib_rs/_cm_bivar.py +1289 -0
- matplotlib_rs/_cm_listed.py +2848 -0
- matplotlib_rs/_cm_multivar.py +167 -0
- matplotlib_rs/_color_data.py +1142 -0
- matplotlib_rs/_colormap.py +132 -0
- matplotlib_rs/_constrained_layout.py +825 -0
- matplotlib_rs/_contour.py +108 -0
- matplotlib_rs/_doc_cache.py +12214 -0
- matplotlib_rs/_docstring.py +142 -0
- matplotlib_rs/_enums.py +178 -0
- matplotlib_rs/_figure_rs.py +294 -0
- matplotlib_rs/_fontconfig_pattern.py +129 -0
- matplotlib_rs/_foreign.py +220 -0
- matplotlib_rs/_hook.py +94 -0
- matplotlib_rs/_image.py +160 -0
- matplotlib_rs/_imageio.py +229 -0
- matplotlib_rs/_internal_utils.py +65 -0
- matplotlib_rs/_kiwi.py +484 -0
- matplotlib_rs/_layoutgrid.py +549 -0
- matplotlib_rs/_live.py +192 -0
- matplotlib_rs/_mathtext.py +3103 -0
- matplotlib_rs/_mathtext_data.py +1811 -0
- matplotlib_rs/_mplrs.cp313-win_amd64.pyd +0 -0
- matplotlib_rs/_path.py +25 -0
- matplotlib_rs/_png.py +162 -0
- matplotlib_rs/_pylab_helpers.py +137 -0
- matplotlib_rs/_qhull.py +66 -0
- matplotlib_rs/_rcpush.py +84 -0
- matplotlib_rs/_spines_rs.py +108 -0
- matplotlib_rs/_style_helpers.py +52 -0
- matplotlib_rs/_text_helpers.py +51 -0
- matplotlib_rs/_tight_bbox.py +85 -0
- matplotlib_rs/_tight_layout.py +302 -0
- matplotlib_rs/_tri.py +140 -0
- matplotlib_rs/_type1font.py +1228 -0
- matplotlib_rs/_vendor/__init__.py +8 -0
- matplotlib_rs/_vendor/cycler.py +574 -0
- matplotlib_rs/_vendor/dateutil/__init__.py +27 -0
- matplotlib_rs/_vendor/dateutil/_common.py +44 -0
- matplotlib_rs/_vendor/dateutil/_tzdata_impl.py +148 -0
- matplotlib_rs/_vendor/dateutil/_version.py +5 -0
- matplotlib_rs/_vendor/dateutil/easter.py +90 -0
- matplotlib_rs/_vendor/dateutil/parser/__init__.py +62 -0
- matplotlib_rs/_vendor/dateutil/parser/_parser.py +1614 -0
- matplotlib_rs/_vendor/dateutil/parser/isoparser.py +417 -0
- matplotlib_rs/_vendor/dateutil/relativedelta.py +597 -0
- matplotlib_rs/_vendor/dateutil/rrule.py +1765 -0
- matplotlib_rs/_vendor/dateutil/tz/__init__.py +61 -0
- matplotlib_rs/_vendor/dateutil/tz/_common.py +420 -0
- matplotlib_rs/_vendor/dateutil/tz/_factories.py +81 -0
- matplotlib_rs/_vendor/dateutil/tz/_tzfile.py +1429 -0
- matplotlib_rs/_vendor/dateutil/tz/_tzpath.py +105 -0
- matplotlib_rs/_vendor/dateutil/tz/tz.py +1473 -0
- matplotlib_rs/_vendor/dateutil/tz/win.py +371 -0
- matplotlib_rs/_vendor/dateutil/tzwin.py +3 -0
- matplotlib_rs/_vendor/dateutil/utils.py +72 -0
- matplotlib_rs/_vendor/dateutil/zoneinfo/__init__.py +234 -0
- matplotlib_rs/_vendor/pyparsing/__init__.py +414 -0
- matplotlib_rs/_vendor/pyparsing/actions.py +265 -0
- matplotlib_rs/_vendor/pyparsing/common.py +571 -0
- matplotlib_rs/_vendor/pyparsing/core.py +6973 -0
- matplotlib_rs/_vendor/pyparsing/exceptions.py +354 -0
- matplotlib_rs/_vendor/pyparsing/helpers.py +1770 -0
- matplotlib_rs/_vendor/pyparsing/results.py +929 -0
- matplotlib_rs/_vendor/pyparsing/testing.py +399 -0
- matplotlib_rs/_vendor/pyparsing/unicode.py +357 -0
- matplotlib_rs/_vendor/pyparsing/util.py +515 -0
- matplotlib_rs/_vendor/pyparsing/warnings.py +11 -0
- matplotlib_rs/_vendor/six.py +1004 -0
- matplotlib_rs/animation.py +1843 -0
- matplotlib_rs/artist.py +2302 -0
- matplotlib_rs/axes/__init__.py +19 -0
- matplotlib_rs/axes/_axes.py +9402 -0
- matplotlib_rs/axes/_bar.py +185 -0
- matplotlib_rs/axes/_base.py +5236 -0
- matplotlib_rs/axes/_base_rs.py +727 -0
- matplotlib_rs/axes/_boxplot.py +391 -0
- matplotlib_rs/axes/_hist.py +99 -0
- matplotlib_rs/axes/_secondary_axes.py +357 -0
- matplotlib_rs/axis.py +1963 -0
- matplotlib_rs/backend_bases.py +3760 -0
- matplotlib_rs/backend_managers.py +388 -0
- matplotlib_rs/backend_tools.py +1002 -0
- matplotlib_rs/backends/__init__.py +6 -0
- matplotlib_rs/backends/_backend_pdf_ps.py +451 -0
- matplotlib_rs/backends/backend_agg.py +552 -0
- matplotlib_rs/backends/backend_mixed.py +123 -0
- matplotlib_rs/backends/backend_pdf.py +2711 -0
- matplotlib_rs/backends/backend_pgf.py +1031 -0
- matplotlib_rs/backends/backend_ps.py +1491 -0
- matplotlib_rs/backends/backend_svg.py +1395 -0
- matplotlib_rs/backends/backend_template.py +214 -0
- matplotlib_rs/backends/registry.py +423 -0
- matplotlib_rs/bezier.py +691 -0
- matplotlib_rs/category.py +236 -0
- matplotlib_rs/cbook.py +2762 -0
- matplotlib_rs/cm.py +251 -0
- matplotlib_rs/collections.py +2711 -0
- matplotlib_rs/colorbar.py +1586 -0
- matplotlib_rs/colorizer.py +909 -0
- matplotlib_rs/colors.py +4278 -0
- matplotlib_rs/container.py +256 -0
- matplotlib_rs/contour.py +1756 -0
- matplotlib_rs/dates.py +1847 -0
- matplotlib_rs/dviread.py +1386 -0
- matplotlib_rs/figure.py +3815 -0
- matplotlib_rs/font_manager.py +1855 -0
- matplotlib_rs/ft2font.py +515 -0
- matplotlib_rs/gridspec.py +808 -0
- matplotlib_rs/hatch.py +244 -0
- matplotlib_rs/image.py +1863 -0
- matplotlib_rs/inset.py +291 -0
- matplotlib_rs/layout_engine.py +310 -0
- matplotlib_rs/legend.py +1480 -0
- matplotlib_rs/legend_handler.py +812 -0
- matplotlib_rs/lines.py +1886 -0
- matplotlib_rs/markers.py +908 -0
- matplotlib_rs/mathtext.py +141 -0
- matplotlib_rs/mlab.py +959 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-Bold.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-BoldOblique.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-Oblique.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansDisplay.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-Bold.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-BoldOblique.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-Oblique.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-Bold.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-BoldItalic.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-Italic.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerifDisplay.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/LICENSE_DEJAVU +99 -0
- matplotlib_rs/mpl-data/fonts/ttf/LICENSE_STIX +124 -0
- matplotlib_rs/mpl-data/fonts/ttf/LastResortHE-Regular.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXGeneral.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralBolIta.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralItalic.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXNonUni.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniBolIta.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniIta.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizFiveSymReg.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizFourSymBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizFourSymReg.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizOneSymBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizOneSymReg.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizThreeSymBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizThreeSymReg.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizTwoSymBol.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/STIXSizTwoSymReg.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmb10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmex10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmmi10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmr10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmss10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmsy10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmti10.ttf +0 -0
- matplotlib_rs/mpl-data/fonts/ttf/cmtt10.ttf +0 -0
- matplotlib_rs/mpl-data/images/back-symbolic.svg +46 -0
- matplotlib_rs/mpl-data/images/back.pdf +0 -0
- matplotlib_rs/mpl-data/images/back.png +0 -0
- matplotlib_rs/mpl-data/images/back.svg +46 -0
- matplotlib_rs/mpl-data/images/back_large.png +0 -0
- matplotlib_rs/mpl-data/images/filesave-symbolic.svg +68 -0
- matplotlib_rs/mpl-data/images/filesave.pdf +72 -0
- matplotlib_rs/mpl-data/images/filesave.png +0 -0
- matplotlib_rs/mpl-data/images/filesave.svg +68 -0
- matplotlib_rs/mpl-data/images/filesave_large.png +0 -0
- matplotlib_rs/mpl-data/images/forward-symbolic.svg +46 -0
- matplotlib_rs/mpl-data/images/forward.pdf +0 -0
- matplotlib_rs/mpl-data/images/forward.png +0 -0
- matplotlib_rs/mpl-data/images/forward.svg +46 -0
- matplotlib_rs/mpl-data/images/forward_large.png +0 -0
- matplotlib_rs/mpl-data/images/hand.pdf +0 -0
- matplotlib_rs/mpl-data/images/hand.png +0 -0
- matplotlib_rs/mpl-data/images/hand.svg +130 -0
- matplotlib_rs/mpl-data/images/help-symbolic.svg +52 -0
- matplotlib_rs/mpl-data/images/help.pdf +71 -0
- matplotlib_rs/mpl-data/images/help.png +0 -0
- matplotlib_rs/mpl-data/images/help.svg +52 -0
- matplotlib_rs/mpl-data/images/help_large.png +0 -0
- matplotlib_rs/mpl-data/images/home-symbolic.svg +59 -0
- matplotlib_rs/mpl-data/images/home.pdf +0 -0
- matplotlib_rs/mpl-data/images/home.png +0 -0
- matplotlib_rs/mpl-data/images/home.svg +59 -0
- matplotlib_rs/mpl-data/images/home_large.png +0 -0
- matplotlib_rs/mpl-data/images/matplotlib.pdf +0 -0
- matplotlib_rs/mpl-data/images/matplotlib.png +0 -0
- matplotlib_rs/mpl-data/images/matplotlib.svg +3171 -0
- matplotlib_rs/mpl-data/images/matplotlib_large.png +0 -0
- matplotlib_rs/mpl-data/images/move-symbolic.svg +73 -0
- matplotlib_rs/mpl-data/images/move.pdf +0 -0
- matplotlib_rs/mpl-data/images/move.png +0 -0
- matplotlib_rs/mpl-data/images/move.svg +73 -0
- matplotlib_rs/mpl-data/images/move_large.png +0 -0
- matplotlib_rs/mpl-data/images/qt4_editor_options.pdf +0 -0
- matplotlib_rs/mpl-data/images/qt4_editor_options.png +0 -0
- matplotlib_rs/mpl-data/images/qt4_editor_options.svg +48 -0
- matplotlib_rs/mpl-data/images/qt4_editor_options_large.png +0 -0
- matplotlib_rs/mpl-data/images/subplots-symbolic.svg +81 -0
- matplotlib_rs/mpl-data/images/subplots.pdf +0 -0
- matplotlib_rs/mpl-data/images/subplots.png +0 -0
- matplotlib_rs/mpl-data/images/subplots.svg +81 -0
- matplotlib_rs/mpl-data/images/subplots_large.png +0 -0
- matplotlib_rs/mpl-data/images/zoom_to_rect-symbolic.svg +40 -0
- matplotlib_rs/mpl-data/images/zoom_to_rect.pdf +69 -0
- matplotlib_rs/mpl-data/images/zoom_to_rect.png +0 -0
- matplotlib_rs/mpl-data/images/zoom_to_rect.svg +40 -0
- matplotlib_rs/mpl-data/images/zoom_to_rect_large.png +0 -0
- matplotlib_rs/mpl-data/kpsewhich.lua +4 -0
- matplotlib_rs/mpl-data/matplotlibrc +849 -0
- matplotlib_rs/mpl-data/plot_directive/plot_directive.css +16 -0
- matplotlib_rs/mpl-data/sample_data/Minduka_Present_Blue_Pack.png +0 -0
- matplotlib_rs/mpl-data/sample_data/README.txt +2 -0
- matplotlib_rs/mpl-data/sample_data/Stocks.csv +526 -0
- matplotlib_rs/mpl-data/sample_data/axes_grid/bivariate_normal.npy +0 -0
- matplotlib_rs/mpl-data/sample_data/data_x_x2_x3.csv +11 -0
- matplotlib_rs/mpl-data/sample_data/eeg.dat +0 -0
- matplotlib_rs/mpl-data/sample_data/embedding_in_wx3.xrc +65 -0
- matplotlib_rs/mpl-data/sample_data/goog.npz +0 -0
- matplotlib_rs/mpl-data/sample_data/grace_hopper.jpg +0 -0
- matplotlib_rs/mpl-data/sample_data/jacksboro_fault_dem.npz +0 -0
- matplotlib_rs/mpl-data/sample_data/logo2.png +0 -0
- matplotlib_rs/mpl-data/sample_data/membrane.dat +0 -0
- matplotlib_rs/mpl-data/sample_data/msft.csv +66 -0
- matplotlib_rs/mpl-data/sample_data/s1045.ima.gz +0 -0
- matplotlib_rs/mpl-data/sample_data/topobathy.npz +0 -0
- matplotlib_rs/mpl-data/stylelib/Solarize_Light2.mplstyle +53 -0
- matplotlib_rs/mpl-data/stylelib/_classic_test_patch.mplstyle +8 -0
- matplotlib_rs/mpl-data/stylelib/_mpl-gallery-nogrid.mplstyle +19 -0
- matplotlib_rs/mpl-data/stylelib/_mpl-gallery.mplstyle +19 -0
- matplotlib_rs/mpl-data/stylelib/bmh.mplstyle +27 -0
- matplotlib_rs/mpl-data/stylelib/classic.mplstyle +491 -0
- matplotlib_rs/mpl-data/stylelib/dark_background.mplstyle +26 -0
- matplotlib_rs/mpl-data/stylelib/fast.mplstyle +11 -0
- matplotlib_rs/mpl-data/stylelib/fivethirtyeight.mplstyle +37 -0
- matplotlib_rs/mpl-data/stylelib/ggplot.mplstyle +39 -0
- matplotlib_rs/mpl-data/stylelib/grayscale.mplstyle +29 -0
- matplotlib_rs/mpl-data/stylelib/petroff10.mplstyle +5 -0
- matplotlib_rs/mpl-data/stylelib/petroff6.mplstyle +5 -0
- matplotlib_rs/mpl-data/stylelib/petroff8.mplstyle +5 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-bright.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-colorblind.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-dark-palette.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-dark.mplstyle +30 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-darkgrid.mplstyle +30 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-deep.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-muted.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-notebook.mplstyle +21 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-paper.mplstyle +21 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-pastel.mplstyle +3 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-poster.mplstyle +21 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-talk.mplstyle +21 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-ticks.mplstyle +30 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-white.mplstyle +30 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-whitegrid.mplstyle +30 -0
- matplotlib_rs/mpl-data/stylelib/seaborn-v0_8.mplstyle +57 -0
- matplotlib_rs/mpl-data/stylelib/tableau-colorblind10.mplstyle +3 -0
- matplotlib_rs/mpl_toolkits/__init__.py +3 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/__init__.py +11 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/anchored_artists.py +415 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/axes_divider.py +619 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/axes_grid.py +565 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/axes_rgb.py +158 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/axes_size.py +272 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/inset_locator.py +525 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/mpl_axes.py +129 -0
- matplotlib_rs/mpl_toolkits/axes_grid1/parasite_axes.py +261 -0
- matplotlib_rs/mpl_toolkits/axisartist/__init__.py +15 -0
- matplotlib_rs/mpl_toolkits/axisartist/angle_helper.py +396 -0
- matplotlib_rs/mpl_toolkits/axisartist/axes_divider.py +3 -0
- matplotlib_rs/mpl_toolkits/axisartist/axis_artist.py +1148 -0
- matplotlib_rs/mpl_toolkits/axisartist/axisline_style.py +193 -0
- matplotlib_rs/mpl_toolkits/axisartist/axislines.py +475 -0
- matplotlib_rs/mpl_toolkits/axisartist/floating_axes.py +265 -0
- matplotlib_rs/mpl_toolkits/axisartist/grid_finder.py +329 -0
- matplotlib_rs/mpl_toolkits/axisartist/grid_helper_curvelinear.py +353 -0
- matplotlib_rs/mpl_toolkits/axisartist/parasite_axes.py +8 -0
- matplotlib_rs/mpl_toolkits/mplot3d/__init__.py +4 -0
- matplotlib_rs/mpl_toolkits/mplot3d/art3d.py +1758 -0
- matplotlib_rs/mpl_toolkits/mplot3d/axes3d.py +4462 -0
- matplotlib_rs/mpl_toolkits/mplot3d/axis3d.py +807 -0
- matplotlib_rs/mpl_toolkits/mplot3d/proj3d.py +270 -0
- matplotlib_rs/offsetbox.py +1726 -0
- matplotlib_rs/patches.py +5049 -0
- matplotlib_rs/path.py +1147 -0
- matplotlib_rs/patheffects.py +512 -0
- matplotlib_rs/projections/__init__.py +126 -0
- matplotlib_rs/projections/geo.py +512 -0
- matplotlib_rs/projections/polar.py +1518 -0
- matplotlib_rs/pylab.py +68 -0
- matplotlib_rs/pyplot.py +4834 -0
- matplotlib_rs/quiver.py +1236 -0
- matplotlib_rs/rcsetup.py +3435 -0
- matplotlib_rs/sankey.py +815 -0
- matplotlib_rs/scale.py +1002 -0
- matplotlib_rs/spines.py +618 -0
- matplotlib_rs/stackplot.py +144 -0
- matplotlib_rs/streamplot.py +768 -0
- matplotlib_rs/style/__init__.py +269 -0
- matplotlib_rs/style/core.py +28 -0
- matplotlib_rs/table.py +860 -0
- matplotlib_rs/texmanager.py +375 -0
- matplotlib_rs/text.py +2412 -0
- matplotlib_rs/textpath.py +377 -0
- matplotlib_rs/ticker.py +3111 -0
- matplotlib_rs/transforms.py +3069 -0
- matplotlib_rs/tri/__init__.py +24 -0
- matplotlib_rs/tri/_triangulation.py +248 -0
- matplotlib_rs/tri/_tricontour.py +271 -0
- matplotlib_rs/tri/_trifinder.py +97 -0
- matplotlib_rs/tri/_triinterpolate.py +1575 -0
- matplotlib_rs/tri/_tripcolor.py +170 -0
- matplotlib_rs/tri/_triplot.py +87 -0
- matplotlib_rs/tri/_trirefine.py +308 -0
- matplotlib_rs/tri/_tritools.py +264 -0
- matplotlib_rs/typing.py +597 -0
- matplotlib_rs/units.py +196 -0
- matplotlib_rs/widgets.py +4455 -0
- matplotlib_rs-0.0.8.dist-info/METADATA +392 -0
- matplotlib_rs-0.0.8.dist-info/RECORD +352 -0
- matplotlib_rs-0.0.8.dist-info/WHEEL +4 -0
- matplotlib_rs-0.0.8.dist-info/sboms/matplotlib-rs.cyclonedx.json +4390 -0
matplotlib_rs/axis.py
ADDED
|
@@ -0,0 +1,1963 @@
|
|
|
1
|
+
"""
|
|
2
|
+
`matplotlib.axis` for matplotlib_rs.
|
|
3
|
+
|
|
4
|
+
Limits, scales, units, locators and formatters live in Python exactly as in
|
|
5
|
+
matplotlib (much of this module is matplotlib's own code). The ticks
|
|
6
|
+
themselves (tick lines, grid lines, tick labels) and the axis label and
|
|
7
|
+
offset text are owned by the Rust core, which updates and draws them; the
|
|
8
|
+
objects returned by ``get_ticklabels()`` & co. are Python views of them.
|
|
9
|
+
Locators and formatters of matplotlib's standard classes are mirrored by
|
|
10
|
+
native Rust implementations; any other is called back from Rust.
|
|
11
|
+
|
|
12
|
+
Parts of this file are from matplotlib 3.11 (see licenses/LICENSE_MATPLOTLIB).
|
|
13
|
+
"""
|
|
14
|
+
import datetime
|
|
15
|
+
import functools
|
|
16
|
+
import logging
|
|
17
|
+
from numbers import Real
|
|
18
|
+
import warnings
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
import matplotlib_rs as mpl
|
|
23
|
+
from . import _api, cbook
|
|
24
|
+
from . import artist as martist
|
|
25
|
+
from . import colors as mcolors
|
|
26
|
+
from . import lines as mlines
|
|
27
|
+
from . import scale as mscale
|
|
28
|
+
from . import text as mtext
|
|
29
|
+
from . import ticker as mticker
|
|
30
|
+
from . import transforms as mtransforms
|
|
31
|
+
from . import units as munits
|
|
32
|
+
from .ticker import NullLocator
|
|
33
|
+
|
|
34
|
+
_log = logging.getLogger(__name__)
|
|
35
|
+
|
|
36
|
+
GRIDLINE_INTERPOLATION_STEPS = 180
|
|
37
|
+
|
|
38
|
+
_line_inspector = martist.ArtistInspector(mlines.Line2D)
|
|
39
|
+
_line_param_names = _line_inspector.get_setters()
|
|
40
|
+
_line_param_aliases = [next(iter(d)) for d in _line_inspector.aliasd.values()]
|
|
41
|
+
_gridline_param_names = ['grid_' + name
|
|
42
|
+
for name in _line_param_names + _line_param_aliases]
|
|
43
|
+
|
|
44
|
+
# --------------------------------------------------------------------------
|
|
45
|
+
# Native tick helpers
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _locator_spec(loc):
|
|
49
|
+
"""Rust spec for a locator, or None if it has to run in Python."""
|
|
50
|
+
t = type(loc)
|
|
51
|
+
if t is mticker.AutoLocator:
|
|
52
|
+
if (loc._nbins == "auto" and list(loc._steps) == [1, 2, 2.5, 5, 10]
|
|
53
|
+
and not loc._integer and not loc._symmetric and loc._prune is None
|
|
54
|
+
and loc._min_n_ticks == 2):
|
|
55
|
+
return ("auto",)
|
|
56
|
+
if t in (mticker.MaxNLocator, mticker.AutoLocator):
|
|
57
|
+
return ("maxn", loc._nbins if loc._nbins == "auto" else int(loc._nbins),
|
|
58
|
+
[float(s) for s in loc._steps], bool(loc._integer), bool(loc._symmetric),
|
|
59
|
+
loc._prune, int(loc._min_n_ticks))
|
|
60
|
+
if t is mticker.NullLocator:
|
|
61
|
+
return ("null",)
|
|
62
|
+
if t is mticker.FixedLocator:
|
|
63
|
+
return ("fixed", [float(v) for v in np.asarray(loc.locs, float).ravel()], loc.nbins)
|
|
64
|
+
if t is mticker.MultipleLocator:
|
|
65
|
+
return ("multiple", float(loc._edge.step), float(loc._offset))
|
|
66
|
+
if t is mticker.LinearLocator and not loc.presets:
|
|
67
|
+
return ("linear", int(loc.numticks))
|
|
68
|
+
if t is mticker.IndexLocator:
|
|
69
|
+
return ("index", float(loc._base), float(loc.offset))
|
|
70
|
+
if t is mticker.AutoMinorLocator:
|
|
71
|
+
n = loc.ndivs
|
|
72
|
+
return ("autominor", None if n is None else ("auto" if n == "auto" else int(n)))
|
|
73
|
+
if t is mticker.LogLocator:
|
|
74
|
+
subs = loc._subs
|
|
75
|
+
if isinstance(subs, str):
|
|
76
|
+
s = subs
|
|
77
|
+
else:
|
|
78
|
+
s = [float(v) for v in np.asarray(subs).ravel()]
|
|
79
|
+
return ("log", float(loc._base), s,
|
|
80
|
+
None if loc.numticks == "auto" else int(loc.numticks))
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _formatter_spec(fmt):
|
|
85
|
+
"""Rust spec for a formatter, or None if it has to run in Python."""
|
|
86
|
+
t = type(fmt)
|
|
87
|
+
if t is mticker.ScalarFormatter:
|
|
88
|
+
if isinstance(fmt._useOffset, bool) and not (fmt._useOffset is False and fmt.offset):
|
|
89
|
+
uo = bool(fmt._useOffset)
|
|
90
|
+
else:
|
|
91
|
+
uo = float(fmt.offset)
|
|
92
|
+
pl = fmt._powerlimits
|
|
93
|
+
return ("scalar", uo, bool(fmt._useMathText), bool(fmt._useLocale),
|
|
94
|
+
bool(fmt._usetex), bool(fmt._scientific), (int(pl[0]), int(pl[1])))
|
|
95
|
+
if t is mticker.NullFormatter:
|
|
96
|
+
return ("null",)
|
|
97
|
+
if t is mticker.FixedFormatter:
|
|
98
|
+
return ("fixed", [str(s) for s in fmt.seq], str(fmt.offset_string))
|
|
99
|
+
kinds = {mticker.LogFormatterSciNotation: "logsci",
|
|
100
|
+
mticker.LogFormatterMathtext: "logmath",
|
|
101
|
+
mticker.LogFormatter: "log",
|
|
102
|
+
mticker.LogFormatterExponent: "logexp"}
|
|
103
|
+
if t in kinds and fmt._linthresh is None:
|
|
104
|
+
return (kinds[t], float(fmt._base), bool(fmt.labelOnlyBase),
|
|
105
|
+
tuple(map(float, fmt.minor_thresholds)), None)
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class _PyLocatorAdapter:
|
|
110
|
+
"""Lets the Rust core call a Python locator."""
|
|
111
|
+
|
|
112
|
+
def __init__(self, loc):
|
|
113
|
+
self._loc = loc
|
|
114
|
+
self.rs_is_null = isinstance(loc, mticker.NullLocator)
|
|
115
|
+
|
|
116
|
+
def rs_call(self, info):
|
|
117
|
+
return [float(v) for v in np.asarray(self._loc(), float).ravel()]
|
|
118
|
+
|
|
119
|
+
def rs_tick_values(self, vmin, vmax, info):
|
|
120
|
+
return [float(v) for v in np.asarray(self._loc.tick_values(vmin, vmax), float).ravel()]
|
|
121
|
+
|
|
122
|
+
def rs_nonsingular(self, v0, v1):
|
|
123
|
+
a, b = self._loc.nonsingular(v0, v1)
|
|
124
|
+
return float(a), float(b)
|
|
125
|
+
|
|
126
|
+
def rs_view_limits(self, v0, v1):
|
|
127
|
+
a, b = self._loc.view_limits(v0, v1)
|
|
128
|
+
return float(a), float(b)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class _PyFormatterAdapter:
|
|
132
|
+
"""Lets the Rust core call a Python formatter."""
|
|
133
|
+
|
|
134
|
+
def __init__(self, fmt):
|
|
135
|
+
self._fmt = fmt
|
|
136
|
+
|
|
137
|
+
def rs_format_ticks(self, values, info):
|
|
138
|
+
return [str(s) for s in self._fmt.format_ticks(np.asarray(values, float))]
|
|
139
|
+
|
|
140
|
+
def rs_get_offset(self):
|
|
141
|
+
return str(self._fmt.get_offset())
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# --------------------------------------------------------------------------
|
|
145
|
+
# Ticks
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class Tick(martist.Artist):
|
|
149
|
+
"""
|
|
150
|
+
One tick of an `Axis`: a view of the tick owned by the Rust core.
|
|
151
|
+
|
|
152
|
+
``tick1line``, ``tick2line``, ``gridline``, ``label1`` and ``label2``
|
|
153
|
+
are views of the Rust artists, so changes to them are drawn.
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
def __init__(self, axis, idx, major, line_handles, label1, label2):
|
|
157
|
+
super().__init__()
|
|
158
|
+
self.set_figure(axis.axes.get_figure(root=False))
|
|
159
|
+
self._axis_proxy = axis
|
|
160
|
+
self._idx = idx
|
|
161
|
+
self._major = major
|
|
162
|
+
# Rust handles of tick1line, tick2line and gridline; their Python
|
|
163
|
+
# views are made when first used
|
|
164
|
+
self._rs_line_handles = line_handles
|
|
165
|
+
self._rs_line_views = {}
|
|
166
|
+
self.label1 = label1
|
|
167
|
+
self.label2 = label2
|
|
168
|
+
self.axes = axis.axes
|
|
169
|
+
|
|
170
|
+
def _rs_line(self, i):
|
|
171
|
+
v = self._rs_line_views.get(i)
|
|
172
|
+
if v is not None and v._h is self._rs_line_handles[i]:
|
|
173
|
+
v._rs_refresh()
|
|
174
|
+
return v
|
|
175
|
+
v = _wrap_rs_line(self._axis_proxy._line_cache, self._rs_line_handles[i], self.axes)
|
|
176
|
+
self._rs_line_views[i] = v
|
|
177
|
+
return v
|
|
178
|
+
|
|
179
|
+
def _rs_line_property(i):
|
|
180
|
+
def fget(self):
|
|
181
|
+
return self._rs_line(i)
|
|
182
|
+
|
|
183
|
+
def fset(self, line):
|
|
184
|
+
self._rs_line_views[i] = line
|
|
185
|
+
|
|
186
|
+
return property(fget, fset)
|
|
187
|
+
|
|
188
|
+
tick1line = _rs_line_property(0)
|
|
189
|
+
tick2line = _rs_line_property(1)
|
|
190
|
+
gridline = _rs_line_property(2)
|
|
191
|
+
del _rs_line_property
|
|
192
|
+
|
|
193
|
+
def __repr__(self):
|
|
194
|
+
return f"<{type(self).__name__} {self._idx} of {self._axis_proxy}>"
|
|
195
|
+
|
|
196
|
+
def get_loc(self):
|
|
197
|
+
loc = self.__dict__.get("_loc")
|
|
198
|
+
if loc is None:
|
|
199
|
+
locs = self._axis_proxy.get_ticklocs(minor=not self._major)
|
|
200
|
+
loc = locs[self._idx] if self._idx < len(locs) else np.nan
|
|
201
|
+
return loc
|
|
202
|
+
|
|
203
|
+
@property
|
|
204
|
+
def _size(self):
|
|
205
|
+
return self._axis_proxy._get_tick_kw(self._major).get(
|
|
206
|
+
"size", mpl.rcParams[f"{self._axis_proxy.axis_name}tick.{self._which()}.size"])
|
|
207
|
+
|
|
208
|
+
@property
|
|
209
|
+
def _tickdir(self):
|
|
210
|
+
return self.get_tickdir()
|
|
211
|
+
|
|
212
|
+
@property
|
|
213
|
+
def label(self):
|
|
214
|
+
return self.label1
|
|
215
|
+
|
|
216
|
+
def get_children(self):
|
|
217
|
+
return [self.tick1line, self.tick2line, self.gridline, self.label1, self.label2]
|
|
218
|
+
|
|
219
|
+
def _which(self):
|
|
220
|
+
return "major" if self._major else "minor"
|
|
221
|
+
|
|
222
|
+
def set_label1(self, s):
|
|
223
|
+
self.label1.set_text(s)
|
|
224
|
+
|
|
225
|
+
set_label = set_label1
|
|
226
|
+
|
|
227
|
+
def set_label2(self, s):
|
|
228
|
+
self.label2.set_text(s)
|
|
229
|
+
|
|
230
|
+
def set_pad(self, val):
|
|
231
|
+
self._axis_proxy.set_tick_params(which=self._which(), pad=val)
|
|
232
|
+
|
|
233
|
+
def get_pad(self):
|
|
234
|
+
return self._axis_proxy._get_tick_kw(self._major).get("pad", mpl.rcParams[
|
|
235
|
+
f"{self._axis_proxy.axis_name}tick.{self._which()}.pad"])
|
|
236
|
+
|
|
237
|
+
def get_tickdir(self):
|
|
238
|
+
return self._axis_proxy._get_tick_kw(self._major).get(
|
|
239
|
+
"tickdir", mpl.rcParams[f"{self._axis_proxy.axis_name}tick.direction"])
|
|
240
|
+
|
|
241
|
+
def get_tick_padding(self):
|
|
242
|
+
size = self._axis_proxy._get_tick_kw(self._major).get(
|
|
243
|
+
"size", mpl.rcParams[f"{self._axis_proxy.axis_name}tick.{self._which()}.size"])
|
|
244
|
+
return size * {"in": 0.0, "inout": 0.5, "out": 1.0}[self.get_tickdir()]
|
|
245
|
+
|
|
246
|
+
def set_visible(self, b):
|
|
247
|
+
for a in self.get_children():
|
|
248
|
+
a.set_visible(b)
|
|
249
|
+
|
|
250
|
+
def get_visible(self):
|
|
251
|
+
return True
|
|
252
|
+
|
|
253
|
+
def _apply_params(self, **kwargs):
|
|
254
|
+
self._axis_proxy.set_tick_params(which=self._which(), **kwargs)
|
|
255
|
+
|
|
256
|
+
def update_position(self, loc):
|
|
257
|
+
self._loc = loc
|
|
258
|
+
|
|
259
|
+
def set_clip_path(self, path, transform=None):
|
|
260
|
+
self.gridline.set_clip_path(path, transform)
|
|
261
|
+
|
|
262
|
+
def get_view_interval(self):
|
|
263
|
+
return self._axis_proxy.get_view_interval()
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
class XTick(Tick):
|
|
267
|
+
__name__ = 'xtick'
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
class YTick(Tick):
|
|
271
|
+
__name__ = 'ytick'
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
class Ticker:
|
|
275
|
+
"""
|
|
276
|
+
A container for the objects defining tick position and format.
|
|
277
|
+
"""
|
|
278
|
+
|
|
279
|
+
def __init__(self):
|
|
280
|
+
self._locator = None
|
|
281
|
+
self._formatter = None
|
|
282
|
+
self._locator_is_default = True
|
|
283
|
+
self._formatter_is_default = True
|
|
284
|
+
|
|
285
|
+
@property
|
|
286
|
+
def locator(self):
|
|
287
|
+
return self._locator
|
|
288
|
+
|
|
289
|
+
@locator.setter
|
|
290
|
+
def locator(self, locator):
|
|
291
|
+
if not isinstance(locator, mticker.Locator):
|
|
292
|
+
raise TypeError('locator must be a subclass of '
|
|
293
|
+
'matplotlib.ticker.Locator')
|
|
294
|
+
self._locator = locator
|
|
295
|
+
|
|
296
|
+
@property
|
|
297
|
+
def formatter(self):
|
|
298
|
+
return self._formatter
|
|
299
|
+
|
|
300
|
+
@formatter.setter
|
|
301
|
+
def formatter(self, formatter):
|
|
302
|
+
if not isinstance(formatter, mticker.Formatter):
|
|
303
|
+
raise TypeError('formatter must be a subclass of '
|
|
304
|
+
'matplotlib.ticker.Formatter')
|
|
305
|
+
self._formatter = formatter
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
# --------------------------------------------------------------------------
|
|
309
|
+
# Axis
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def _wrap_rs_text(cache, h, owner):
|
|
313
|
+
"""A Python Text view of an existing Rust text handle."""
|
|
314
|
+
key = h.ident()
|
|
315
|
+
t = cache.get(key)
|
|
316
|
+
if t is None:
|
|
317
|
+
t = mtext._RsText._from_rs(h, owner)
|
|
318
|
+
cache[key] = t
|
|
319
|
+
else:
|
|
320
|
+
t._rs_refresh()
|
|
321
|
+
return t
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def _wrap_rs_line(cache, h, owner):
|
|
325
|
+
key = h.ident()
|
|
326
|
+
ln = cache.get(key)
|
|
327
|
+
if ln is None:
|
|
328
|
+
ln = mlines._RsLine2D._from_rs(h, owner)
|
|
329
|
+
cache[key] = ln
|
|
330
|
+
else:
|
|
331
|
+
ln._rs_refresh()
|
|
332
|
+
return ln
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _rs_prop(name, axis_key, conv=lambda v: v, default=None):
|
|
336
|
+
"""A plain attribute that is also pushed to the Rust axis as `axis_key`."""
|
|
337
|
+
attr = "_rs_" + name
|
|
338
|
+
|
|
339
|
+
def getter(self):
|
|
340
|
+
return self.__dict__.get(attr, default)
|
|
341
|
+
|
|
342
|
+
def setter(self, v):
|
|
343
|
+
self.__dict__[attr] = v
|
|
344
|
+
if self.__dict__.get("_axes") is not None:
|
|
345
|
+
self.axes._rs.axis_set(self.axis_name, axis_key, conv(v))
|
|
346
|
+
|
|
347
|
+
return property(getter, setter)
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
# Axis classes of other implementations (the Python one used by polar and
|
|
351
|
+
# geo axes, see _axis_py.py); matplotlib treats them like Axis.
|
|
352
|
+
_rs_other_axis_classes = []
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
class Axis(martist.Artist):
|
|
356
|
+
"""
|
|
357
|
+
Base class for `.XAxis` and `.YAxis`.
|
|
358
|
+
"""
|
|
359
|
+
OFFSETTEXTPAD = 3
|
|
360
|
+
_tick_class = None
|
|
361
|
+
converter = _api.deprecate_privatize_attribute(
|
|
362
|
+
"3.10",
|
|
363
|
+
alternative="get_converter and set_converter methods"
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
labelpad = _rs_prop("labelpad", "labelpad", float)
|
|
367
|
+
label_position = _rs_prop("label_position", "label_position", str)
|
|
368
|
+
_tick_position = _rs_prop("tick_position", "tick_position", str, "bottom")
|
|
369
|
+
_autolabelpos = _rs_prop("autolabelpos", "autolabelpos", bool)
|
|
370
|
+
|
|
371
|
+
def __str__(self):
|
|
372
|
+
return "{}({},{})".format(
|
|
373
|
+
type(self).__name__, *self.axes.transAxes.transform((0, 0)))
|
|
374
|
+
|
|
375
|
+
def __init__(self, axes, *, pickradius=15, clear=True):
|
|
376
|
+
super().__init__()
|
|
377
|
+
self._remove_overlapping_locs = True
|
|
378
|
+
self.set_figure(axes.get_figure(root=False))
|
|
379
|
+
self.isDefault_label = True
|
|
380
|
+
self.axes = axes
|
|
381
|
+
self.major = Ticker()
|
|
382
|
+
self.minor = Ticker()
|
|
383
|
+
self.callbacks = cbook.CallbackRegistry(signals=["units"])
|
|
384
|
+
self._autolabelpos = True
|
|
385
|
+
self._text_cache = {}
|
|
386
|
+
self._line_cache = {}
|
|
387
|
+
self._tick_cache = {}
|
|
388
|
+
self._pushed = {}
|
|
389
|
+
self.label = _wrap_rs_text(self._text_cache, axes._rs.axis_label(self.axis_name), axes)
|
|
390
|
+
self.offsetText = _wrap_rs_text(self._text_cache, axes._rs.offset_text(self.axis_name), axes)
|
|
391
|
+
self.labelpad = mpl.rcParams['axes.labelpad']
|
|
392
|
+
self.pickradius = pickradius
|
|
393
|
+
self._major_tick_kw = dict()
|
|
394
|
+
self._minor_tick_kw = dict()
|
|
395
|
+
self._scale = mscale.LinearScale(self)
|
|
396
|
+
if clear:
|
|
397
|
+
self.clear()
|
|
398
|
+
else:
|
|
399
|
+
self._converter = None
|
|
400
|
+
self._converter_is_explicit = False
|
|
401
|
+
self.units = None
|
|
402
|
+
self._autoscale_on = True
|
|
403
|
+
|
|
404
|
+
# -- Rust helpers ----------------------------------------------------
|
|
405
|
+
@property
|
|
406
|
+
def _rs(self):
|
|
407
|
+
return self.axes._rs
|
|
408
|
+
|
|
409
|
+
def _get_tick_kw(self, major):
|
|
410
|
+
return self._major_tick_kw if major else self._minor_tick_kw
|
|
411
|
+
|
|
412
|
+
def _rs_sync_tickers(self):
|
|
413
|
+
"""Push the current locators and formatters if they changed."""
|
|
414
|
+
rs = self.axes._rs
|
|
415
|
+
for which, tk in (("major", self.major), ("minor", self.minor)):
|
|
416
|
+
minor = which == "minor"
|
|
417
|
+
loc = tk.locator
|
|
418
|
+
if loc is not None:
|
|
419
|
+
spec = _locator_spec(loc)
|
|
420
|
+
key = (which, "loc")
|
|
421
|
+
if spec is None:
|
|
422
|
+
old = self._pushed.get(key)
|
|
423
|
+
if not (isinstance(old, tuple) and old[0] == "py" and old[1] is loc):
|
|
424
|
+
rs.set_locator(self.axis_name, ("py", _PyLocatorAdapter(loc)), minor)
|
|
425
|
+
self._pushed[key] = ("py", loc)
|
|
426
|
+
elif self._pushed.get(key) != spec:
|
|
427
|
+
rs.set_locator(self.axis_name, spec, minor)
|
|
428
|
+
self._pushed[key] = spec
|
|
429
|
+
fmt = tk.formatter
|
|
430
|
+
if fmt is not None:
|
|
431
|
+
spec = _formatter_spec(fmt)
|
|
432
|
+
key = (which, "fmt")
|
|
433
|
+
if spec is None:
|
|
434
|
+
old = self._pushed.get(key)
|
|
435
|
+
if not (isinstance(old, tuple) and old[0] == "py" and old[1] is fmt):
|
|
436
|
+
rs.set_formatter(self.axis_name, ("py", _PyFormatterAdapter(fmt)), minor)
|
|
437
|
+
self._pushed[key] = ("py", fmt)
|
|
438
|
+
elif self._pushed.get(key) != spec:
|
|
439
|
+
rs.set_formatter(self.axis_name, spec, minor)
|
|
440
|
+
self._pushed[key] = spec
|
|
441
|
+
|
|
442
|
+
def _rs_push_scale(self):
|
|
443
|
+
s = self._scale
|
|
444
|
+
name = s.name
|
|
445
|
+
kw = {}
|
|
446
|
+
if name == "log":
|
|
447
|
+
kw = dict(base=float(s.base),
|
|
448
|
+
subs=None if s.subs is None else [float(v) for v in s.subs],
|
|
449
|
+
clip=bool(getattr(s._transform, "_clip", True)))
|
|
450
|
+
elif name == "symlog":
|
|
451
|
+
tr = s._transform
|
|
452
|
+
kw = dict(base=float(tr.base), linthresh=float(tr.linthresh),
|
|
453
|
+
linscale=float(tr.linscale),
|
|
454
|
+
subs=None if s.subs is None else [float(v) for v in s.subs])
|
|
455
|
+
elif name == "logit":
|
|
456
|
+
kw = dict(clip=bool(getattr(s._transform, "_clip", False)))
|
|
457
|
+
elif name == "asinh":
|
|
458
|
+
kw = dict(linear_width=float(s.linear_width))
|
|
459
|
+
if name not in ("linear", "log", "symlog", "logit", "asinh"):
|
|
460
|
+
# any other scale: the Rust axis evaluates its transform in Python
|
|
461
|
+
from . import _rs_register_scale_transform
|
|
462
|
+
kw = dict(custom_id=_rs_register_scale_transform(s.get_transform()))
|
|
463
|
+
name = "custom"
|
|
464
|
+
self.axes._rs.set_scale(self.axis_name, name, **kw)
|
|
465
|
+
# the Rust axis resets its tick helpers with the scale
|
|
466
|
+
self._pushed = {}
|
|
467
|
+
|
|
468
|
+
def _rs_prepare(self):
|
|
469
|
+
"""Bring the Rust axis up to date before reading its ticks."""
|
|
470
|
+
self.axes._unstale_viewLim()
|
|
471
|
+
self._rs_sync_tickers()
|
|
472
|
+
martist._sync_dirty()
|
|
473
|
+
|
|
474
|
+
# -- properties ------------------------------------------------------
|
|
475
|
+
@property
|
|
476
|
+
def isDefault_majloc(self):
|
|
477
|
+
return self.major._locator_is_default
|
|
478
|
+
|
|
479
|
+
@isDefault_majloc.setter
|
|
480
|
+
def isDefault_majloc(self, value):
|
|
481
|
+
self.major._locator_is_default = value
|
|
482
|
+
|
|
483
|
+
@property
|
|
484
|
+
def isDefault_majfmt(self):
|
|
485
|
+
return self.major._formatter_is_default
|
|
486
|
+
|
|
487
|
+
@isDefault_majfmt.setter
|
|
488
|
+
def isDefault_majfmt(self, value):
|
|
489
|
+
self.major._formatter_is_default = value
|
|
490
|
+
|
|
491
|
+
@property
|
|
492
|
+
def isDefault_minloc(self):
|
|
493
|
+
return self.minor._locator_is_default
|
|
494
|
+
|
|
495
|
+
@isDefault_minloc.setter
|
|
496
|
+
def isDefault_minloc(self, value):
|
|
497
|
+
self.minor._locator_is_default = value
|
|
498
|
+
|
|
499
|
+
@property
|
|
500
|
+
def isDefault_minfmt(self):
|
|
501
|
+
return self.minor._formatter_is_default
|
|
502
|
+
|
|
503
|
+
@isDefault_minfmt.setter
|
|
504
|
+
def isDefault_minfmt(self, value):
|
|
505
|
+
self.minor._formatter_is_default = value
|
|
506
|
+
|
|
507
|
+
def _get_shared_axes(self):
|
|
508
|
+
"""Return a list of shared Axes for current axis."""
|
|
509
|
+
return self.axes._shared_axes[
|
|
510
|
+
self._get_axis_name()].get_siblings(self.axes)
|
|
511
|
+
|
|
512
|
+
def _get_shared_axis(self):
|
|
513
|
+
"""Return list of shared axis for current axis."""
|
|
514
|
+
name = self._get_axis_name()
|
|
515
|
+
return [ax._axis_map[name] for ax in self._get_shared_axes()]
|
|
516
|
+
|
|
517
|
+
def _get_axis_name(self):
|
|
518
|
+
"""Return the axis name."""
|
|
519
|
+
return self.axis_name
|
|
520
|
+
|
|
521
|
+
def get_remove_overlapping_locs(self):
|
|
522
|
+
return self._remove_overlapping_locs
|
|
523
|
+
|
|
524
|
+
def set_remove_overlapping_locs(self, val):
|
|
525
|
+
self._remove_overlapping_locs = bool(val)
|
|
526
|
+
self.axes._rs.axis_set(self.axis_name, "remove_overlapping_locs", bool(val))
|
|
527
|
+
|
|
528
|
+
remove_overlapping_locs = property(
|
|
529
|
+
get_remove_overlapping_locs, set_remove_overlapping_locs,
|
|
530
|
+
doc=('If minor ticker locations that overlap with major '
|
|
531
|
+
'ticker locations should be trimmed.'))
|
|
532
|
+
|
|
533
|
+
@property
|
|
534
|
+
def pickradius(self):
|
|
535
|
+
return self._pickradius
|
|
536
|
+
|
|
537
|
+
@pickradius.setter
|
|
538
|
+
def pickradius(self, pickradius):
|
|
539
|
+
if not isinstance(pickradius, Real) or pickradius < 0:
|
|
540
|
+
raise ValueError("pick radius should be a distance")
|
|
541
|
+
self._pickradius = pickradius
|
|
542
|
+
|
|
543
|
+
def get_pickradius(self):
|
|
544
|
+
return self._pickradius
|
|
545
|
+
|
|
546
|
+
def set_pickradius(self, pickradius):
|
|
547
|
+
self.pickradius = pickradius
|
|
548
|
+
|
|
549
|
+
def set_label_coords(self, x, y, transform=None):
|
|
550
|
+
self._autolabelpos = False
|
|
551
|
+
if transform is None:
|
|
552
|
+
transform = self.axes.transAxes
|
|
553
|
+
self.label.set_transform(transform)
|
|
554
|
+
self.label.set_position((x, y))
|
|
555
|
+
self.stale = True
|
|
556
|
+
|
|
557
|
+
# -- visibility & zorder are also Rust state --------------------------
|
|
558
|
+
def set_visible(self, b):
|
|
559
|
+
super().set_visible(b)
|
|
560
|
+
self.axes._rs.axis_set(self.axis_name, "visible", bool(b))
|
|
561
|
+
|
|
562
|
+
def set_zorder(self, level):
|
|
563
|
+
if level is None:
|
|
564
|
+
level = self.__class__.zorder
|
|
565
|
+
self.zorder = level
|
|
566
|
+
self.axes._rs.axis_set(self.axis_name, "zorder", float(level))
|
|
567
|
+
self.pchanged()
|
|
568
|
+
self.stale = True
|
|
569
|
+
|
|
570
|
+
# -- scale (matplotlib's code + Rust mirror) ---------------------------
|
|
571
|
+
def get_transform(self):
|
|
572
|
+
"""Return the transform used in the Axis' scale"""
|
|
573
|
+
return self._scale.get_transform()
|
|
574
|
+
|
|
575
|
+
def get_scale(self):
|
|
576
|
+
"""Return this Axis' scale (as a str)."""
|
|
577
|
+
return self._scale.name
|
|
578
|
+
|
|
579
|
+
def _set_scale(self, value, **kwargs):
|
|
580
|
+
if not isinstance(value, mscale.ScaleBase):
|
|
581
|
+
self._scale = mscale.scale_factory(value, self, **kwargs)
|
|
582
|
+
else:
|
|
583
|
+
self._scale = value
|
|
584
|
+
self._rs_push_scale()
|
|
585
|
+
self._scale.set_default_locators_and_formatters(self)
|
|
586
|
+
|
|
587
|
+
self.isDefault_majloc = True
|
|
588
|
+
self.isDefault_minloc = True
|
|
589
|
+
self.isDefault_majfmt = True
|
|
590
|
+
self.isDefault_minfmt = True
|
|
591
|
+
|
|
592
|
+
def _set_axes_scale(self, value, **kwargs):
|
|
593
|
+
name = self._get_axis_name()
|
|
594
|
+
old_default_lims = (self.get_major_locator()
|
|
595
|
+
.nonsingular(-np.inf, np.inf))
|
|
596
|
+
for ax in self._get_shared_axes():
|
|
597
|
+
ax._axis_map[name]._set_scale(value, **kwargs)
|
|
598
|
+
ax._update_transScale()
|
|
599
|
+
ax.stale = True
|
|
600
|
+
new_default_lims = (self.get_major_locator()
|
|
601
|
+
.nonsingular(-np.inf, np.inf))
|
|
602
|
+
if old_default_lims != new_default_lims:
|
|
603
|
+
self.axes.autoscale_view(
|
|
604
|
+
**{f"scale{k}": k == name for k in self.axes._axis_names})
|
|
605
|
+
|
|
606
|
+
def limit_range_for_scale(self, vmin, vmax):
|
|
607
|
+
return self._scale.limit_range_for_scale(vmin, vmax, self.get_minpos())
|
|
608
|
+
|
|
609
|
+
def _nan_out_of_scale_range(self, data):
|
|
610
|
+
data = np.asanyarray(data, dtype=float)
|
|
611
|
+
valid = self._scale.val_in_range(data)
|
|
612
|
+
return data if np.all(valid) else np.where(valid, data, np.nan)
|
|
613
|
+
|
|
614
|
+
def _get_autoscale_on(self):
|
|
615
|
+
"""Return whether this Axis is autoscaled."""
|
|
616
|
+
return self._autoscale_on
|
|
617
|
+
|
|
618
|
+
def _set_autoscale_on(self, b):
|
|
619
|
+
if b is not None:
|
|
620
|
+
self._autoscale_on = b
|
|
621
|
+
|
|
622
|
+
def get_children(self):
|
|
623
|
+
return [self.label, self.offsetText,
|
|
624
|
+
*self.get_major_ticks(), *self.get_minor_ticks()]
|
|
625
|
+
|
|
626
|
+
def _reset_major_tick_kw(self):
|
|
627
|
+
self._major_tick_kw.clear()
|
|
628
|
+
self._major_tick_kw['gridOn'] = (
|
|
629
|
+
mpl.rcParams['axes.grid'] and
|
|
630
|
+
mpl.rcParams['axes.grid.which'] in ('both', 'major'))
|
|
631
|
+
|
|
632
|
+
def _reset_minor_tick_kw(self):
|
|
633
|
+
self._minor_tick_kw.clear()
|
|
634
|
+
self._minor_tick_kw['gridOn'] = (
|
|
635
|
+
mpl.rcParams['axes.grid'] and
|
|
636
|
+
mpl.rcParams['axes.grid.which'] in ('both', 'minor'))
|
|
637
|
+
|
|
638
|
+
def clear(self):
|
|
639
|
+
"""
|
|
640
|
+
Clear the axis (the Rust axis is reset with its Axes).
|
|
641
|
+
"""
|
|
642
|
+
# Rust-owned tick handles are recreated by the reset
|
|
643
|
+
label, offset = self.label, self.offsetText
|
|
644
|
+
self._text_cache = {label._h.ident(): label, offset._h.ident(): offset}
|
|
645
|
+
self._line_cache = {}
|
|
646
|
+
self._tick_cache = {}
|
|
647
|
+
label._rs_refresh()
|
|
648
|
+
offset._rs_refresh()
|
|
649
|
+
self.labelpad = mpl.rcParams['axes.labelpad']
|
|
650
|
+
self._init()
|
|
651
|
+
self._set_scale('linear')
|
|
652
|
+
self.callbacks = cbook.CallbackRegistry(signals=["units"])
|
|
653
|
+
self._major_tick_kw['gridOn'] = (
|
|
654
|
+
mpl.rcParams['axes.grid'] and
|
|
655
|
+
mpl.rcParams['axes.grid.which'] in ('both', 'major'))
|
|
656
|
+
self._minor_tick_kw['gridOn'] = (
|
|
657
|
+
mpl.rcParams['axes.grid'] and
|
|
658
|
+
mpl.rcParams['axes.grid.which'] in ('both', 'minor'))
|
|
659
|
+
self.reset_ticks()
|
|
660
|
+
self._converter = None
|
|
661
|
+
self._converter_is_explicit = False
|
|
662
|
+
self.units = None
|
|
663
|
+
self.stale = True
|
|
664
|
+
|
|
665
|
+
def reset_ticks(self):
|
|
666
|
+
self.axes._rs.reset_ticks(self.axis_name)
|
|
667
|
+
self._line_cache = {}
|
|
668
|
+
self._tick_cache = {}
|
|
669
|
+
|
|
670
|
+
def minorticks_on(self):
|
|
671
|
+
scale = self.get_scale()
|
|
672
|
+
if scale == 'log':
|
|
673
|
+
s = self._scale
|
|
674
|
+
self.set_minor_locator(mticker.LogLocator(s.base, s.subs))
|
|
675
|
+
elif scale == 'symlog':
|
|
676
|
+
s = self._scale
|
|
677
|
+
self.set_minor_locator(
|
|
678
|
+
mticker.SymmetricalLogLocator(s._transform, s.subs))
|
|
679
|
+
elif scale == 'asinh':
|
|
680
|
+
s = self._scale
|
|
681
|
+
self.set_minor_locator(
|
|
682
|
+
mticker.AsinhLocator(s.linear_width, base=s._base,
|
|
683
|
+
subs=s._subs))
|
|
684
|
+
elif scale == 'logit':
|
|
685
|
+
self.set_minor_locator(mticker.LogitLocator(minor=True))
|
|
686
|
+
else:
|
|
687
|
+
self.set_minor_locator(mticker.AutoMinorLocator())
|
|
688
|
+
|
|
689
|
+
def minorticks_off(self):
|
|
690
|
+
self.set_minor_locator(mticker.NullLocator())
|
|
691
|
+
|
|
692
|
+
# -- tick parameters -------------------------------------------------
|
|
693
|
+
def set_tick_params(self, which='major', reset=False, **kwargs):
|
|
694
|
+
_api.check_in_list(['major', 'minor', 'both'], which=which)
|
|
695
|
+
kwtrans = self._translate_tick_params(kwargs)
|
|
696
|
+
if reset:
|
|
697
|
+
if which in ['major', 'both']:
|
|
698
|
+
self._reset_major_tick_kw()
|
|
699
|
+
self._major_tick_kw.update(kwtrans)
|
|
700
|
+
if which in ['minor', 'both']:
|
|
701
|
+
self._reset_minor_tick_kw()
|
|
702
|
+
self._minor_tick_kw.update(kwtrans)
|
|
703
|
+
else:
|
|
704
|
+
if which in ['major', 'both']:
|
|
705
|
+
self._major_tick_kw.update(kwtrans)
|
|
706
|
+
if which in ['minor', 'both']:
|
|
707
|
+
self._minor_tick_kw.update(kwtrans)
|
|
708
|
+
martist._sync_dirty()
|
|
709
|
+
self.axes._rs.tick_params(self.axis_name, which, bool(reset), _rs_tick_kw(kwtrans))
|
|
710
|
+
for t in list(self._text_cache.values()):
|
|
711
|
+
t._rs_refresh()
|
|
712
|
+
for ln in list(self._line_cache.values()):
|
|
713
|
+
ln._rs_refresh()
|
|
714
|
+
self.stale = True
|
|
715
|
+
|
|
716
|
+
def get_tick_params(self, which='major'):
|
|
717
|
+
_api.check_in_list(['major', 'minor'], which=which)
|
|
718
|
+
if which == 'major':
|
|
719
|
+
return self._translate_tick_params(
|
|
720
|
+
self._major_tick_kw, reverse=True
|
|
721
|
+
)
|
|
722
|
+
return self._translate_tick_params(self._minor_tick_kw, reverse=True)
|
|
723
|
+
|
|
724
|
+
@classmethod
|
|
725
|
+
def _translate_tick_params(cls, kw, reverse=False):
|
|
726
|
+
kw_ = {**kw}
|
|
727
|
+
|
|
728
|
+
# The following lists may be moved to a more accessible location.
|
|
729
|
+
allowed_keys = [
|
|
730
|
+
'size', 'width', 'color', 'tickdir', 'pad',
|
|
731
|
+
'labelsize', 'labelcolor', 'labelfontfamily', 'zorder', 'gridOn',
|
|
732
|
+
'tick1On', 'tick2On', 'label1On', 'label2On',
|
|
733
|
+
'length', 'direction', 'left', 'bottom', 'right', 'top',
|
|
734
|
+
'labelleft', 'labelbottom', 'labelright', 'labeltop',
|
|
735
|
+
'labelrotation', 'labelrotation_mode',
|
|
736
|
+
*_gridline_param_names]
|
|
737
|
+
|
|
738
|
+
keymap = {
|
|
739
|
+
# tick_params key -> axis key
|
|
740
|
+
'length': 'size',
|
|
741
|
+
'direction': 'tickdir',
|
|
742
|
+
'rotation': 'labelrotation',
|
|
743
|
+
'rotation_mode': 'labelrotation_mode',
|
|
744
|
+
'left': 'tick1On',
|
|
745
|
+
'bottom': 'tick1On',
|
|
746
|
+
'right': 'tick2On',
|
|
747
|
+
'top': 'tick2On',
|
|
748
|
+
'labelleft': 'label1On',
|
|
749
|
+
'labelbottom': 'label1On',
|
|
750
|
+
'labelright': 'label2On',
|
|
751
|
+
'labeltop': 'label2On',
|
|
752
|
+
}
|
|
753
|
+
if reverse:
|
|
754
|
+
kwtrans = {}
|
|
755
|
+
is_x_axis = cls.axis_name == 'x'
|
|
756
|
+
y_axis_keys = ['left', 'right', 'labelleft', 'labelright']
|
|
757
|
+
for oldkey, newkey in keymap.items():
|
|
758
|
+
if newkey in kw_:
|
|
759
|
+
if is_x_axis and oldkey in y_axis_keys:
|
|
760
|
+
continue
|
|
761
|
+
else:
|
|
762
|
+
kwtrans[oldkey] = kw_.pop(newkey)
|
|
763
|
+
else:
|
|
764
|
+
kwtrans = {
|
|
765
|
+
newkey: kw_.pop(oldkey)
|
|
766
|
+
for oldkey, newkey in keymap.items() if oldkey in kw_
|
|
767
|
+
}
|
|
768
|
+
if 'colors' in kw_:
|
|
769
|
+
c = kw_.pop('colors')
|
|
770
|
+
kwtrans['color'] = c
|
|
771
|
+
kwtrans['labelcolor'] = c
|
|
772
|
+
# Maybe move the checking up to the caller of this method.
|
|
773
|
+
for key in kw_:
|
|
774
|
+
if key not in allowed_keys:
|
|
775
|
+
raise ValueError(
|
|
776
|
+
"keyword %s is not recognized; valid keywords are %s"
|
|
777
|
+
% (key, allowed_keys))
|
|
778
|
+
kwtrans.update(kw_)
|
|
779
|
+
return kwtrans
|
|
780
|
+
|
|
781
|
+
def set_clip_path(self, path, transform=None):
|
|
782
|
+
super().set_clip_path(path, transform)
|
|
783
|
+
self.stale = True
|
|
784
|
+
|
|
785
|
+
# -- intervals (Python state, mirrored to Rust at draw time) ------------
|
|
786
|
+
def get_view_interval(self):
|
|
787
|
+
"""Return the ``(min, max)`` view limits of this axis."""
|
|
788
|
+
raise NotImplementedError('Derived must override')
|
|
789
|
+
|
|
790
|
+
def set_view_interval(self, vmin, vmax, ignore=False):
|
|
791
|
+
raise NotImplementedError('Derived must override')
|
|
792
|
+
|
|
793
|
+
def get_data_interval(self):
|
|
794
|
+
"""Return the ``(min, max)`` data limits of this axis."""
|
|
795
|
+
raise NotImplementedError('Derived must override')
|
|
796
|
+
|
|
797
|
+
def set_data_interval(self, vmin, vmax, ignore=False):
|
|
798
|
+
raise NotImplementedError('Derived must override')
|
|
799
|
+
|
|
800
|
+
def get_inverted(self):
|
|
801
|
+
low, high = self.get_view_interval()
|
|
802
|
+
return high < low
|
|
803
|
+
|
|
804
|
+
def set_inverted(self, inverted):
|
|
805
|
+
a, b = self.get_view_interval()
|
|
806
|
+
# cast to bool to avoid bad interaction between python 3.8 and np.bool_
|
|
807
|
+
self._set_lim(*sorted((a, b), reverse=bool(inverted)), auto=None)
|
|
808
|
+
|
|
809
|
+
def set_default_intervals(self):
|
|
810
|
+
"""
|
|
811
|
+
Set the default limits for the axis data and view interval if they
|
|
812
|
+
have not been not mutated yet.
|
|
813
|
+
"""
|
|
814
|
+
|
|
815
|
+
def _set_lim(self, v0, v1, *, emit=True, auto):
|
|
816
|
+
name = self._get_axis_name()
|
|
817
|
+
|
|
818
|
+
self.axes._process_unit_info([(name, (v0, v1))], convert=False)
|
|
819
|
+
v0 = self.axes._validate_converted_limits(v0, self.convert_units)
|
|
820
|
+
v1 = self.axes._validate_converted_limits(v1, self.convert_units)
|
|
821
|
+
|
|
822
|
+
if v0 is None or v1 is None:
|
|
823
|
+
# Axes init calls set_xlim(0, 1) before get_xlim() can be called,
|
|
824
|
+
# so only grab the limits if we really need them.
|
|
825
|
+
old0, old1 = self.get_view_interval()
|
|
826
|
+
if v0 is None:
|
|
827
|
+
v0 = old0
|
|
828
|
+
if v1 is None:
|
|
829
|
+
v1 = old1
|
|
830
|
+
|
|
831
|
+
if self.get_scale() == 'log' and (v0 <= 0 or v1 <= 0):
|
|
832
|
+
# Axes init calls set_xlim(0, 1) before get_xlim() can be called,
|
|
833
|
+
# so only grab the limits if we really need them.
|
|
834
|
+
old0, old1 = self.get_view_interval()
|
|
835
|
+
if v0 <= 0:
|
|
836
|
+
_api.warn_external(f"Attempt to set non-positive {name}lim on "
|
|
837
|
+
f"a log-scaled axis will be ignored.")
|
|
838
|
+
v0 = old0
|
|
839
|
+
if v1 <= 0:
|
|
840
|
+
_api.warn_external(f"Attempt to set non-positive {name}lim on "
|
|
841
|
+
f"a log-scaled axis will be ignored.")
|
|
842
|
+
v1 = old1
|
|
843
|
+
if v0 == v1:
|
|
844
|
+
_api.warn_external(
|
|
845
|
+
f"Attempting to set identical low and high {name}lims "
|
|
846
|
+
f"makes transformation singular; automatically expanding.")
|
|
847
|
+
reverse = bool(v0 > v1) # explicit cast needed for python3.8+np.bool_.
|
|
848
|
+
v0, v1 = self.get_major_locator().nonsingular(v0, v1)
|
|
849
|
+
v0, v1 = self.limit_range_for_scale(v0, v1)
|
|
850
|
+
v0, v1 = sorted([v0, v1], reverse=bool(reverse))
|
|
851
|
+
|
|
852
|
+
self.set_view_interval(v0, v1, ignore=True)
|
|
853
|
+
# Mark viewlims as no longer stale without triggering an autoscale.
|
|
854
|
+
for ax in self._get_shared_axes():
|
|
855
|
+
ax._stale_viewlims[name] = False
|
|
856
|
+
self._set_autoscale_on(auto)
|
|
857
|
+
|
|
858
|
+
if emit:
|
|
859
|
+
self.axes.callbacks.process(f"{name}lim_changed", self.axes)
|
|
860
|
+
# Call all of the other Axes that are shared with this one
|
|
861
|
+
for other in self._get_shared_axes():
|
|
862
|
+
if other is self.axes:
|
|
863
|
+
continue
|
|
864
|
+
other._axis_map[name]._set_lim(v0, v1, emit=False, auto=auto)
|
|
865
|
+
if emit:
|
|
866
|
+
other.callbacks.process(f"{name}lim_changed", other)
|
|
867
|
+
if ((other_fig := other.get_figure(root=False)) !=
|
|
868
|
+
self.get_figure(root=False)):
|
|
869
|
+
other_fig.canvas.draw_idle()
|
|
870
|
+
|
|
871
|
+
self.stale = True
|
|
872
|
+
return v0, v1
|
|
873
|
+
|
|
874
|
+
def _set_artist_props(self, a):
|
|
875
|
+
if a is None:
|
|
876
|
+
return
|
|
877
|
+
a.set_figure(self.get_figure(root=False))
|
|
878
|
+
|
|
879
|
+
def _get_ticklabel_bboxes(self, ticks, renderer):
|
|
880
|
+
"""Return lists of bboxes for ticks' label1's and label2's."""
|
|
881
|
+
return ([tick.label1.get_window_extent(renderer)
|
|
882
|
+
for tick in ticks
|
|
883
|
+
if tick.label1.get_visible() and tick.label1.get_in_layout()],
|
|
884
|
+
[tick.label2.get_window_extent(renderer)
|
|
885
|
+
for tick in ticks
|
|
886
|
+
if tick.label2.get_visible() and tick.label2.get_in_layout()])
|
|
887
|
+
|
|
888
|
+
def get_tightbbox(self, renderer=None, *, for_layout_only=False):
|
|
889
|
+
"""
|
|
890
|
+
Return a bounding box that encloses the axis. It only accounts
|
|
891
|
+
tick labels, axis label, and offsetText.
|
|
892
|
+
"""
|
|
893
|
+
if not self.get_visible() or for_layout_only and not self.get_in_layout():
|
|
894
|
+
return
|
|
895
|
+
if renderer is None:
|
|
896
|
+
renderer = self.get_figure(root=True)._get_renderer()
|
|
897
|
+
ticks_to_draw = self._update_ticks()
|
|
898
|
+
|
|
899
|
+
self._update_label_position(renderer)
|
|
900
|
+
|
|
901
|
+
# go back to just this axis's tick labels
|
|
902
|
+
tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
|
|
903
|
+
|
|
904
|
+
self._update_offset_text_position(tlb1, tlb2)
|
|
905
|
+
self.offsetText.set_text(self.major.formatter.get_offset())
|
|
906
|
+
|
|
907
|
+
bboxes = [
|
|
908
|
+
*(a.get_window_extent(renderer)
|
|
909
|
+
for a in [self.offsetText]
|
|
910
|
+
if a.get_visible()),
|
|
911
|
+
*tlb1, *tlb2,
|
|
912
|
+
]
|
|
913
|
+
# take care of label
|
|
914
|
+
if self.label.get_visible():
|
|
915
|
+
bb = self.label.get_window_extent(renderer)
|
|
916
|
+
# for constrained/tight_layout, we want to ignore the label's
|
|
917
|
+
# width/height because the adjustments they make can't be improved.
|
|
918
|
+
# this code collapses the relevant direction
|
|
919
|
+
if for_layout_only:
|
|
920
|
+
if self.axis_name == "x" and bb.width > 0:
|
|
921
|
+
bb.x0 = (bb.x0 + bb.x1) / 2 - 0.5
|
|
922
|
+
bb.x1 = bb.x0 + 1.0
|
|
923
|
+
if self.axis_name == "y" and bb.height > 0:
|
|
924
|
+
bb.y0 = (bb.y0 + bb.y1) / 2 - 0.5
|
|
925
|
+
bb.y1 = bb.y0 + 1.0
|
|
926
|
+
bboxes.append(bb)
|
|
927
|
+
bboxes = [b for b in bboxes if b._is_finite()]
|
|
928
|
+
if bboxes:
|
|
929
|
+
return mtransforms.Bbox.union(bboxes)
|
|
930
|
+
else:
|
|
931
|
+
return None
|
|
932
|
+
|
|
933
|
+
def get_tick_padding(self):
|
|
934
|
+
values = []
|
|
935
|
+
if len(self.get_majorticklocs()):
|
|
936
|
+
values.append(self.get_major_ticks(1)[0].get_tick_padding())
|
|
937
|
+
if len(self.get_minorticklocs()):
|
|
938
|
+
values.append(self.get_minor_ticks(1)[0].get_tick_padding())
|
|
939
|
+
return max(values, default=0)
|
|
940
|
+
|
|
941
|
+
def draw(self, renderer):
|
|
942
|
+
# drawn by the Rust core as part of its Axes
|
|
943
|
+
self.stale = False
|
|
944
|
+
|
|
945
|
+
def get_gridlines(self):
|
|
946
|
+
"""Return this Axis' grid lines as a list of `.Line2D`\\s."""
|
|
947
|
+
self._rs_prepare()
|
|
948
|
+
return cbook.silent_list('Line2D gridline', [
|
|
949
|
+
_wrap_rs_line(self._line_cache, h, self.axes)
|
|
950
|
+
for h in self.axes._rs.get_gridlines(self.axis_name, False)])
|
|
951
|
+
|
|
952
|
+
def set_label(self, s):
|
|
953
|
+
raise RuntimeError(
|
|
954
|
+
"A legend label cannot be assigned to an Axis. Did you mean to "
|
|
955
|
+
"set the axis label via set_label_text()?")
|
|
956
|
+
|
|
957
|
+
def get_label(self):
|
|
958
|
+
"""Return the axis label as a Text instance."""
|
|
959
|
+
return self.label
|
|
960
|
+
|
|
961
|
+
def get_offset_text(self):
|
|
962
|
+
"""Return the axis offsetText as a Text instance."""
|
|
963
|
+
return self.offsetText
|
|
964
|
+
|
|
965
|
+
def get_pickradius_(self):
|
|
966
|
+
return self._pickradius
|
|
967
|
+
|
|
968
|
+
def _labels(self, which, visible_only=True):
|
|
969
|
+
self._rs_prepare()
|
|
970
|
+
return [_wrap_rs_text(self._text_cache, h, self.axes)
|
|
971
|
+
for h in self.axes._rs.get_ticklabels(self.axis_name, which, visible_only)]
|
|
972
|
+
|
|
973
|
+
def get_majorticklabels(self):
|
|
974
|
+
return self._labels("major")
|
|
975
|
+
|
|
976
|
+
def get_minorticklabels(self):
|
|
977
|
+
return self._labels("minor")
|
|
978
|
+
|
|
979
|
+
def get_ticklabels(self, minor=False, which=None):
|
|
980
|
+
if which is not None:
|
|
981
|
+
if which == 'minor':
|
|
982
|
+
return self.get_minorticklabels()
|
|
983
|
+
elif which == 'major':
|
|
984
|
+
return self.get_majorticklabels()
|
|
985
|
+
elif which == 'both':
|
|
986
|
+
return self.get_majorticklabels() + self.get_minorticklabels()
|
|
987
|
+
else:
|
|
988
|
+
_api.check_in_list(['major', 'minor', 'both'], which=which)
|
|
989
|
+
if minor:
|
|
990
|
+
return self.get_minorticklabels()
|
|
991
|
+
return self.get_majorticklabels()
|
|
992
|
+
|
|
993
|
+
def get_majorticklines(self):
|
|
994
|
+
self._rs_prepare()
|
|
995
|
+
return cbook.silent_list('Line2D ticklines', [
|
|
996
|
+
_wrap_rs_line(self._line_cache, h, self.axes)
|
|
997
|
+
for h in self.axes._rs.get_ticklines(self.axis_name, False)])
|
|
998
|
+
|
|
999
|
+
def get_minorticklines(self):
|
|
1000
|
+
self._rs_prepare()
|
|
1001
|
+
return cbook.silent_list('Line2D ticklines', [
|
|
1002
|
+
_wrap_rs_line(self._line_cache, h, self.axes)
|
|
1003
|
+
for h in self.axes._rs.get_ticklines(self.axis_name, True)])
|
|
1004
|
+
|
|
1005
|
+
def get_ticklines(self, minor=False):
|
|
1006
|
+
if minor:
|
|
1007
|
+
return self.get_minorticklines()
|
|
1008
|
+
return self.get_majorticklines()
|
|
1009
|
+
|
|
1010
|
+
def get_majorticklocs(self):
|
|
1011
|
+
"""Return this Axis' major tick locations in data coordinates."""
|
|
1012
|
+
return self.get_major_locator()()
|
|
1013
|
+
|
|
1014
|
+
def get_minorticklocs(self):
|
|
1015
|
+
"""Return this Axis' minor tick locations in data coordinates."""
|
|
1016
|
+
# Remove minor ticks duplicating major ticks.
|
|
1017
|
+
minor_locs = np.asarray(self.get_minor_locator()())
|
|
1018
|
+
if self.remove_overlapping_locs:
|
|
1019
|
+
major_locs = self.get_majorticklocs()
|
|
1020
|
+
transform = self._scale.get_transform()
|
|
1021
|
+
tr_minor_locs = transform.transform(minor_locs)
|
|
1022
|
+
tr_major_locs = transform.transform(major_locs)
|
|
1023
|
+
lo, hi = sorted(transform.transform(self.get_view_interval()))
|
|
1024
|
+
# Use the transformed view limits as scale. 1e-5 is the default
|
|
1025
|
+
# rtol for np.isclose.
|
|
1026
|
+
tol = (hi - lo) * 1e-5
|
|
1027
|
+
mask = np.isclose(tr_minor_locs[:, None], tr_major_locs[None, :],
|
|
1028
|
+
atol=tol, rtol=0).any(axis=1)
|
|
1029
|
+
minor_locs = minor_locs[~mask]
|
|
1030
|
+
return minor_locs
|
|
1031
|
+
|
|
1032
|
+
def get_ticklocs(self, *, minor=False):
|
|
1033
|
+
return self.get_minorticklocs() if minor else self.get_majorticklocs()
|
|
1034
|
+
|
|
1035
|
+
def get_ticks_direction(self, minor=False):
|
|
1036
|
+
kw = self._minor_tick_kw if minor else self._major_tick_kw
|
|
1037
|
+
d = kw.get("tickdir", mpl.rcParams[f"{self.axis_name}tick.direction"])
|
|
1038
|
+
n = len(self.get_ticklocs(minor=minor))
|
|
1039
|
+
return np.array([d] * n)
|
|
1040
|
+
|
|
1041
|
+
def _make_ticks(self, major, n):
|
|
1042
|
+
self._rs_prepare()
|
|
1043
|
+
rs = self.axes._rs
|
|
1044
|
+
# reuse the tick views while the Rust ticks are unchanged
|
|
1045
|
+
# (at least *n* ticks, as matplotlib creates them on request)
|
|
1046
|
+
sig = rs.ticks_signature(self.axis_name, major, n)
|
|
1047
|
+
made = self.__dict__.setdefault("_rs_made_ticks", {})
|
|
1048
|
+
prev = made.get(major)
|
|
1049
|
+
if prev is not None and prev[0] == sig:
|
|
1050
|
+
ticks = prev[1]
|
|
1051
|
+
return ticks[:n] if n is not None else ticks
|
|
1052
|
+
ticks = self._make_ticks_from_rs(major, n)
|
|
1053
|
+
made[major] = (sig, ticks)
|
|
1054
|
+
return ticks[:n] if n is not None else ticks
|
|
1055
|
+
|
|
1056
|
+
def _make_ticks_from_rs(self, major, n=None):
|
|
1057
|
+
which = "major" if major else "minor"
|
|
1058
|
+
rs = self.axes._rs
|
|
1059
|
+
labels = [_wrap_rs_text(self._text_cache, h, self.axes)
|
|
1060
|
+
for h in rs.get_ticklabels(self.axis_name, which, False, n)]
|
|
1061
|
+
lines = rs.get_ticklines(self.axis_name, not major, n)
|
|
1062
|
+
grids = rs.get_gridlines(self.axis_name, not major, n)
|
|
1063
|
+
nt = len(grids)
|
|
1064
|
+
cls = self._tick_class or Tick
|
|
1065
|
+
cache = self.__dict__.setdefault("_tick_cache", {})
|
|
1066
|
+
ticks = []
|
|
1067
|
+
for i in range(nt):
|
|
1068
|
+
key = (major, labels[i]._h.ident())
|
|
1069
|
+
t = cache.get(key)
|
|
1070
|
+
handles = (lines[2 * i], lines[2 * i + 1], grids[i])
|
|
1071
|
+
if (t is None or t.label1 is not labels[i]
|
|
1072
|
+
or t._rs_line_handles[2].ident() != grids[i].ident()):
|
|
1073
|
+
t = cls(self, i, major, handles, labels[i], labels[nt + i])
|
|
1074
|
+
else:
|
|
1075
|
+
t._rs_line_handles = handles
|
|
1076
|
+
cache[key] = t
|
|
1077
|
+
t._idx = i
|
|
1078
|
+
ticks.append(t)
|
|
1079
|
+
return ticks
|
|
1080
|
+
|
|
1081
|
+
def _update_ticks(self):
|
|
1082
|
+
"""
|
|
1083
|
+
Update the ticks (position and labels) using the current data
|
|
1084
|
+
interval of the axes. Return the list of ticks that will be drawn.
|
|
1085
|
+
"""
|
|
1086
|
+
# The tick labels themselves are formatted by the Rust core; the
|
|
1087
|
+
# formatters are run for their state (e.g. the offset).
|
|
1088
|
+
major_locs = self.get_majorticklocs()
|
|
1089
|
+
self.major.formatter.format_ticks(major_locs)
|
|
1090
|
+
major_ticks = self.get_major_ticks(len(major_locs))
|
|
1091
|
+
for tick, loc in zip(major_ticks, major_locs):
|
|
1092
|
+
tick.update_position(loc)
|
|
1093
|
+
minor_locs = self.get_minorticklocs()
|
|
1094
|
+
self.minor.formatter.format_ticks(minor_locs)
|
|
1095
|
+
minor_ticks = self.get_minor_ticks(len(minor_locs))
|
|
1096
|
+
for tick, loc in zip(minor_ticks, minor_locs):
|
|
1097
|
+
tick.update_position(loc)
|
|
1098
|
+
ticks = [*major_ticks, *minor_ticks]
|
|
1099
|
+
|
|
1100
|
+
view_low, view_high = self.get_view_interval()
|
|
1101
|
+
if view_low > view_high:
|
|
1102
|
+
view_low, view_high = view_high, view_low
|
|
1103
|
+
|
|
1104
|
+
interval_t = self.get_transform().transform([view_low, view_high])
|
|
1105
|
+
|
|
1106
|
+
ticks_to_draw = []
|
|
1107
|
+
for tick in ticks:
|
|
1108
|
+
try:
|
|
1109
|
+
loc_t = self.get_transform().transform(tick.get_loc())
|
|
1110
|
+
except AssertionError:
|
|
1111
|
+
# Transform.transform doesn't allow masked values but
|
|
1112
|
+
# some scales might make them, so we need this try/except.
|
|
1113
|
+
pass
|
|
1114
|
+
else:
|
|
1115
|
+
if mtransforms._interval_contains_close(interval_t, loc_t):
|
|
1116
|
+
ticks_to_draw.append(tick)
|
|
1117
|
+
|
|
1118
|
+
return ticks_to_draw
|
|
1119
|
+
|
|
1120
|
+
@property
|
|
1121
|
+
def majorTicks(self):
|
|
1122
|
+
return self._make_ticks(True, None)
|
|
1123
|
+
|
|
1124
|
+
@property
|
|
1125
|
+
def minorTicks(self):
|
|
1126
|
+
return self._make_ticks(False, None)
|
|
1127
|
+
|
|
1128
|
+
def get_major_ticks(self, numticks=None):
|
|
1129
|
+
return self._make_ticks(True, numticks)
|
|
1130
|
+
|
|
1131
|
+
def get_minor_ticks(self, numticks=None):
|
|
1132
|
+
return self._make_ticks(False, numticks)
|
|
1133
|
+
|
|
1134
|
+
def grid(self, visible=None, which='major', **kwargs):
|
|
1135
|
+
if kwargs:
|
|
1136
|
+
if visible is None:
|
|
1137
|
+
visible = True
|
|
1138
|
+
elif not visible: # something false-like but not None
|
|
1139
|
+
_api.warn_external('First parameter to grid() is false, '
|
|
1140
|
+
'but line properties are supplied. The '
|
|
1141
|
+
'grid will be enabled.')
|
|
1142
|
+
visible = True
|
|
1143
|
+
which = which.lower()
|
|
1144
|
+
_api.check_in_list(['major', 'minor', 'both'], which=which)
|
|
1145
|
+
gridkw = {f'grid_{name}': value for name, value in kwargs.items()}
|
|
1146
|
+
if which in ['minor', 'both']:
|
|
1147
|
+
gridkw['gridOn'] = (not self._minor_tick_kw['gridOn']
|
|
1148
|
+
if visible is None else visible)
|
|
1149
|
+
self.set_tick_params(which='minor', **gridkw)
|
|
1150
|
+
if which in ['major', 'both']:
|
|
1151
|
+
gridkw['gridOn'] = (not self._major_tick_kw['gridOn']
|
|
1152
|
+
if visible is None else visible)
|
|
1153
|
+
self.set_tick_params(which='major', **gridkw)
|
|
1154
|
+
self.stale = True
|
|
1155
|
+
|
|
1156
|
+
# -- units (matplotlib's code) -------------------------------------------
|
|
1157
|
+
def update_units(self, data):
|
|
1158
|
+
if not self._converter_is_explicit:
|
|
1159
|
+
converter = munits.registry.get_converter(data)
|
|
1160
|
+
else:
|
|
1161
|
+
converter = self._converter
|
|
1162
|
+
|
|
1163
|
+
if converter is None:
|
|
1164
|
+
return False
|
|
1165
|
+
|
|
1166
|
+
neednew = self._converter != converter
|
|
1167
|
+
self._set_converter(converter)
|
|
1168
|
+
default = self._converter.default_units(data, self)
|
|
1169
|
+
if default is not None and self.units is None:
|
|
1170
|
+
self.set_units(default)
|
|
1171
|
+
|
|
1172
|
+
elif neednew:
|
|
1173
|
+
self._update_axisinfo()
|
|
1174
|
+
self.stale = True
|
|
1175
|
+
return True
|
|
1176
|
+
|
|
1177
|
+
def _update_axisinfo(self):
|
|
1178
|
+
if self._converter is None:
|
|
1179
|
+
return
|
|
1180
|
+
|
|
1181
|
+
info = self._converter.axisinfo(self.units, self)
|
|
1182
|
+
|
|
1183
|
+
if info is None:
|
|
1184
|
+
return
|
|
1185
|
+
if info.majloc is not None and \
|
|
1186
|
+
self.major.locator != info.majloc and self.isDefault_majloc:
|
|
1187
|
+
self.set_major_locator(info.majloc)
|
|
1188
|
+
self.isDefault_majloc = True
|
|
1189
|
+
if info.minloc is not None and \
|
|
1190
|
+
self.minor.locator != info.minloc and self.isDefault_minloc:
|
|
1191
|
+
self.set_minor_locator(info.minloc)
|
|
1192
|
+
self.isDefault_minloc = True
|
|
1193
|
+
if info.majfmt is not None and \
|
|
1194
|
+
self.major.formatter != info.majfmt and self.isDefault_majfmt:
|
|
1195
|
+
self.set_major_formatter(info.majfmt)
|
|
1196
|
+
self.isDefault_majfmt = True
|
|
1197
|
+
if info.minfmt is not None and \
|
|
1198
|
+
self.minor.formatter != info.minfmt and self.isDefault_minfmt:
|
|
1199
|
+
self.set_minor_formatter(info.minfmt)
|
|
1200
|
+
self.isDefault_minfmt = True
|
|
1201
|
+
if info.label is not None and self.isDefault_label:
|
|
1202
|
+
self.set_label_text(info.label)
|
|
1203
|
+
self.isDefault_label = True
|
|
1204
|
+
|
|
1205
|
+
self.set_default_intervals()
|
|
1206
|
+
|
|
1207
|
+
def have_units(self):
|
|
1208
|
+
return self._converter is not None or self.units is not None
|
|
1209
|
+
|
|
1210
|
+
def convert_units(self, x):
|
|
1211
|
+
# If x is natively supported by Matplotlib, doesn't need converting
|
|
1212
|
+
if munits._is_natively_supported(x):
|
|
1213
|
+
return x
|
|
1214
|
+
|
|
1215
|
+
if self._converter is None:
|
|
1216
|
+
self._set_converter(munits.registry.get_converter(x))
|
|
1217
|
+
|
|
1218
|
+
if self._converter is None:
|
|
1219
|
+
return x
|
|
1220
|
+
try:
|
|
1221
|
+
ret = self._converter.convert(x, self.units, self)
|
|
1222
|
+
except Exception as e:
|
|
1223
|
+
raise munits.ConversionError('Failed to convert value(s) to axis '
|
|
1224
|
+
f'units: {x!r}') from e
|
|
1225
|
+
return ret
|
|
1226
|
+
|
|
1227
|
+
def get_converter(self):
|
|
1228
|
+
return self._converter
|
|
1229
|
+
|
|
1230
|
+
def set_converter(self, converter):
|
|
1231
|
+
self._set_converter(converter)
|
|
1232
|
+
self._converter_is_explicit = True
|
|
1233
|
+
|
|
1234
|
+
def _set_converter(self, converter):
|
|
1235
|
+
if self._converter is converter or self._converter == converter:
|
|
1236
|
+
return
|
|
1237
|
+
if self._converter_is_explicit:
|
|
1238
|
+
raise RuntimeError("Axis already has an explicit converter set")
|
|
1239
|
+
elif (
|
|
1240
|
+
self._converter is not None and
|
|
1241
|
+
not isinstance(converter, type(self._converter)) and
|
|
1242
|
+
not isinstance(self._converter, type(converter))
|
|
1243
|
+
):
|
|
1244
|
+
_api.warn_external(
|
|
1245
|
+
"This axis already has a converter set and "
|
|
1246
|
+
"is updating to a potentially incompatible converter"
|
|
1247
|
+
)
|
|
1248
|
+
self._converter = converter
|
|
1249
|
+
|
|
1250
|
+
def set_units(self, u):
|
|
1251
|
+
if u == self.units:
|
|
1252
|
+
return
|
|
1253
|
+
for axis in self._get_shared_axis():
|
|
1254
|
+
axis.units = u
|
|
1255
|
+
axis._update_axisinfo()
|
|
1256
|
+
axis.callbacks.process('units')
|
|
1257
|
+
axis.stale = True
|
|
1258
|
+
|
|
1259
|
+
def get_units(self):
|
|
1260
|
+
return self.units
|
|
1261
|
+
|
|
1262
|
+
# -- labels ----------------------------------------------------------
|
|
1263
|
+
def set_label_text(self, label, fontdict=None, **kwargs):
|
|
1264
|
+
self.isDefault_label = False
|
|
1265
|
+
self.label.set_text(label)
|
|
1266
|
+
if fontdict is not None:
|
|
1267
|
+
self.label.update(fontdict)
|
|
1268
|
+
self.label.update(kwargs)
|
|
1269
|
+
self.stale = True
|
|
1270
|
+
return self.label
|
|
1271
|
+
|
|
1272
|
+
def get_label_text(self):
|
|
1273
|
+
return self.label.get_text()
|
|
1274
|
+
|
|
1275
|
+
def get_label_position(self):
|
|
1276
|
+
return self.label_position
|
|
1277
|
+
|
|
1278
|
+
def set_label_position(self, position):
|
|
1279
|
+
raise NotImplementedError()
|
|
1280
|
+
|
|
1281
|
+
# -- locators / formatters --------------------------------------------
|
|
1282
|
+
def get_major_locator(self):
|
|
1283
|
+
return self.major.locator
|
|
1284
|
+
|
|
1285
|
+
def get_minor_locator(self):
|
|
1286
|
+
return self.minor.locator
|
|
1287
|
+
|
|
1288
|
+
def get_major_formatter(self):
|
|
1289
|
+
return self.major.formatter
|
|
1290
|
+
|
|
1291
|
+
def get_minor_formatter(self):
|
|
1292
|
+
return self.minor.formatter
|
|
1293
|
+
|
|
1294
|
+
def set_major_formatter(self, formatter):
|
|
1295
|
+
self._set_formatter(formatter, self.major)
|
|
1296
|
+
|
|
1297
|
+
def set_minor_formatter(self, formatter):
|
|
1298
|
+
self._set_formatter(formatter, self.minor)
|
|
1299
|
+
|
|
1300
|
+
def _set_formatter(self, formatter, level):
|
|
1301
|
+
if isinstance(formatter, str):
|
|
1302
|
+
formatter = mticker.StrMethodFormatter(formatter)
|
|
1303
|
+
# Don't allow any other TickHelper to avoid easy-to-make errors,
|
|
1304
|
+
# like using a Locator instead of a Formatter.
|
|
1305
|
+
elif (callable(formatter) and
|
|
1306
|
+
not isinstance(formatter, mticker.TickHelper)):
|
|
1307
|
+
formatter = mticker.FuncFormatter(formatter)
|
|
1308
|
+
else:
|
|
1309
|
+
_api.check_isinstance(mticker.Formatter, formatter=formatter)
|
|
1310
|
+
|
|
1311
|
+
if (isinstance(formatter, mticker.FixedFormatter)
|
|
1312
|
+
and len(formatter.seq) > 0
|
|
1313
|
+
and not isinstance(level.locator, mticker.FixedLocator)):
|
|
1314
|
+
_api.warn_external('FixedFormatter should only be used together '
|
|
1315
|
+
'with FixedLocator')
|
|
1316
|
+
|
|
1317
|
+
if level == self.major:
|
|
1318
|
+
self.isDefault_majfmt = False
|
|
1319
|
+
else:
|
|
1320
|
+
self.isDefault_minfmt = False
|
|
1321
|
+
|
|
1322
|
+
level.formatter = formatter
|
|
1323
|
+
formatter.set_axis(self)
|
|
1324
|
+
self.stale = True
|
|
1325
|
+
|
|
1326
|
+
def set_major_locator(self, locator):
|
|
1327
|
+
_api.check_isinstance(mticker.Locator, locator=locator)
|
|
1328
|
+
self.isDefault_majloc = False
|
|
1329
|
+
self.major.locator = locator
|
|
1330
|
+
if self.major.formatter:
|
|
1331
|
+
self.major.formatter._set_locator(locator)
|
|
1332
|
+
locator.set_axis(self)
|
|
1333
|
+
self.stale = True
|
|
1334
|
+
|
|
1335
|
+
def set_minor_locator(self, locator):
|
|
1336
|
+
_api.check_isinstance(mticker.Locator, locator=locator)
|
|
1337
|
+
self.isDefault_minloc = False
|
|
1338
|
+
self.minor.locator = locator
|
|
1339
|
+
if self.minor.formatter:
|
|
1340
|
+
self.minor.formatter._set_locator(locator)
|
|
1341
|
+
locator.set_axis(self)
|
|
1342
|
+
self.stale = True
|
|
1343
|
+
|
|
1344
|
+
@staticmethod
|
|
1345
|
+
def _format_with_dict(tickd, x, pos):
|
|
1346
|
+
return tickd.get(x, "")
|
|
1347
|
+
|
|
1348
|
+
def set_ticklabels(self, labels, *, minor=False, fontdict=None, **kwargs):
|
|
1349
|
+
try:
|
|
1350
|
+
labels = [t.get_text() if hasattr(t, 'get_text') else t
|
|
1351
|
+
for t in labels]
|
|
1352
|
+
except TypeError:
|
|
1353
|
+
raise TypeError(f"{labels:=} must be a sequence") from None
|
|
1354
|
+
locator = (self.get_minor_locator() if minor
|
|
1355
|
+
else self.get_major_locator())
|
|
1356
|
+
if not labels:
|
|
1357
|
+
# eg labels=[]:
|
|
1358
|
+
formatter = mticker.NullFormatter()
|
|
1359
|
+
elif isinstance(locator, mticker.FixedLocator):
|
|
1360
|
+
# Passing [] as a list of labels is often used as a way to
|
|
1361
|
+
# remove all tick labels, so only error for > 0 labels
|
|
1362
|
+
if len(locator.locs) != len(labels) and len(labels) != 0:
|
|
1363
|
+
raise ValueError(
|
|
1364
|
+
"The number of FixedLocator locations"
|
|
1365
|
+
f" ({len(locator.locs)}), usually from a call to"
|
|
1366
|
+
" set_ticks, does not match"
|
|
1367
|
+
f" the number of labels ({len(labels)}).")
|
|
1368
|
+
tickd = {loc: lab for loc, lab in zip(locator.locs, labels)}
|
|
1369
|
+
func = functools.partial(self._format_with_dict, tickd)
|
|
1370
|
+
formatter = mticker.FuncFormatter(func)
|
|
1371
|
+
else:
|
|
1372
|
+
_api.warn_external(
|
|
1373
|
+
"set_ticklabels() should only be used with a fixed number of "
|
|
1374
|
+
"ticks, i.e. after set_ticks() or using a FixedLocator. "
|
|
1375
|
+
"Otherwise, ticks may be mislabeled.")
|
|
1376
|
+
formatter = mticker.FixedFormatter(labels)
|
|
1377
|
+
|
|
1378
|
+
with warnings.catch_warnings():
|
|
1379
|
+
warnings.filterwarnings(
|
|
1380
|
+
"ignore",
|
|
1381
|
+
message="FixedFormatter should only be used together with "
|
|
1382
|
+
"FixedLocator")
|
|
1383
|
+
if minor:
|
|
1384
|
+
self.set_minor_formatter(formatter)
|
|
1385
|
+
else:
|
|
1386
|
+
self.set_major_formatter(formatter)
|
|
1387
|
+
|
|
1388
|
+
# Note: The tick labels are updated by the Rust core at draw time;
|
|
1389
|
+
# setting their text here returns the labels as matplotlib does.
|
|
1390
|
+
if minor:
|
|
1391
|
+
locs = self.get_minorticklocs()
|
|
1392
|
+
ticks = self.get_minor_ticks(len(locs))
|
|
1393
|
+
else:
|
|
1394
|
+
locs = self.get_majorticklocs()
|
|
1395
|
+
ticks = self.get_major_ticks(len(locs))
|
|
1396
|
+
|
|
1397
|
+
ret = []
|
|
1398
|
+
if fontdict is not None:
|
|
1399
|
+
kwargs.update(fontdict)
|
|
1400
|
+
if len(kwargs) or len(labels):
|
|
1401
|
+
for pos, (loc, tick) in enumerate(zip(locs, ticks)):
|
|
1402
|
+
tick.update_position(loc)
|
|
1403
|
+
tick_label = formatter(loc, pos)
|
|
1404
|
+
# deal with label1
|
|
1405
|
+
tick.label1.set_text(tick_label)
|
|
1406
|
+
tick.label1._internal_update(kwargs)
|
|
1407
|
+
# deal with label2
|
|
1408
|
+
tick.label2.set_text(tick_label)
|
|
1409
|
+
tick.label2._internal_update(kwargs)
|
|
1410
|
+
# only return visible tick labels
|
|
1411
|
+
if tick.label1.get_visible():
|
|
1412
|
+
ret.append(tick.label1)
|
|
1413
|
+
if tick.label2.get_visible():
|
|
1414
|
+
ret.append(tick.label2)
|
|
1415
|
+
|
|
1416
|
+
self.stale = True
|
|
1417
|
+
return ret
|
|
1418
|
+
|
|
1419
|
+
def _set_tick_locations(self, ticks, *, minor=False):
|
|
1420
|
+
# XXX if the user changes units, the information will be lost here
|
|
1421
|
+
ticks = self.convert_units(ticks)
|
|
1422
|
+
locator = mticker.FixedLocator(ticks) # validate ticks early.
|
|
1423
|
+
if len(ticks):
|
|
1424
|
+
for axis in self._get_shared_axis():
|
|
1425
|
+
# set_view_interval maintains any preexisting inversion.
|
|
1426
|
+
axis.set_view_interval(min(ticks), max(ticks))
|
|
1427
|
+
self.axes.stale = True
|
|
1428
|
+
if minor:
|
|
1429
|
+
self.set_minor_locator(locator)
|
|
1430
|
+
return self.get_minor_ticks(len(ticks))
|
|
1431
|
+
else:
|
|
1432
|
+
self.set_major_locator(locator)
|
|
1433
|
+
return self.get_major_ticks(len(ticks))
|
|
1434
|
+
|
|
1435
|
+
def set_ticks(self, ticks, labels=None, *, minor=False, **kwargs):
|
|
1436
|
+
if labels is None and kwargs:
|
|
1437
|
+
first_key = next(iter(kwargs))
|
|
1438
|
+
raise ValueError(
|
|
1439
|
+
f"Incorrect use of keyword argument {first_key!r}. Keyword arguments "
|
|
1440
|
+
"other than 'minor' modify the text labels and can only be used if "
|
|
1441
|
+
"'labels' are passed as well.")
|
|
1442
|
+
result = self._set_tick_locations(ticks, minor=minor)
|
|
1443
|
+
if labels is not None:
|
|
1444
|
+
self.set_ticklabels(labels, minor=minor, **kwargs)
|
|
1445
|
+
return result
|
|
1446
|
+
|
|
1447
|
+
def _get_tick_boxes_siblings(self, renderer):
|
|
1448
|
+
name = self._get_axis_name()
|
|
1449
|
+
if name not in self.get_figure(root=False)._align_label_groups:
|
|
1450
|
+
return [], []
|
|
1451
|
+
grouper = self.get_figure(root=False)._align_label_groups[name]
|
|
1452
|
+
bboxes = []
|
|
1453
|
+
bboxes2 = []
|
|
1454
|
+
for ax in grouper.get_siblings(self.axes):
|
|
1455
|
+
axis = ax._axis_map[name]
|
|
1456
|
+
ticks_to_draw = axis._update_ticks()
|
|
1457
|
+
tlb, tlb2 = axis._get_ticklabel_bboxes(ticks_to_draw, renderer)
|
|
1458
|
+
bboxes.extend(tlb)
|
|
1459
|
+
bboxes2.extend(tlb2)
|
|
1460
|
+
return bboxes, bboxes2
|
|
1461
|
+
|
|
1462
|
+
def axis_date(self, tz=None):
|
|
1463
|
+
if isinstance(tz, str):
|
|
1464
|
+
from matplotlib_rs._vendor.dateutil import tz as dateutil_tz
|
|
1465
|
+
tz = dateutil_tz.gettz(tz)
|
|
1466
|
+
self.update_units(datetime.datetime(2009, 1, 1, 0, 0, 0, 0, tz))
|
|
1467
|
+
|
|
1468
|
+
def get_tick_space(self):
|
|
1469
|
+
"""Return the estimated number of ticks that can fit on the axis."""
|
|
1470
|
+
# Must be overridden in the subclass
|
|
1471
|
+
raise NotImplementedError()
|
|
1472
|
+
|
|
1473
|
+
def _get_ticks_position(self):
|
|
1474
|
+
representative_ticks = []
|
|
1475
|
+
if not isinstance(self.get_major_locator(), NullLocator):
|
|
1476
|
+
representative_ticks.append(self.get_major_ticks(1)[0])
|
|
1477
|
+
if not isinstance(self.get_minor_locator(), NullLocator):
|
|
1478
|
+
mt = self.get_minor_ticks(1)
|
|
1479
|
+
if mt:
|
|
1480
|
+
representative_ticks.append(mt[0])
|
|
1481
|
+
|
|
1482
|
+
if all(tick.tick1line.get_visible()
|
|
1483
|
+
and not tick.tick2line.get_visible()
|
|
1484
|
+
and tick.label1.get_visible()
|
|
1485
|
+
and not tick.label2.get_visible()
|
|
1486
|
+
for tick in representative_ticks):
|
|
1487
|
+
return 1
|
|
1488
|
+
elif all(tick.tick2line.get_visible()
|
|
1489
|
+
and not tick.tick1line.get_visible()
|
|
1490
|
+
and tick.label2.get_visible()
|
|
1491
|
+
and not tick.label1.get_visible()
|
|
1492
|
+
for tick in representative_ticks):
|
|
1493
|
+
return 2
|
|
1494
|
+
elif all(tick.tick1line.get_visible()
|
|
1495
|
+
and tick.tick2line.get_visible()
|
|
1496
|
+
and tick.label1.get_visible()
|
|
1497
|
+
and not tick.label2.get_visible()
|
|
1498
|
+
for tick in representative_ticks):
|
|
1499
|
+
return "default"
|
|
1500
|
+
else:
|
|
1501
|
+
return "unknown"
|
|
1502
|
+
|
|
1503
|
+
def _get_tick_label_size(self, axis_name):
|
|
1504
|
+
tick_kw = self._major_tick_kw
|
|
1505
|
+
size = tick_kw.get('labelsize',
|
|
1506
|
+
mpl.rcParams[f'{axis_name}tick.labelsize'])
|
|
1507
|
+
return mtext.FontProperties(size=size).get_size_in_points()
|
|
1508
|
+
|
|
1509
|
+
def get_minpos(self):
|
|
1510
|
+
raise NotImplementedError()
|
|
1511
|
+
|
|
1512
|
+
def contains(self, mouseevent):
|
|
1513
|
+
return False, {}
|
|
1514
|
+
|
|
1515
|
+
|
|
1516
|
+
def _make_getset_interval(method_name, lim_name, attr_name):
|
|
1517
|
+
"""
|
|
1518
|
+
Helper to generate ``get_{data,view}_interval`` and
|
|
1519
|
+
``set_{data,view}_interval`` implementations.
|
|
1520
|
+
"""
|
|
1521
|
+
|
|
1522
|
+
def getter(self):
|
|
1523
|
+
# docstring inherited.
|
|
1524
|
+
return getattr(getattr(self.axes, lim_name), attr_name)
|
|
1525
|
+
|
|
1526
|
+
def setter(self, vmin, vmax, ignore=False):
|
|
1527
|
+
# docstring inherited.
|
|
1528
|
+
if ignore:
|
|
1529
|
+
setattr(getattr(self.axes, lim_name), attr_name, (vmin, vmax))
|
|
1530
|
+
else:
|
|
1531
|
+
oldmin, oldmax = getter(self)
|
|
1532
|
+
if oldmin < oldmax:
|
|
1533
|
+
setter(self, min(vmin, vmax, oldmin), max(vmin, vmax, oldmax),
|
|
1534
|
+
ignore=True)
|
|
1535
|
+
else:
|
|
1536
|
+
setter(self, max(vmin, vmax, oldmin), min(vmin, vmax, oldmax),
|
|
1537
|
+
ignore=True)
|
|
1538
|
+
self.stale = True
|
|
1539
|
+
|
|
1540
|
+
getter.__name__ = f"get_{method_name}_interval"
|
|
1541
|
+
setter.__name__ = f"set_{method_name}_interval"
|
|
1542
|
+
|
|
1543
|
+
return getter, setter
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
def _rs_tick_kw(kw):
|
|
1547
|
+
"""Resolve tick parameters to the values the Rust core expects."""
|
|
1548
|
+
out = {}
|
|
1549
|
+
for k, v in kw.items():
|
|
1550
|
+
if k in ("color", "labelcolor", "grid_color", "grid_c"):
|
|
1551
|
+
key = "grid_color" if k.startswith("grid") else k
|
|
1552
|
+
if isinstance(v, str) and v.lower() == "inherit":
|
|
1553
|
+
continue
|
|
1554
|
+
out[key] = mcolors.to_rgba(v)
|
|
1555
|
+
elif k in ("size", "width", "pad", "zorder", "grid_linewidth", "grid_lw",
|
|
1556
|
+
"grid_zorder"):
|
|
1557
|
+
key = {"grid_lw": "grid_linewidth"}.get(k, k)
|
|
1558
|
+
out[key] = float(v)
|
|
1559
|
+
elif k == "labelsize":
|
|
1560
|
+
out[k] = float(mtext.FontProperties(size=v).get_size_in_points())
|
|
1561
|
+
elif k in ("gridOn", "tick1On", "tick2On", "label1On", "label2On", "grid_visible",
|
|
1562
|
+
"grid_antialiased", "grid_aa"):
|
|
1563
|
+
key = {"grid_aa": "grid_antialiased"}.get(k, k)
|
|
1564
|
+
out[key] = bool(v)
|
|
1565
|
+
elif k == "grid_alpha":
|
|
1566
|
+
out[k] = None if v is None else float(v)
|
|
1567
|
+
elif k in ("grid_linestyle", "grid_ls"):
|
|
1568
|
+
ls = v
|
|
1569
|
+
if isinstance(ls, str):
|
|
1570
|
+
if ls in (" ", "", "none"):
|
|
1571
|
+
ls = "None"
|
|
1572
|
+
out["grid_linestyle"] = ls
|
|
1573
|
+
else:
|
|
1574
|
+
from .lines import _get_dash_pattern
|
|
1575
|
+
out["grid_linestyle"] = _get_dash_pattern(ls)
|
|
1576
|
+
elif k == "tickdir":
|
|
1577
|
+
out[k] = str(v)
|
|
1578
|
+
elif k == "labelrotation":
|
|
1579
|
+
out[k] = v if not isinstance(v, str) else (v, 0.0)
|
|
1580
|
+
elif k in ("labelrotation_mode", "labelfontfamily"):
|
|
1581
|
+
out[k] = v
|
|
1582
|
+
return out
|
|
1583
|
+
|
|
1584
|
+
|
|
1585
|
+
class XAxis(Axis):
|
|
1586
|
+
__name__ = 'xaxis'
|
|
1587
|
+
axis_name = 'x' #: Read-only name identifying the axis.
|
|
1588
|
+
_tick_class = XTick
|
|
1589
|
+
|
|
1590
|
+
def __init__(self, *args, **kwargs):
|
|
1591
|
+
super().__init__(*args, **kwargs)
|
|
1592
|
+
self._init()
|
|
1593
|
+
|
|
1594
|
+
def _init(self):
|
|
1595
|
+
# x in axes coords, y in display coords (updated at draw time by the
|
|
1596
|
+
# Rust core).
|
|
1597
|
+
self.label.set(
|
|
1598
|
+
x=0.5, y=0,
|
|
1599
|
+
verticalalignment='top', horizontalalignment='center',
|
|
1600
|
+
transform=mtransforms.blended_transform_factory(
|
|
1601
|
+
self.axes.transAxes, mtransforms.IdentityTransform()),
|
|
1602
|
+
)
|
|
1603
|
+
self.label_position = 'bottom'
|
|
1604
|
+
|
|
1605
|
+
if mpl.rcParams['xtick.labelcolor'] == 'inherit':
|
|
1606
|
+
tick_color = mpl.rcParams['xtick.color']
|
|
1607
|
+
else:
|
|
1608
|
+
tick_color = mpl.rcParams['xtick.labelcolor']
|
|
1609
|
+
|
|
1610
|
+
self.offsetText.set(
|
|
1611
|
+
x=1, y=0,
|
|
1612
|
+
verticalalignment='top', horizontalalignment='right',
|
|
1613
|
+
transform=mtransforms.blended_transform_factory(
|
|
1614
|
+
self.axes.transAxes, mtransforms.IdentityTransform()),
|
|
1615
|
+
fontsize=mpl.rcParams['xtick.labelsize'],
|
|
1616
|
+
color=tick_color
|
|
1617
|
+
)
|
|
1618
|
+
self.offset_text_position = 'bottom'
|
|
1619
|
+
|
|
1620
|
+
def contains(self, mouseevent):
|
|
1621
|
+
"""Test whether the mouse event occurred in the x-axis."""
|
|
1622
|
+
if self._different_canvas(mouseevent):
|
|
1623
|
+
return False, {}
|
|
1624
|
+
x, y = mouseevent.x, mouseevent.y
|
|
1625
|
+
try:
|
|
1626
|
+
trans = self.axes.transAxes.inverted()
|
|
1627
|
+
xaxes, yaxes = trans.transform((x, y))
|
|
1628
|
+
except ValueError:
|
|
1629
|
+
return False, {}
|
|
1630
|
+
(l, b), (r, t) = self.axes.transAxes.transform([(0, 0), (1, 1)])
|
|
1631
|
+
inaxis = 0 <= xaxes <= 1 and (
|
|
1632
|
+
b - self._pickradius < y < b or
|
|
1633
|
+
t < y < t + self._pickradius)
|
|
1634
|
+
return inaxis, {}
|
|
1635
|
+
|
|
1636
|
+
def set_label_position(self, position):
|
|
1637
|
+
self.label.set_verticalalignment(_api.getitem_checked({
|
|
1638
|
+
'top': 'baseline', 'bottom': 'top',
|
|
1639
|
+
}, position=position))
|
|
1640
|
+
self.label_position = position
|
|
1641
|
+
self.stale = True
|
|
1642
|
+
|
|
1643
|
+
def _update_label_position(self, renderer):
|
|
1644
|
+
"""
|
|
1645
|
+
Update the label position based on the bounding box enclosing
|
|
1646
|
+
all the ticklabels and axis spine
|
|
1647
|
+
"""
|
|
1648
|
+
if not self._autolabelpos:
|
|
1649
|
+
return
|
|
1650
|
+
|
|
1651
|
+
# get bounding boxes for this axis and any siblings
|
|
1652
|
+
# that have been set by `fig.align_xlabels()`
|
|
1653
|
+
bboxes, bboxes2 = self._get_tick_boxes_siblings(renderer=renderer)
|
|
1654
|
+
x, y = self.label.get_position()
|
|
1655
|
+
|
|
1656
|
+
if self.label_position == 'bottom':
|
|
1657
|
+
# Union with extents of the bottom spine if present, of the axes otherwise.
|
|
1658
|
+
bbox = mtransforms.Bbox.union([
|
|
1659
|
+
*bboxes, self.axes.spines.get("bottom", self.axes).get_window_extent()])
|
|
1660
|
+
self.label.set_position(
|
|
1661
|
+
(x, bbox.y0 - self.labelpad * self.get_figure(root=True).dpi / 72))
|
|
1662
|
+
else:
|
|
1663
|
+
# Union with extents of the top spine if present, of the axes otherwise.
|
|
1664
|
+
bbox = mtransforms.Bbox.union([
|
|
1665
|
+
*bboxes2, self.axes.spines.get("top", self.axes).get_window_extent()])
|
|
1666
|
+
self.label.set_position(
|
|
1667
|
+
(x, bbox.y1 + self.labelpad * self.get_figure(root=True).dpi / 72))
|
|
1668
|
+
|
|
1669
|
+
def _update_offset_text_position(self, bboxes, bboxes2):
|
|
1670
|
+
"""
|
|
1671
|
+
Update the offset_text position based on the sequence of bounding
|
|
1672
|
+
boxes of all the ticklabels
|
|
1673
|
+
"""
|
|
1674
|
+
x, y = self.offsetText.get_position()
|
|
1675
|
+
if not hasattr(self, '_tick_position'):
|
|
1676
|
+
self._tick_position = 'bottom'
|
|
1677
|
+
if self._tick_position == 'bottom':
|
|
1678
|
+
if not len(bboxes):
|
|
1679
|
+
bottom = self.axes.bbox.ymin
|
|
1680
|
+
else:
|
|
1681
|
+
bbox = mtransforms.Bbox.union(bboxes)
|
|
1682
|
+
bottom = bbox.y0
|
|
1683
|
+
y = bottom - self.OFFSETTEXTPAD * self.get_figure(root=True).dpi / 72
|
|
1684
|
+
else:
|
|
1685
|
+
if not len(bboxes2):
|
|
1686
|
+
top = self.axes.bbox.ymax
|
|
1687
|
+
else:
|
|
1688
|
+
bbox = mtransforms.Bbox.union(bboxes2)
|
|
1689
|
+
top = bbox.y1
|
|
1690
|
+
y = top + self.OFFSETTEXTPAD * self.get_figure(root=True).dpi / 72
|
|
1691
|
+
self.offsetText.set_position((x, y))
|
|
1692
|
+
|
|
1693
|
+
def set_ticks_position(self, position):
|
|
1694
|
+
if position == 'top':
|
|
1695
|
+
self.set_tick_params(which='both', top=True, labeltop=True,
|
|
1696
|
+
bottom=False, labelbottom=False)
|
|
1697
|
+
self._tick_position = 'top'
|
|
1698
|
+
self.offsetText.set_verticalalignment('bottom')
|
|
1699
|
+
elif position == 'bottom':
|
|
1700
|
+
self.set_tick_params(which='both', top=False, labeltop=False,
|
|
1701
|
+
bottom=True, labelbottom=True)
|
|
1702
|
+
self._tick_position = 'bottom'
|
|
1703
|
+
self.offsetText.set_verticalalignment('top')
|
|
1704
|
+
elif position == 'both':
|
|
1705
|
+
self.set_tick_params(which='both', top=True,
|
|
1706
|
+
bottom=True)
|
|
1707
|
+
elif position == 'none':
|
|
1708
|
+
self.set_tick_params(which='both', top=False,
|
|
1709
|
+
bottom=False)
|
|
1710
|
+
elif position == 'default':
|
|
1711
|
+
self.set_tick_params(which='both', top=True, labeltop=False,
|
|
1712
|
+
bottom=True, labelbottom=True)
|
|
1713
|
+
self._tick_position = 'bottom'
|
|
1714
|
+
self.offsetText.set_verticalalignment('top')
|
|
1715
|
+
else:
|
|
1716
|
+
_api.check_in_list(['top', 'bottom', 'both', 'default', 'none'],
|
|
1717
|
+
position=position)
|
|
1718
|
+
self.stale = True
|
|
1719
|
+
|
|
1720
|
+
def tick_top(self):
|
|
1721
|
+
label = True
|
|
1722
|
+
if 'label1On' in self._major_tick_kw:
|
|
1723
|
+
label = (self._major_tick_kw['label1On']
|
|
1724
|
+
or self._major_tick_kw['label2On'])
|
|
1725
|
+
self.set_ticks_position('top')
|
|
1726
|
+
# If labels were turned off before this was called, leave them off.
|
|
1727
|
+
self.set_tick_params(which='both', labeltop=label)
|
|
1728
|
+
|
|
1729
|
+
def tick_bottom(self):
|
|
1730
|
+
label = True
|
|
1731
|
+
if 'label1On' in self._major_tick_kw:
|
|
1732
|
+
label = (self._major_tick_kw['label1On']
|
|
1733
|
+
or self._major_tick_kw['label2On'])
|
|
1734
|
+
self.set_ticks_position('bottom')
|
|
1735
|
+
# If labels were turned off before this was called, leave them off.
|
|
1736
|
+
self.set_tick_params(which='both', labelbottom=label)
|
|
1737
|
+
|
|
1738
|
+
def get_ticks_position(self):
|
|
1739
|
+
return {1: "bottom", 2: "top",
|
|
1740
|
+
"default": "default", "unknown": "unknown"}[
|
|
1741
|
+
self._get_ticks_position()]
|
|
1742
|
+
|
|
1743
|
+
get_view_interval, set_view_interval = _make_getset_interval(
|
|
1744
|
+
"view", "viewLim", "intervalx")
|
|
1745
|
+
get_data_interval, set_data_interval = _make_getset_interval(
|
|
1746
|
+
"data", "dataLim", "intervalx")
|
|
1747
|
+
|
|
1748
|
+
def get_minpos(self):
|
|
1749
|
+
return self.axes.dataLim.minposx
|
|
1750
|
+
|
|
1751
|
+
def set_default_intervals(self):
|
|
1752
|
+
# only change view if dataLim has not changed and user has
|
|
1753
|
+
# not changed the view:
|
|
1754
|
+
if (not self.axes.dataLim.mutatedx() and
|
|
1755
|
+
not self.axes.viewLim.mutatedx()):
|
|
1756
|
+
if self._converter is not None:
|
|
1757
|
+
info = self._converter.axisinfo(self.units, self)
|
|
1758
|
+
if info.default_limits is not None:
|
|
1759
|
+
xmin, xmax = self.convert_units(info.default_limits)
|
|
1760
|
+
self.axes.viewLim.intervalx = xmin, xmax
|
|
1761
|
+
self.stale = True
|
|
1762
|
+
|
|
1763
|
+
def get_tick_space(self):
|
|
1764
|
+
ends = mtransforms.Bbox.unit().transformed(
|
|
1765
|
+
self.axes.transAxes - self.get_figure(root=False).dpi_scale_trans)
|
|
1766
|
+
length = ends.width * 72
|
|
1767
|
+
# There is a heuristic here that the aspect ratio of tick text
|
|
1768
|
+
# is no more than 3:1
|
|
1769
|
+
size = self._get_tick_label_size('x') * 3
|
|
1770
|
+
if size > 0:
|
|
1771
|
+
return int(np.floor(length / size))
|
|
1772
|
+
else:
|
|
1773
|
+
return 2**31 - 1
|
|
1774
|
+
|
|
1775
|
+
|
|
1776
|
+
class YAxis(Axis):
|
|
1777
|
+
__name__ = 'yaxis'
|
|
1778
|
+
axis_name = 'y' #: Read-only name identifying the axis.
|
|
1779
|
+
_tick_class = YTick
|
|
1780
|
+
|
|
1781
|
+
def __init__(self, *args, **kwargs):
|
|
1782
|
+
super().__init__(*args, **kwargs)
|
|
1783
|
+
self._init()
|
|
1784
|
+
|
|
1785
|
+
def _init(self):
|
|
1786
|
+
# x in display coords, y in axes coords (updated at draw time by the
|
|
1787
|
+
# Rust core).
|
|
1788
|
+
self.label.set(
|
|
1789
|
+
x=0, y=0.5,
|
|
1790
|
+
verticalalignment='bottom', horizontalalignment='center',
|
|
1791
|
+
rotation='vertical', rotation_mode='anchor',
|
|
1792
|
+
transform=mtransforms.blended_transform_factory(
|
|
1793
|
+
mtransforms.IdentityTransform(), self.axes.transAxes),
|
|
1794
|
+
)
|
|
1795
|
+
self.label_position = 'left'
|
|
1796
|
+
|
|
1797
|
+
if mpl.rcParams['ytick.labelcolor'] == 'inherit':
|
|
1798
|
+
tick_color = mpl.rcParams['ytick.color']
|
|
1799
|
+
else:
|
|
1800
|
+
tick_color = mpl.rcParams['ytick.labelcolor']
|
|
1801
|
+
|
|
1802
|
+
# x in axes coords, y in display coords(!).
|
|
1803
|
+
self.offsetText.set(
|
|
1804
|
+
x=0, y=0.5,
|
|
1805
|
+
verticalalignment='baseline', horizontalalignment='left',
|
|
1806
|
+
transform=mtransforms.blended_transform_factory(
|
|
1807
|
+
self.axes.transAxes, mtransforms.IdentityTransform()),
|
|
1808
|
+
fontsize=mpl.rcParams['ytick.labelsize'],
|
|
1809
|
+
color=tick_color
|
|
1810
|
+
)
|
|
1811
|
+
self.offset_text_position = 'left'
|
|
1812
|
+
|
|
1813
|
+
def contains(self, mouseevent):
|
|
1814
|
+
if self._different_canvas(mouseevent):
|
|
1815
|
+
return False, {}
|
|
1816
|
+
x, y = mouseevent.x, mouseevent.y
|
|
1817
|
+
try:
|
|
1818
|
+
trans = self.axes.transAxes.inverted()
|
|
1819
|
+
xaxes, yaxes = trans.transform((x, y))
|
|
1820
|
+
except ValueError:
|
|
1821
|
+
return False, {}
|
|
1822
|
+
(l, b), (r, t) = self.axes.transAxes.transform([(0, 0), (1, 1)])
|
|
1823
|
+
inaxis = 0 <= yaxes <= 1 and (
|
|
1824
|
+
l - self._pickradius < x < l or
|
|
1825
|
+
r < x < r + self._pickradius)
|
|
1826
|
+
return inaxis, {}
|
|
1827
|
+
|
|
1828
|
+
def set_label_position(self, position):
|
|
1829
|
+
self.label.set_rotation_mode('anchor')
|
|
1830
|
+
self.label.set_verticalalignment(_api.getitem_checked({
|
|
1831
|
+
'left': 'bottom', 'right': 'top',
|
|
1832
|
+
}, position=position))
|
|
1833
|
+
self.label_position = position
|
|
1834
|
+
self.stale = True
|
|
1835
|
+
|
|
1836
|
+
def _update_label_position(self, renderer):
|
|
1837
|
+
"""
|
|
1838
|
+
Update the label position based on the bounding box enclosing
|
|
1839
|
+
all the ticklabels and axis spine
|
|
1840
|
+
"""
|
|
1841
|
+
if not self._autolabelpos:
|
|
1842
|
+
return
|
|
1843
|
+
|
|
1844
|
+
# get bounding boxes for this axis and any siblings
|
|
1845
|
+
# that have been set by `fig.align_ylabels()`
|
|
1846
|
+
bboxes, bboxes2 = self._get_tick_boxes_siblings(renderer=renderer)
|
|
1847
|
+
x, y = self.label.get_position()
|
|
1848
|
+
|
|
1849
|
+
if self.label_position == 'left':
|
|
1850
|
+
# Union with extents of the left spine if present, of the axes otherwise.
|
|
1851
|
+
bbox = mtransforms.Bbox.union([
|
|
1852
|
+
*bboxes, self.axes.spines.get("left", self.axes).get_window_extent()])
|
|
1853
|
+
self.label.set_position(
|
|
1854
|
+
(bbox.x0 - self.labelpad * self.get_figure(root=True).dpi / 72, y))
|
|
1855
|
+
else:
|
|
1856
|
+
# Union with extents of the right spine if present, of the axes otherwise.
|
|
1857
|
+
bbox = mtransforms.Bbox.union([
|
|
1858
|
+
*bboxes2, self.axes.spines.get("right", self.axes).get_window_extent()])
|
|
1859
|
+
self.label.set_position(
|
|
1860
|
+
(bbox.x1 + self.labelpad * self.get_figure(root=True).dpi / 72, y))
|
|
1861
|
+
|
|
1862
|
+
def _update_offset_text_position(self, bboxes, bboxes2):
|
|
1863
|
+
"""
|
|
1864
|
+
Update the offset_text position based on the sequence of bounding
|
|
1865
|
+
boxes of all the ticklabels
|
|
1866
|
+
"""
|
|
1867
|
+
x, _ = self.offsetText.get_position()
|
|
1868
|
+
if 'outline' in self.axes.spines:
|
|
1869
|
+
# Special case for colorbars:
|
|
1870
|
+
bbox = self.axes.spines['outline'].get_window_extent()
|
|
1871
|
+
else:
|
|
1872
|
+
bbox = self.axes.bbox
|
|
1873
|
+
top = bbox.ymax
|
|
1874
|
+
self.offsetText.set_position(
|
|
1875
|
+
(x, top + self.OFFSETTEXTPAD * self.get_figure(root=True).dpi / 72)
|
|
1876
|
+
)
|
|
1877
|
+
|
|
1878
|
+
def set_offset_position(self, position):
|
|
1879
|
+
x, y = self.offsetText.get_position()
|
|
1880
|
+
x = _api.getitem_checked({'left': 0, 'right': 1}, position=position)
|
|
1881
|
+
|
|
1882
|
+
self.offsetText.set_ha(position)
|
|
1883
|
+
self.offsetText.set_position((x, y))
|
|
1884
|
+
self.stale = True
|
|
1885
|
+
|
|
1886
|
+
def set_ticks_position(self, position):
|
|
1887
|
+
if position == 'right':
|
|
1888
|
+
self.set_tick_params(which='both', right=True, labelright=True,
|
|
1889
|
+
left=False, labelleft=False)
|
|
1890
|
+
self.set_offset_position(position)
|
|
1891
|
+
elif position == 'left':
|
|
1892
|
+
self.set_tick_params(which='both', right=False, labelright=False,
|
|
1893
|
+
left=True, labelleft=True)
|
|
1894
|
+
self.set_offset_position(position)
|
|
1895
|
+
elif position == 'both':
|
|
1896
|
+
self.set_tick_params(which='both', right=True,
|
|
1897
|
+
left=True)
|
|
1898
|
+
elif position == 'none':
|
|
1899
|
+
self.set_tick_params(which='both', right=False,
|
|
1900
|
+
left=False)
|
|
1901
|
+
elif position == 'default':
|
|
1902
|
+
self.set_tick_params(which='both', right=True, labelright=False,
|
|
1903
|
+
left=True, labelleft=True)
|
|
1904
|
+
else:
|
|
1905
|
+
_api.check_in_list(['left', 'right', 'both', 'default', 'none'],
|
|
1906
|
+
position=position)
|
|
1907
|
+
self.stale = True
|
|
1908
|
+
|
|
1909
|
+
def tick_right(self):
|
|
1910
|
+
label = True
|
|
1911
|
+
if 'label1On' in self._major_tick_kw:
|
|
1912
|
+
label = (self._major_tick_kw['label1On']
|
|
1913
|
+
or self._major_tick_kw['label2On'])
|
|
1914
|
+
self.set_ticks_position('right')
|
|
1915
|
+
# if labels were turned off before this was called
|
|
1916
|
+
# leave them off
|
|
1917
|
+
self.set_tick_params(which='both', labelright=label)
|
|
1918
|
+
|
|
1919
|
+
def tick_left(self):
|
|
1920
|
+
label = True
|
|
1921
|
+
if 'label1On' in self._major_tick_kw:
|
|
1922
|
+
label = (self._major_tick_kw['label1On']
|
|
1923
|
+
or self._major_tick_kw['label2On'])
|
|
1924
|
+
self.set_ticks_position('left')
|
|
1925
|
+
# if labels were turned off before this was called
|
|
1926
|
+
# leave them off
|
|
1927
|
+
self.set_tick_params(which='both', labelleft=label)
|
|
1928
|
+
|
|
1929
|
+
def get_ticks_position(self):
|
|
1930
|
+
return {1: "left", 2: "right",
|
|
1931
|
+
"default": "default", "unknown": "unknown"}[
|
|
1932
|
+
self._get_ticks_position()]
|
|
1933
|
+
|
|
1934
|
+
get_view_interval, set_view_interval = _make_getset_interval(
|
|
1935
|
+
"view", "viewLim", "intervaly")
|
|
1936
|
+
get_data_interval, set_data_interval = _make_getset_interval(
|
|
1937
|
+
"data", "dataLim", "intervaly")
|
|
1938
|
+
|
|
1939
|
+
def get_minpos(self):
|
|
1940
|
+
return self.axes.dataLim.minposy
|
|
1941
|
+
|
|
1942
|
+
def set_default_intervals(self):
|
|
1943
|
+
# only change view if dataLim has not changed and user has
|
|
1944
|
+
# not changed the view:
|
|
1945
|
+
if (not self.axes.dataLim.mutatedy() and
|
|
1946
|
+
not self.axes.viewLim.mutatedy()):
|
|
1947
|
+
if self._converter is not None:
|
|
1948
|
+
info = self._converter.axisinfo(self.units, self)
|
|
1949
|
+
if info.default_limits is not None:
|
|
1950
|
+
ymin, ymax = self.convert_units(info.default_limits)
|
|
1951
|
+
self.axes.viewLim.intervaly = ymin, ymax
|
|
1952
|
+
self.stale = True
|
|
1953
|
+
|
|
1954
|
+
def get_tick_space(self):
|
|
1955
|
+
ends = mtransforms.Bbox.unit().transformed(
|
|
1956
|
+
self.axes.transAxes - self.get_figure(root=False).dpi_scale_trans)
|
|
1957
|
+
length = ends.height * 72
|
|
1958
|
+
# Having a spacing of at least 2 just looks good.
|
|
1959
|
+
size = self._get_tick_label_size('y') * 2
|
|
1960
|
+
if size > 0:
|
|
1961
|
+
return int(np.floor(length / size))
|
|
1962
|
+
else:
|
|
1963
|
+
return 2**31 - 1
|