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
|
@@ -0,0 +1,1586 @@
|
|
|
1
|
+
# Vendored from matplotlib 3.11 (see licenses/LICENSE_MATPLOTLIB), adapted for matplotlib_rs.
|
|
2
|
+
"""
|
|
3
|
+
Colorbars are a visualization of the mapping from scalar values to colors.
|
|
4
|
+
In Matplotlib they are drawn into a dedicated `~.axes.Axes`.
|
|
5
|
+
|
|
6
|
+
.. note::
|
|
7
|
+
Colorbars are typically created through `.Figure.colorbar` or its pyplot
|
|
8
|
+
wrapper `.pyplot.colorbar`, which internally use `.Colorbar` together with
|
|
9
|
+
`.make_axes_gridspec` (for `.GridSpec`-positioned Axes) or `.make_axes` (for
|
|
10
|
+
non-`.GridSpec`-positioned Axes).
|
|
11
|
+
|
|
12
|
+
End-users most likely won't need to directly use this module's API.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import functools
|
|
16
|
+
import logging
|
|
17
|
+
|
|
18
|
+
import numpy as np
|
|
19
|
+
|
|
20
|
+
import matplotlib_rs as mpl
|
|
21
|
+
from matplotlib_rs import _api, cbook, collections, colors, contour, ticker
|
|
22
|
+
import matplotlib_rs.artist as martist
|
|
23
|
+
import matplotlib_rs.colorizer as mcolorizer
|
|
24
|
+
import matplotlib_rs.patches as mpatches
|
|
25
|
+
import matplotlib_rs.path as mpath
|
|
26
|
+
import matplotlib_rs.spines as mspines
|
|
27
|
+
import matplotlib_rs.transforms as mtransforms
|
|
28
|
+
from matplotlib_rs import _docstring
|
|
29
|
+
|
|
30
|
+
_log = logging.getLogger(__name__)
|
|
31
|
+
|
|
32
|
+
_docstring.interpd.register(
|
|
33
|
+
_make_axes_kw_doc="""
|
|
34
|
+
location : None or {'left', 'right', 'top', 'bottom'}
|
|
35
|
+
The location, relative to the parent Axes, where the colorbar Axes
|
|
36
|
+
is created. It also determines the *orientation* of the colorbar
|
|
37
|
+
(colorbars on the left and right are vertical, colorbars at the top
|
|
38
|
+
and bottom are horizontal). If None, the location will come from the
|
|
39
|
+
*orientation* if it is set (vertical colorbars on the right, horizontal
|
|
40
|
+
ones at the bottom), or default to 'right' if *orientation* is unset.
|
|
41
|
+
|
|
42
|
+
orientation : None or {'vertical', 'horizontal'}
|
|
43
|
+
The orientation of the colorbar. It is preferable to set the *location*
|
|
44
|
+
of the colorbar, as that also determines the *orientation*; passing
|
|
45
|
+
incompatible values for *location* and *orientation* raises an exception.
|
|
46
|
+
|
|
47
|
+
fraction : float, default: 0.15
|
|
48
|
+
Fraction of original Axes to use for colorbar.
|
|
49
|
+
|
|
50
|
+
shrink : float, default: 1.0
|
|
51
|
+
Fraction by which to multiply the size of the colorbar.
|
|
52
|
+
|
|
53
|
+
aspect : float, default: 20
|
|
54
|
+
Ratio of long to short dimensions.
|
|
55
|
+
|
|
56
|
+
pad : float, default: 0.05 if vertical, 0.15 if horizontal
|
|
57
|
+
Fraction of original Axes between colorbar and new image Axes.
|
|
58
|
+
|
|
59
|
+
anchor : (float, float), optional
|
|
60
|
+
The anchor point of the colorbar Axes.
|
|
61
|
+
Defaults to (0.0, 0.5) if vertical; (0.5, 1.0) if horizontal.
|
|
62
|
+
|
|
63
|
+
panchor : (float, float), or *False*, optional
|
|
64
|
+
The anchor point of the colorbar parent Axes. If *False*, the parent
|
|
65
|
+
axes' anchor will be unchanged.
|
|
66
|
+
Defaults to (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal.""",
|
|
67
|
+
_colormap_kw_doc="""
|
|
68
|
+
extend : {'neither', 'both', 'min', 'max'}
|
|
69
|
+
Make pointed end(s) for out-of-range values (unless 'neither'). These are
|
|
70
|
+
set for a given colormap using the colormap set_under and set_over methods.
|
|
71
|
+
|
|
72
|
+
extendfrac : {*None*, 'auto', length, lengths}
|
|
73
|
+
If set to *None*, both the minimum and maximum triangular colorbar
|
|
74
|
+
extensions will have a length of 5% of the interior colorbar length (this
|
|
75
|
+
is the default setting).
|
|
76
|
+
|
|
77
|
+
If set to 'auto', makes the triangular colorbar extensions the same lengths
|
|
78
|
+
as the interior boxes (when *spacing* is set to 'uniform') or the same
|
|
79
|
+
lengths as the respective adjacent interior boxes (when *spacing* is set to
|
|
80
|
+
'proportional').
|
|
81
|
+
|
|
82
|
+
If a scalar, indicates the length of both the minimum and maximum
|
|
83
|
+
triangular colorbar extensions as a fraction of the interior colorbar
|
|
84
|
+
length. A two-element sequence of fractions may also be given, indicating
|
|
85
|
+
the lengths of the minimum and maximum colorbar extensions respectively as
|
|
86
|
+
a fraction of the interior colorbar length.
|
|
87
|
+
|
|
88
|
+
extendrect : bool
|
|
89
|
+
If *False* the minimum and maximum colorbar extensions will be triangular
|
|
90
|
+
(the default). If *True* the extensions will be rectangular.
|
|
91
|
+
|
|
92
|
+
ticks : None or list of ticks or Locator
|
|
93
|
+
If None, ticks are determined automatically from the input.
|
|
94
|
+
|
|
95
|
+
format : None or str or Formatter
|
|
96
|
+
If None, `~.ticker.ScalarFormatter` is used.
|
|
97
|
+
Format strings, e.g., ``"%4.2e"`` or ``"{x:.2e}"``, are supported.
|
|
98
|
+
An alternative `~.ticker.Formatter` may be given instead.
|
|
99
|
+
|
|
100
|
+
drawedges : bool
|
|
101
|
+
Whether to draw lines at color boundaries.
|
|
102
|
+
|
|
103
|
+
label : str
|
|
104
|
+
The label on the colorbar's long axis.
|
|
105
|
+
|
|
106
|
+
boundaries, values : None or a sequence
|
|
107
|
+
If unset, the colormap will be displayed on a 0-1 scale.
|
|
108
|
+
If sequences, *values* must have a length 1 less than *boundaries*. For
|
|
109
|
+
each region delimited by adjacent entries in *boundaries*, the color mapped
|
|
110
|
+
to the corresponding value in *values* will be used. The size of each
|
|
111
|
+
region is determined by the *spacing* parameter.
|
|
112
|
+
Normally only useful for indexed colors (i.e. ``norm=NoNorm()``) or other
|
|
113
|
+
unusual circumstances.
|
|
114
|
+
|
|
115
|
+
spacing : {'uniform', 'proportional'}
|
|
116
|
+
For discrete colorbars (`.BoundaryNorm` or contours), 'uniform' gives each
|
|
117
|
+
color the same space; 'proportional' makes the space proportional to the
|
|
118
|
+
data interval.""")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _set_ticks_on_axis_warn(*args, **kwargs):
|
|
122
|
+
# a top level function which gets put in at the axes'
|
|
123
|
+
# set_xticks and set_yticks by Colorbar.__init__.
|
|
124
|
+
_api.warn_external("Use the colorbar set_ticks() method instead.")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class _ColorbarSpine(mspines.Spine):
|
|
128
|
+
def __init__(self, axes):
|
|
129
|
+
self._ax = axes
|
|
130
|
+
super().__init__(axes, 'colorbar', mpath.Path(np.empty((0, 2))))
|
|
131
|
+
mpatches.Patch.set_transform(self, axes.transAxes)
|
|
132
|
+
|
|
133
|
+
def get_window_extent(self, renderer=None):
|
|
134
|
+
# This Spine has no Axis associated with it, and doesn't need to adjust
|
|
135
|
+
# its location, so we can directly get the window extent from the
|
|
136
|
+
# super-super-class.
|
|
137
|
+
return mpatches.Patch.get_window_extent(self, renderer=renderer)
|
|
138
|
+
|
|
139
|
+
def set_xy(self, xy):
|
|
140
|
+
self._path = mpath.Path(xy, closed=True)
|
|
141
|
+
self._xy = xy
|
|
142
|
+
self.stale = True
|
|
143
|
+
|
|
144
|
+
def draw(self, renderer):
|
|
145
|
+
ret = mpatches.Patch.draw(self, renderer)
|
|
146
|
+
self.stale = False
|
|
147
|
+
return ret
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class _ColorbarAxesLocator:
|
|
151
|
+
"""
|
|
152
|
+
Shrink the Axes if there are triangular or rectangular extends.
|
|
153
|
+
"""
|
|
154
|
+
def __init__(self, cbar):
|
|
155
|
+
self._cbar = cbar
|
|
156
|
+
self._orig_locator = cbar.ax._axes_locator
|
|
157
|
+
|
|
158
|
+
def __call__(self, ax, renderer):
|
|
159
|
+
if self._orig_locator is not None:
|
|
160
|
+
pos = self._orig_locator(ax, renderer)
|
|
161
|
+
else:
|
|
162
|
+
pos = ax.get_position(original=True)
|
|
163
|
+
if self._cbar.extend == 'neither':
|
|
164
|
+
return pos
|
|
165
|
+
|
|
166
|
+
y, extendlen = self._cbar._proportional_y()
|
|
167
|
+
if not self._cbar._extend_lower():
|
|
168
|
+
extendlen[0] = 0
|
|
169
|
+
if not self._cbar._extend_upper():
|
|
170
|
+
extendlen[1] = 0
|
|
171
|
+
len = sum(extendlen) + 1
|
|
172
|
+
shrink = 1 / len
|
|
173
|
+
offset = extendlen[0] / len
|
|
174
|
+
# we need to reset the aspect ratio of the axes to account
|
|
175
|
+
# of the extends...
|
|
176
|
+
if hasattr(ax, '_colorbar_info'):
|
|
177
|
+
aspect = ax._colorbar_info['aspect']
|
|
178
|
+
else:
|
|
179
|
+
aspect = False
|
|
180
|
+
# now shrink and/or offset to take into account the
|
|
181
|
+
# extend tri/rectangles.
|
|
182
|
+
if self._cbar.orientation == 'vertical':
|
|
183
|
+
if aspect:
|
|
184
|
+
self._cbar.ax.set_box_aspect(aspect*shrink)
|
|
185
|
+
pos = pos.shrunk(1, shrink).translated(0, offset * pos.height)
|
|
186
|
+
else:
|
|
187
|
+
if aspect:
|
|
188
|
+
self._cbar.ax.set_box_aspect(1/(aspect * shrink))
|
|
189
|
+
pos = pos.shrunk(shrink, 1).translated(offset * pos.width, 0)
|
|
190
|
+
return pos
|
|
191
|
+
|
|
192
|
+
def get_subplotspec(self):
|
|
193
|
+
# make tight_layout happy..
|
|
194
|
+
return (
|
|
195
|
+
self._cbar.ax.get_subplotspec()
|
|
196
|
+
or getattr(self._orig_locator, "get_subplotspec", lambda: None)())
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _remove_cbar_axes(ax, cbar):
|
|
200
|
+
"""
|
|
201
|
+
Replacement remove method for a colorbar's axes, so that the colorbar is
|
|
202
|
+
properly removed.
|
|
203
|
+
|
|
204
|
+
Note we define this at the module level to preserve pickling. A lambda or
|
|
205
|
+
local def within the Colorbar.__init__ method will not work.
|
|
206
|
+
"""
|
|
207
|
+
cbar.remove()
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
@_docstring.interpd
|
|
211
|
+
class Colorbar:
|
|
212
|
+
r"""
|
|
213
|
+
Draw a colorbar in an existing Axes.
|
|
214
|
+
|
|
215
|
+
Typically, colorbars are created using `.Figure.colorbar` or
|
|
216
|
+
`.pyplot.colorbar` and associated with `.ColorizingArtist`\s (such as an
|
|
217
|
+
`.AxesImage` generated via `~.axes.Axes.imshow`).
|
|
218
|
+
|
|
219
|
+
In order to draw a colorbar not associated with other elements in the
|
|
220
|
+
figure, e.g. when showing a colormap by itself, one can create an empty
|
|
221
|
+
`.ColorizingArtist`, or directly pass *cmap* and *norm* instead of *mappable*
|
|
222
|
+
to `Colorbar`.
|
|
223
|
+
|
|
224
|
+
Useful public methods are :meth:`set_label` and :meth:`add_lines`.
|
|
225
|
+
|
|
226
|
+
Attributes
|
|
227
|
+
----------
|
|
228
|
+
ax : `~matplotlib.axes.Axes`
|
|
229
|
+
The `~.axes.Axes` instance in which the colorbar is drawn.
|
|
230
|
+
lines : list
|
|
231
|
+
A list of `.LineCollection` (empty if no lines were drawn).
|
|
232
|
+
dividers : `.LineCollection`
|
|
233
|
+
A LineCollection (empty if *drawedges* is ``False``).
|
|
234
|
+
"""
|
|
235
|
+
|
|
236
|
+
n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize
|
|
237
|
+
|
|
238
|
+
def __init__(
|
|
239
|
+
self, ax, mappable=None, *,
|
|
240
|
+
alpha=None,
|
|
241
|
+
location=None,
|
|
242
|
+
extend=None,
|
|
243
|
+
extendfrac=None,
|
|
244
|
+
extendrect=False,
|
|
245
|
+
ticks=None,
|
|
246
|
+
format=None,
|
|
247
|
+
values=None,
|
|
248
|
+
boundaries=None,
|
|
249
|
+
spacing='uniform',
|
|
250
|
+
drawedges=False,
|
|
251
|
+
label='',
|
|
252
|
+
cmap=None, norm=None, # redundant with *mappable*
|
|
253
|
+
orientation=None, ticklocation='auto', # redundant with *location*
|
|
254
|
+
):
|
|
255
|
+
"""
|
|
256
|
+
Parameters
|
|
257
|
+
----------
|
|
258
|
+
ax : `~matplotlib.axes.Axes`
|
|
259
|
+
The `~.axes.Axes` instance in which the colorbar is drawn.
|
|
260
|
+
|
|
261
|
+
mappable : `.ColorizingArtist`
|
|
262
|
+
The mappable whose colormap and norm will be used.
|
|
263
|
+
|
|
264
|
+
To show the colors versus index instead of on a 0-1 scale, set the
|
|
265
|
+
mappable's norm to ``colors.NoNorm()``.
|
|
266
|
+
|
|
267
|
+
alpha : float
|
|
268
|
+
The colorbar transparency between 0 (transparent) and 1 (opaque).
|
|
269
|
+
|
|
270
|
+
location : None or {'left', 'right', 'top', 'bottom'}
|
|
271
|
+
Set the colorbar's *orientation* and *ticklocation*. Colorbars on
|
|
272
|
+
the left and right are vertical, colorbars at the top and bottom
|
|
273
|
+
are horizontal. The *ticklocation* is the same as *location*, so if
|
|
274
|
+
*location* is 'top', the ticks are on the top. *orientation* and/or
|
|
275
|
+
*ticklocation* can be provided as well and overrides the value set by
|
|
276
|
+
*location*, but there will be an error for incompatible combinations.
|
|
277
|
+
|
|
278
|
+
.. versionadded:: 3.7
|
|
279
|
+
|
|
280
|
+
%(_colormap_kw_doc)s
|
|
281
|
+
|
|
282
|
+
Other Parameters
|
|
283
|
+
----------------
|
|
284
|
+
cmap : `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
|
|
285
|
+
The colormap to use. This parameter is ignored, unless *mappable* is
|
|
286
|
+
None.
|
|
287
|
+
|
|
288
|
+
norm : `~matplotlib.colors.Normalize`
|
|
289
|
+
The normalization to use. This parameter is ignored, unless *mappable*
|
|
290
|
+
is None.
|
|
291
|
+
|
|
292
|
+
orientation : None or {'vertical', 'horizontal'}
|
|
293
|
+
If None, use the value determined by *location*. If both
|
|
294
|
+
*orientation* and *location* are None then defaults to 'vertical'.
|
|
295
|
+
|
|
296
|
+
ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}
|
|
297
|
+
The location of the colorbar ticks. The *ticklocation* must match
|
|
298
|
+
*orientation*. For example, a horizontal colorbar can only have ticks
|
|
299
|
+
at the top or the bottom. If 'auto', the ticks will be the same as
|
|
300
|
+
*location*, so a colorbar to the left will have ticks to the left. If
|
|
301
|
+
*location* is None, the ticks will be at the bottom for a horizontal
|
|
302
|
+
colorbar and at the right for a vertical.
|
|
303
|
+
"""
|
|
304
|
+
if mappable is None:
|
|
305
|
+
colorizer = mcolorizer.Colorizer(norm=norm, cmap=cmap)
|
|
306
|
+
mappable = mcolorizer.ColorizingArtist(colorizer)
|
|
307
|
+
|
|
308
|
+
self.mappable = mappable
|
|
309
|
+
cmap = mappable.cmap
|
|
310
|
+
norm = mappable.norm
|
|
311
|
+
|
|
312
|
+
filled = True
|
|
313
|
+
if isinstance(mappable, contour.ContourSet):
|
|
314
|
+
cs = mappable
|
|
315
|
+
alpha = cs.get_alpha()
|
|
316
|
+
boundaries = cs._levels
|
|
317
|
+
values = cs.cvalues
|
|
318
|
+
extend = cs.extend
|
|
319
|
+
filled = cs.filled
|
|
320
|
+
if ticks is None:
|
|
321
|
+
ticks = ticker.FixedLocator(cs.levels, nbins=10)
|
|
322
|
+
elif isinstance(mappable, martist.Artist):
|
|
323
|
+
alpha = mappable.get_alpha()
|
|
324
|
+
|
|
325
|
+
mappable.colorbar = self
|
|
326
|
+
mappable.colorbar_cid = mappable.callbacks.connect(
|
|
327
|
+
'changed', self.update_normal)
|
|
328
|
+
|
|
329
|
+
location_orientation = _get_orientation_from_location(location)
|
|
330
|
+
|
|
331
|
+
_api.check_in_list(
|
|
332
|
+
[None, 'vertical', 'horizontal'], orientation=orientation)
|
|
333
|
+
_api.check_in_list(
|
|
334
|
+
['auto', 'left', 'right', 'top', 'bottom'],
|
|
335
|
+
ticklocation=ticklocation)
|
|
336
|
+
_api.check_in_list(
|
|
337
|
+
['uniform', 'proportional'], spacing=spacing)
|
|
338
|
+
|
|
339
|
+
if location_orientation is not None and orientation is not None:
|
|
340
|
+
if location_orientation != orientation:
|
|
341
|
+
raise TypeError(
|
|
342
|
+
"location and orientation are mutually exclusive")
|
|
343
|
+
else:
|
|
344
|
+
orientation = orientation or location_orientation or "vertical"
|
|
345
|
+
|
|
346
|
+
self.ax = ax
|
|
347
|
+
self.ax._axes_locator = _ColorbarAxesLocator(self)
|
|
348
|
+
|
|
349
|
+
if extend is None:
|
|
350
|
+
if (not isinstance(mappable, contour.ContourSet)
|
|
351
|
+
and getattr(cmap, 'colorbar_extend', False) is not False):
|
|
352
|
+
extend = cmap.colorbar_extend
|
|
353
|
+
elif hasattr(norm, 'extend'):
|
|
354
|
+
extend = norm.extend
|
|
355
|
+
else:
|
|
356
|
+
extend = 'neither'
|
|
357
|
+
self.alpha = None
|
|
358
|
+
# Call set_alpha to handle array-like alphas properly
|
|
359
|
+
self.set_alpha(alpha)
|
|
360
|
+
self.cmap = cmap
|
|
361
|
+
self.norm = norm
|
|
362
|
+
self.values = values
|
|
363
|
+
self.boundaries = boundaries
|
|
364
|
+
self.extend = extend
|
|
365
|
+
self._inside = _api.getitem_checked(
|
|
366
|
+
{'neither': slice(0, None), 'both': slice(1, -1),
|
|
367
|
+
'min': slice(1, None), 'max': slice(0, -1)},
|
|
368
|
+
extend=extend)
|
|
369
|
+
self.spacing = spacing
|
|
370
|
+
self.orientation = orientation
|
|
371
|
+
self.drawedges = drawedges
|
|
372
|
+
self._filled = filled
|
|
373
|
+
self.extendfrac = extendfrac
|
|
374
|
+
self.extendrect = extendrect
|
|
375
|
+
self._extend_patches = []
|
|
376
|
+
self.solids = None
|
|
377
|
+
self.solids_patches = []
|
|
378
|
+
self.lines = []
|
|
379
|
+
|
|
380
|
+
for spine in self.ax.spines.values():
|
|
381
|
+
spine.set_visible(False)
|
|
382
|
+
self.outline = self.ax.spines['outline'] = _ColorbarSpine(self.ax)
|
|
383
|
+
|
|
384
|
+
self.dividers = collections.LineCollection(
|
|
385
|
+
[],
|
|
386
|
+
colors=[mpl.rcParams['axes.edgecolor']],
|
|
387
|
+
linewidths=[0.5 * mpl.rcParams['axes.linewidth']],
|
|
388
|
+
clip_on=False)
|
|
389
|
+
self.ax.add_collection(self.dividers, autolim=False)
|
|
390
|
+
|
|
391
|
+
self._locator = None
|
|
392
|
+
self._minorlocator = None
|
|
393
|
+
self._formatter = None
|
|
394
|
+
self._minorformatter = None
|
|
395
|
+
|
|
396
|
+
if ticklocation == 'auto':
|
|
397
|
+
ticklocation = _get_ticklocation_from_orientation(
|
|
398
|
+
orientation) if location is None else location
|
|
399
|
+
self.ticklocation = ticklocation
|
|
400
|
+
|
|
401
|
+
self.set_label(label)
|
|
402
|
+
self._reset_locator_formatter_scale()
|
|
403
|
+
|
|
404
|
+
if np.iterable(ticks):
|
|
405
|
+
self._locator = ticker.FixedLocator(ticks, nbins=len(ticks))
|
|
406
|
+
else:
|
|
407
|
+
self._locator = ticks
|
|
408
|
+
|
|
409
|
+
if isinstance(format, str):
|
|
410
|
+
# Check format between FormatStrFormatter and StrMethodFormatter
|
|
411
|
+
try:
|
|
412
|
+
self._formatter = ticker.FormatStrFormatter(format)
|
|
413
|
+
_ = self._formatter(0)
|
|
414
|
+
except (TypeError, ValueError):
|
|
415
|
+
self._formatter = ticker.StrMethodFormatter(format)
|
|
416
|
+
else:
|
|
417
|
+
self._formatter = format # Assume it is a Formatter or None
|
|
418
|
+
self._draw_all()
|
|
419
|
+
|
|
420
|
+
if isinstance(mappable, contour.ContourSet) and not mappable.filled:
|
|
421
|
+
self.add_lines(mappable)
|
|
422
|
+
|
|
423
|
+
# Link the Axes and Colorbar for interactive use
|
|
424
|
+
self.ax._colorbar = self
|
|
425
|
+
# Don't navigate on any of these types of mappables
|
|
426
|
+
if (isinstance(self.norm, (colors.BoundaryNorm, colors.NoNorm)) or
|
|
427
|
+
isinstance(self.mappable, contour.ContourSet)):
|
|
428
|
+
self.ax.set_navigate(False)
|
|
429
|
+
|
|
430
|
+
# These are the functions that set up interactivity on this colorbar
|
|
431
|
+
self._interactive_funcs = ["_get_view", "_set_view",
|
|
432
|
+
"_set_view_from_bbox", "drag_pan"]
|
|
433
|
+
for x in self._interactive_funcs:
|
|
434
|
+
setattr(self.ax, x, getattr(self, x))
|
|
435
|
+
# Set the cla function to the cbar's method to override it
|
|
436
|
+
self.ax.cla = self._cbar_cla
|
|
437
|
+
# Callbacks for the extend calculations to handle inverting the axis
|
|
438
|
+
self._extend_cid1 = self.ax.callbacks.connect(
|
|
439
|
+
"xlim_changed", self._do_extends)
|
|
440
|
+
self._extend_cid2 = self.ax.callbacks.connect(
|
|
441
|
+
"ylim_changed", self._do_extends)
|
|
442
|
+
|
|
443
|
+
# Ensure proper cleanup when `cbar.ax.remove()` is called. We ensure
|
|
444
|
+
# this by overriding the Axes' remove method, so that `cbar.ax.remove()`
|
|
445
|
+
# actually calls `cbar.remove()`. In turn, we store the original Axes'
|
|
446
|
+
# remove method in `_ax_remove`, which `cbar.remove()` will eventually
|
|
447
|
+
# call to clean up the Axes itself.
|
|
448
|
+
self._ax_remove = self.ax._remove_method
|
|
449
|
+
self.ax._remove_method = functools.partial(_remove_cbar_axes, cbar=self)
|
|
450
|
+
|
|
451
|
+
@property
|
|
452
|
+
def long_axis(self):
|
|
453
|
+
"""Axis that has decorations (ticks, etc) on it."""
|
|
454
|
+
if self.orientation == 'vertical':
|
|
455
|
+
return self.ax.yaxis
|
|
456
|
+
return self.ax.xaxis
|
|
457
|
+
|
|
458
|
+
@property
|
|
459
|
+
def locator(self):
|
|
460
|
+
"""Major tick `.Locator` for the colorbar."""
|
|
461
|
+
return self.long_axis.get_major_locator()
|
|
462
|
+
|
|
463
|
+
@locator.setter
|
|
464
|
+
def locator(self, loc):
|
|
465
|
+
self.long_axis.set_major_locator(loc)
|
|
466
|
+
self._locator = loc
|
|
467
|
+
|
|
468
|
+
@property
|
|
469
|
+
def minorlocator(self):
|
|
470
|
+
"""Minor tick `.Locator` for the colorbar."""
|
|
471
|
+
return self.long_axis.get_minor_locator()
|
|
472
|
+
|
|
473
|
+
@minorlocator.setter
|
|
474
|
+
def minorlocator(self, loc):
|
|
475
|
+
self.long_axis.set_minor_locator(loc)
|
|
476
|
+
self._minorlocator = loc
|
|
477
|
+
|
|
478
|
+
@property
|
|
479
|
+
def formatter(self):
|
|
480
|
+
"""Major tick label `.Formatter` for the colorbar."""
|
|
481
|
+
return self.long_axis.get_major_formatter()
|
|
482
|
+
|
|
483
|
+
@formatter.setter
|
|
484
|
+
def formatter(self, fmt):
|
|
485
|
+
self.long_axis.set_major_formatter(fmt)
|
|
486
|
+
self._formatter = fmt
|
|
487
|
+
|
|
488
|
+
@property
|
|
489
|
+
def minorformatter(self):
|
|
490
|
+
"""Minor tick `.Formatter` for the colorbar."""
|
|
491
|
+
return self.long_axis.get_minor_formatter()
|
|
492
|
+
|
|
493
|
+
@minorformatter.setter
|
|
494
|
+
def minorformatter(self, fmt):
|
|
495
|
+
self.long_axis.set_minor_formatter(fmt)
|
|
496
|
+
self._minorformatter = fmt
|
|
497
|
+
|
|
498
|
+
def _cbar_cla(self):
|
|
499
|
+
"""Function to clear the interactive colorbar state."""
|
|
500
|
+
for x in self._interactive_funcs:
|
|
501
|
+
delattr(self.ax, x)
|
|
502
|
+
# We now restore the old cla() back and can call it directly
|
|
503
|
+
del self.ax.cla
|
|
504
|
+
self.ax.cla()
|
|
505
|
+
|
|
506
|
+
def update_normal(self, mappable=None):
|
|
507
|
+
"""
|
|
508
|
+
Update solid patches, lines, etc.
|
|
509
|
+
|
|
510
|
+
This is meant to be called when the norm of the image or contour plot
|
|
511
|
+
to which this colorbar belongs changes.
|
|
512
|
+
|
|
513
|
+
If the norm on the mappable is different than before, this resets the
|
|
514
|
+
locator and formatter for the axis, so if these have been customized,
|
|
515
|
+
they will need to be customized again. However, if the norm only
|
|
516
|
+
changes values of *vmin*, *vmax* or *cmap* then the old formatter
|
|
517
|
+
and locator will be preserved.
|
|
518
|
+
"""
|
|
519
|
+
if mappable:
|
|
520
|
+
# The mappable keyword argument exists because
|
|
521
|
+
# ScalarMappable.changed() emits self.callbacks.process('changed', self)
|
|
522
|
+
# in contrast, ColorizingArtist (and Colorizer) does not use this keyword.
|
|
523
|
+
# [ColorizingArtist.changed() emits self.callbacks.process('changed')]
|
|
524
|
+
# Also, there is no test where self.mappable == mappable is not True
|
|
525
|
+
# and possibly no use case.
|
|
526
|
+
# Therefore, the mappable keyword can be deprecated if cm.ScalarMappable
|
|
527
|
+
# is removed.
|
|
528
|
+
self.mappable = mappable
|
|
529
|
+
_log.debug('colorbar update normal %r %r', self.mappable.norm, self.norm)
|
|
530
|
+
self.set_alpha(self.mappable.get_alpha())
|
|
531
|
+
self.cmap = self.mappable.cmap
|
|
532
|
+
if self.mappable.norm != self.norm:
|
|
533
|
+
self.norm = self.mappable.norm
|
|
534
|
+
self._reset_locator_formatter_scale()
|
|
535
|
+
|
|
536
|
+
self._draw_all()
|
|
537
|
+
if isinstance(self.mappable, contour.ContourSet):
|
|
538
|
+
CS = self.mappable
|
|
539
|
+
if not CS.filled:
|
|
540
|
+
self.add_lines(CS)
|
|
541
|
+
self.stale = True
|
|
542
|
+
|
|
543
|
+
def _draw_all(self):
|
|
544
|
+
"""
|
|
545
|
+
Calculate any free parameters based on the current cmap and norm,
|
|
546
|
+
and do all the drawing.
|
|
547
|
+
"""
|
|
548
|
+
if self.orientation == 'vertical':
|
|
549
|
+
if mpl.rcParams['ytick.minor.visible']:
|
|
550
|
+
self.minorticks_on()
|
|
551
|
+
else:
|
|
552
|
+
if mpl.rcParams['xtick.minor.visible']:
|
|
553
|
+
self.minorticks_on()
|
|
554
|
+
self.long_axis.set(label_position=self.ticklocation,
|
|
555
|
+
ticks_position=self.ticklocation)
|
|
556
|
+
self._short_axis().set_ticks([])
|
|
557
|
+
self._short_axis().set_ticks([], minor=True)
|
|
558
|
+
|
|
559
|
+
# Set self._boundaries and self._values, including extensions.
|
|
560
|
+
# self._boundaries are the edges of each square of color, and
|
|
561
|
+
# self._values are the value to map into the norm to get the
|
|
562
|
+
# color:
|
|
563
|
+
self._process_values()
|
|
564
|
+
# Set self.vmin and self.vmax to first and last boundary, excluding
|
|
565
|
+
# extensions:
|
|
566
|
+
self.vmin, self.vmax = self._boundaries[self._inside][[0, -1]]
|
|
567
|
+
# Compute the X/Y mesh.
|
|
568
|
+
X, Y = self._mesh()
|
|
569
|
+
# draw the extend triangles, and shrink the inner Axes to accommodate.
|
|
570
|
+
# also adds the outline path to self.outline spine:
|
|
571
|
+
self._do_extends()
|
|
572
|
+
lower, upper = self.vmin, self.vmax
|
|
573
|
+
if self.long_axis.get_inverted():
|
|
574
|
+
# If the axis is inverted, we need to swap the vmin/vmax
|
|
575
|
+
lower, upper = upper, lower
|
|
576
|
+
if self.orientation == 'vertical':
|
|
577
|
+
self.ax.set_xlim(0, 1)
|
|
578
|
+
self.ax.set_ylim(lower, upper)
|
|
579
|
+
else:
|
|
580
|
+
self.ax.set_ylim(0, 1)
|
|
581
|
+
self.ax.set_xlim(lower, upper)
|
|
582
|
+
|
|
583
|
+
# set up the tick locators and formatters. A bit complicated because
|
|
584
|
+
# boundary norms + uniform spacing requires a manual locator.
|
|
585
|
+
self.update_ticks()
|
|
586
|
+
|
|
587
|
+
if self._filled:
|
|
588
|
+
ind = np.arange(len(self._values))
|
|
589
|
+
if self._extend_lower():
|
|
590
|
+
ind = ind[1:]
|
|
591
|
+
if self._extend_upper():
|
|
592
|
+
ind = ind[:-1]
|
|
593
|
+
self._add_solids(X, Y, self._values[ind, np.newaxis])
|
|
594
|
+
|
|
595
|
+
def _add_solids(self, X, Y, C):
|
|
596
|
+
"""Draw the colors; optionally add separators."""
|
|
597
|
+
# Cleanup previously set artists.
|
|
598
|
+
if self.solids is not None:
|
|
599
|
+
self.solids.remove()
|
|
600
|
+
for solid in self.solids_patches:
|
|
601
|
+
solid.remove()
|
|
602
|
+
# Add new artist(s), based on mappable type. Use individual patches if
|
|
603
|
+
# hatching is needed, pcolormesh otherwise.
|
|
604
|
+
mappable = getattr(self, 'mappable', None)
|
|
605
|
+
if (isinstance(mappable, contour.ContourSet)
|
|
606
|
+
and any(hatch is not None for hatch in mappable.hatches)):
|
|
607
|
+
self._add_solids_patches(X, Y, C, mappable)
|
|
608
|
+
else:
|
|
609
|
+
self.solids = self.ax.pcolormesh(
|
|
610
|
+
X, Y, C, cmap=self.cmap, norm=self.norm, alpha=self.alpha,
|
|
611
|
+
edgecolors='none', shading='flat')
|
|
612
|
+
if not self.drawedges:
|
|
613
|
+
if len(self._y) >= self.n_rasterize:
|
|
614
|
+
self.solids.set_rasterized(True)
|
|
615
|
+
self._update_dividers()
|
|
616
|
+
|
|
617
|
+
def _update_dividers(self):
|
|
618
|
+
if not self.drawedges:
|
|
619
|
+
self.dividers.set_segments([])
|
|
620
|
+
return
|
|
621
|
+
# Place all *internal* dividers.
|
|
622
|
+
if self.orientation == 'vertical':
|
|
623
|
+
lims = self.ax.get_ylim()
|
|
624
|
+
bounds = (lims[0] < self._y) & (self._y < lims[1])
|
|
625
|
+
else:
|
|
626
|
+
lims = self.ax.get_xlim()
|
|
627
|
+
bounds = (lims[0] < self._y) & (self._y < lims[1])
|
|
628
|
+
y = self._y[bounds]
|
|
629
|
+
# And then add outer dividers if extensions are on.
|
|
630
|
+
if self._extend_lower():
|
|
631
|
+
y = np.insert(y, 0, lims[0])
|
|
632
|
+
if self._extend_upper():
|
|
633
|
+
y = np.append(y, lims[1])
|
|
634
|
+
X, Y = np.meshgrid([0, 1], y)
|
|
635
|
+
if self.orientation == 'vertical':
|
|
636
|
+
segments = np.dstack([X, Y])
|
|
637
|
+
else:
|
|
638
|
+
segments = np.dstack([Y, X])
|
|
639
|
+
self.dividers.set_segments(segments)
|
|
640
|
+
|
|
641
|
+
def _add_solids_patches(self, X, Y, C, mappable):
|
|
642
|
+
hatches = mappable.hatches * (len(C) + 1) # Have enough hatches.
|
|
643
|
+
if self._extend_lower():
|
|
644
|
+
# remove first hatch that goes into the extend patch
|
|
645
|
+
hatches = hatches[1:]
|
|
646
|
+
patches = []
|
|
647
|
+
for i in range(len(X) - 1):
|
|
648
|
+
xy = np.array([[X[i, 0], Y[i, 1]],
|
|
649
|
+
[X[i, 1], Y[i, 0]],
|
|
650
|
+
[X[i + 1, 1], Y[i + 1, 0]],
|
|
651
|
+
[X[i + 1, 0], Y[i + 1, 1]]])
|
|
652
|
+
patch = mpatches.PathPatch(mpath.Path(xy),
|
|
653
|
+
facecolor=self.cmap(self.norm(C[i][0])),
|
|
654
|
+
hatch=hatches[i], linewidth=0,
|
|
655
|
+
antialiased=False, alpha=self.alpha)
|
|
656
|
+
self.ax.add_patch(patch)
|
|
657
|
+
patches.append(patch)
|
|
658
|
+
self.solids_patches = patches
|
|
659
|
+
|
|
660
|
+
def _do_extends(self, ax=None):
|
|
661
|
+
"""
|
|
662
|
+
Add the extend tri/rectangles on the outside of the Axes.
|
|
663
|
+
|
|
664
|
+
ax is unused, but required due to the callbacks on xlim/ylim changed
|
|
665
|
+
"""
|
|
666
|
+
# Clean up any previous extend patches
|
|
667
|
+
for patch in self._extend_patches:
|
|
668
|
+
patch.remove()
|
|
669
|
+
self._extend_patches = []
|
|
670
|
+
# extend lengths are fraction of the *inner* part of colorbar,
|
|
671
|
+
# not the total colorbar:
|
|
672
|
+
_, extendlen = self._proportional_y()
|
|
673
|
+
bot = 0 - (extendlen[0] if self._extend_lower() else 0)
|
|
674
|
+
top = 1 + (extendlen[1] if self._extend_upper() else 0)
|
|
675
|
+
|
|
676
|
+
# xyout is the outline of the colorbar including the extend patches:
|
|
677
|
+
if not self.extendrect:
|
|
678
|
+
# triangle:
|
|
679
|
+
xyout = np.array([[0, 0], [0.5, bot], [1, 0],
|
|
680
|
+
[1, 1], [0.5, top], [0, 1], [0, 0]])
|
|
681
|
+
else:
|
|
682
|
+
# rectangle:
|
|
683
|
+
xyout = np.array([[0, 0], [0, bot], [1, bot], [1, 0],
|
|
684
|
+
[1, 1], [1, top], [0, top], [0, 1],
|
|
685
|
+
[0, 0]])
|
|
686
|
+
|
|
687
|
+
if self.orientation == 'horizontal':
|
|
688
|
+
xyout = xyout[:, ::-1]
|
|
689
|
+
|
|
690
|
+
# xyout is the path for the spine:
|
|
691
|
+
self.outline.set_xy(xyout)
|
|
692
|
+
if not self._filled:
|
|
693
|
+
return
|
|
694
|
+
|
|
695
|
+
# Make extend triangles or rectangles filled patches. These are
|
|
696
|
+
# defined in the outer parent axes' coordinates:
|
|
697
|
+
mappable = getattr(self, 'mappable', None)
|
|
698
|
+
if (isinstance(mappable, contour.ContourSet)
|
|
699
|
+
and any(hatch is not None for hatch in mappable.hatches)):
|
|
700
|
+
hatches = mappable.hatches * (len(self._y) + 1)
|
|
701
|
+
else:
|
|
702
|
+
hatches = [None] * (len(self._y) + 1)
|
|
703
|
+
|
|
704
|
+
if self._extend_lower():
|
|
705
|
+
if not self.extendrect:
|
|
706
|
+
# triangle
|
|
707
|
+
xy = np.array([[0, 0], [0.5, bot], [1, 0]])
|
|
708
|
+
else:
|
|
709
|
+
# rectangle
|
|
710
|
+
xy = np.array([[0, 0], [0, bot], [1., bot], [1, 0]])
|
|
711
|
+
if self.orientation == 'horizontal':
|
|
712
|
+
xy = xy[:, ::-1]
|
|
713
|
+
# add the patch
|
|
714
|
+
val = -1 if self.long_axis.get_inverted() else 0
|
|
715
|
+
color = self.cmap(self.norm(self._values[val]))
|
|
716
|
+
patch = mpatches.PathPatch(
|
|
717
|
+
mpath.Path(xy), facecolor=color, alpha=self.alpha,
|
|
718
|
+
linewidth=0, antialiased=False,
|
|
719
|
+
transform=self.ax.transAxes,
|
|
720
|
+
hatch=hatches[0], clip_on=False,
|
|
721
|
+
# Place it right behind the standard patches, which is
|
|
722
|
+
# needed if we updated the extends
|
|
723
|
+
zorder=np.nextafter(self.ax.patch.zorder, -np.inf))
|
|
724
|
+
self.ax.add_patch(patch)
|
|
725
|
+
self._extend_patches.append(patch)
|
|
726
|
+
# remove first hatch that goes into the extend patch
|
|
727
|
+
hatches = hatches[1:]
|
|
728
|
+
if self._extend_upper():
|
|
729
|
+
if not self.extendrect:
|
|
730
|
+
# triangle
|
|
731
|
+
xy = np.array([[0, 1], [0.5, top], [1, 1]])
|
|
732
|
+
else:
|
|
733
|
+
# rectangle
|
|
734
|
+
xy = np.array([[0, 1], [0, top], [1, top], [1, 1]])
|
|
735
|
+
if self.orientation == 'horizontal':
|
|
736
|
+
xy = xy[:, ::-1]
|
|
737
|
+
# add the patch
|
|
738
|
+
val = 0 if self.long_axis.get_inverted() else -1
|
|
739
|
+
color = self.cmap(self.norm(self._values[val]))
|
|
740
|
+
hatch_idx = len(self._y) - 1
|
|
741
|
+
patch = mpatches.PathPatch(
|
|
742
|
+
mpath.Path(xy), facecolor=color, alpha=self.alpha,
|
|
743
|
+
linewidth=0, antialiased=False,
|
|
744
|
+
transform=self.ax.transAxes, hatch=hatches[hatch_idx],
|
|
745
|
+
clip_on=False,
|
|
746
|
+
# Place it right behind the standard patches, which is
|
|
747
|
+
# needed if we updated the extends
|
|
748
|
+
zorder=np.nextafter(self.ax.patch.zorder, -np.inf))
|
|
749
|
+
self.ax.add_patch(patch)
|
|
750
|
+
self._extend_patches.append(patch)
|
|
751
|
+
|
|
752
|
+
self._update_dividers()
|
|
753
|
+
|
|
754
|
+
def add_lines(self, *args, **kwargs):
|
|
755
|
+
"""
|
|
756
|
+
Draw lines on the colorbar.
|
|
757
|
+
|
|
758
|
+
The lines are appended to the list :attr:`!lines`.
|
|
759
|
+
|
|
760
|
+
Parameters
|
|
761
|
+
----------
|
|
762
|
+
levels : array-like
|
|
763
|
+
The positions of the lines.
|
|
764
|
+
colors : :mpltype:`color` or list of :mpltype:`color`
|
|
765
|
+
Either a single color applying to all lines or one color value for
|
|
766
|
+
each line.
|
|
767
|
+
linewidths : float or array-like
|
|
768
|
+
Either a single linewidth applying to all lines or one linewidth
|
|
769
|
+
for each line.
|
|
770
|
+
erase : bool, default: True
|
|
771
|
+
Whether to remove any previously added lines.
|
|
772
|
+
|
|
773
|
+
Notes
|
|
774
|
+
-----
|
|
775
|
+
Alternatively, this method can also be called with the signature
|
|
776
|
+
``colorbar.add_lines(contour_set, erase=True)``, in which case
|
|
777
|
+
*levels*, *colors*, and *linewidths* are taken from *contour_set*.
|
|
778
|
+
"""
|
|
779
|
+
params = _api.select_matching_signature(
|
|
780
|
+
[lambda self, CS, erase=True: locals(),
|
|
781
|
+
lambda self, levels, colors, linewidths, erase=True: locals()],
|
|
782
|
+
self, *args, **kwargs)
|
|
783
|
+
if "CS" in params:
|
|
784
|
+
self, cs, erase = params.values()
|
|
785
|
+
if not isinstance(cs, contour.ContourSet) or cs.filled:
|
|
786
|
+
raise ValueError("If a single artist is passed to add_lines, "
|
|
787
|
+
"it must be a ContourSet of lines")
|
|
788
|
+
# TODO: Make colorbar lines auto-follow changes in contour lines.
|
|
789
|
+
return self.add_lines(
|
|
790
|
+
cs.levels,
|
|
791
|
+
cs.to_rgba(cs.cvalues, cs.alpha),
|
|
792
|
+
cs.get_linewidths(),
|
|
793
|
+
erase=erase)
|
|
794
|
+
else:
|
|
795
|
+
self, levels, colors, linewidths, erase = params.values()
|
|
796
|
+
|
|
797
|
+
y = self._locate(levels)
|
|
798
|
+
rtol = (self._y[-1] - self._y[0]) * 1e-10
|
|
799
|
+
igood = (y < self._y[-1] + rtol) & (y > self._y[0] - rtol)
|
|
800
|
+
y = y[igood]
|
|
801
|
+
if np.iterable(colors):
|
|
802
|
+
colors = np.asarray(colors)[igood]
|
|
803
|
+
if np.iterable(linewidths):
|
|
804
|
+
linewidths = np.asarray(linewidths)[igood]
|
|
805
|
+
X, Y = np.meshgrid([0, 1], y)
|
|
806
|
+
if self.orientation == 'vertical':
|
|
807
|
+
xy = np.stack([X, Y], axis=-1)
|
|
808
|
+
else:
|
|
809
|
+
xy = np.stack([Y, X], axis=-1)
|
|
810
|
+
col = collections.LineCollection(xy, linewidths=linewidths,
|
|
811
|
+
colors=colors)
|
|
812
|
+
|
|
813
|
+
if erase and self.lines:
|
|
814
|
+
for lc in self.lines:
|
|
815
|
+
lc.remove()
|
|
816
|
+
self.lines = []
|
|
817
|
+
self.lines.append(col)
|
|
818
|
+
|
|
819
|
+
# make a clip path that is just a linewidth bigger than the Axes...
|
|
820
|
+
fac = np.max(linewidths) / 72
|
|
821
|
+
xy = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
|
|
822
|
+
inches = self.ax.get_figure().dpi_scale_trans
|
|
823
|
+
# do in inches:
|
|
824
|
+
xy = inches.inverted().transform(self.ax.transAxes.transform(xy))
|
|
825
|
+
xy[[0, 1, 4], 1] -= fac
|
|
826
|
+
xy[[2, 3], 1] += fac
|
|
827
|
+
# back to axes units...
|
|
828
|
+
xy = self.ax.transAxes.inverted().transform(inches.transform(xy))
|
|
829
|
+
col.set_clip_path(mpath.Path(xy, closed=True),
|
|
830
|
+
self.ax.transAxes)
|
|
831
|
+
self.ax.add_collection(col, autolim=False)
|
|
832
|
+
self.stale = True
|
|
833
|
+
|
|
834
|
+
def update_ticks(self):
|
|
835
|
+
"""
|
|
836
|
+
Set up the ticks and ticklabels. This should not be needed by users.
|
|
837
|
+
"""
|
|
838
|
+
# Get the locator and formatter; defaults to self._locator if not None.
|
|
839
|
+
self._get_ticker_locator_formatter()
|
|
840
|
+
self.long_axis.set_major_locator(self._locator)
|
|
841
|
+
self.long_axis.set_minor_locator(self._minorlocator)
|
|
842
|
+
self.long_axis.set_major_formatter(self._formatter)
|
|
843
|
+
|
|
844
|
+
def _get_ticker_locator_formatter(self):
|
|
845
|
+
"""
|
|
846
|
+
Return the ``locator`` and ``formatter`` of the colorbar.
|
|
847
|
+
|
|
848
|
+
If they have not been defined (i.e. are *None*), the formatter and
|
|
849
|
+
locator are retrieved from the axis, or from the value of the
|
|
850
|
+
boundaries for a boundary norm.
|
|
851
|
+
|
|
852
|
+
Called by update_ticks...
|
|
853
|
+
"""
|
|
854
|
+
locator = self._locator
|
|
855
|
+
formatter = self._formatter
|
|
856
|
+
minorlocator = self._minorlocator
|
|
857
|
+
if isinstance(self.norm, colors.BoundaryNorm):
|
|
858
|
+
b = self.norm.boundaries
|
|
859
|
+
if locator is None:
|
|
860
|
+
locator = ticker.FixedLocator(b, nbins=10)
|
|
861
|
+
if minorlocator is None:
|
|
862
|
+
minorlocator = ticker.FixedLocator(b)
|
|
863
|
+
elif isinstance(self.norm, colors.NoNorm):
|
|
864
|
+
if locator is None:
|
|
865
|
+
# put ticks on integers between the boundaries of NoNorm
|
|
866
|
+
nv = len(self._values)
|
|
867
|
+
base = 1 + int(nv / 10)
|
|
868
|
+
locator = ticker.IndexLocator(base=base, offset=.5)
|
|
869
|
+
elif self.boundaries is not None:
|
|
870
|
+
b = self._boundaries[self._inside]
|
|
871
|
+
if locator is None:
|
|
872
|
+
locator = ticker.FixedLocator(b, nbins=10)
|
|
873
|
+
else: # most cases:
|
|
874
|
+
if locator is None:
|
|
875
|
+
# we haven't set the locator explicitly, so use the default
|
|
876
|
+
# for this axis:
|
|
877
|
+
locator = self.long_axis.get_major_locator()
|
|
878
|
+
if minorlocator is None:
|
|
879
|
+
minorlocator = self.long_axis.get_minor_locator()
|
|
880
|
+
|
|
881
|
+
if minorlocator is None:
|
|
882
|
+
minorlocator = ticker.NullLocator()
|
|
883
|
+
|
|
884
|
+
if formatter is None:
|
|
885
|
+
formatter = self.long_axis.get_major_formatter()
|
|
886
|
+
|
|
887
|
+
self._locator = locator
|
|
888
|
+
self._formatter = formatter
|
|
889
|
+
self._minorlocator = minorlocator
|
|
890
|
+
_log.debug('locator: %r', locator)
|
|
891
|
+
|
|
892
|
+
def set_ticks(self, ticks, *, labels=None, minor=False, **kwargs):
|
|
893
|
+
"""
|
|
894
|
+
Set tick locations.
|
|
895
|
+
|
|
896
|
+
Parameters
|
|
897
|
+
----------
|
|
898
|
+
ticks : 1D array-like
|
|
899
|
+
List of tick locations.
|
|
900
|
+
labels : list of str, optional
|
|
901
|
+
List of tick labels. If not set, the labels show the data value.
|
|
902
|
+
minor : bool, default: False
|
|
903
|
+
If ``False``, set the major ticks; if ``True``, the minor ticks.
|
|
904
|
+
**kwargs
|
|
905
|
+
`.Text` properties for the labels. These take effect only if you
|
|
906
|
+
pass *labels*. In other cases, please use `~.Axes.tick_params`.
|
|
907
|
+
"""
|
|
908
|
+
if np.iterable(ticks):
|
|
909
|
+
self.long_axis.set_ticks(ticks, labels=labels, minor=minor,
|
|
910
|
+
**kwargs)
|
|
911
|
+
self._locator = self.long_axis.get_major_locator()
|
|
912
|
+
else:
|
|
913
|
+
self._locator = ticks
|
|
914
|
+
self.long_axis.set_major_locator(self._locator)
|
|
915
|
+
self.stale = True
|
|
916
|
+
|
|
917
|
+
def get_ticks(self, minor=False):
|
|
918
|
+
"""
|
|
919
|
+
Return the ticks as a list of locations.
|
|
920
|
+
|
|
921
|
+
Parameters
|
|
922
|
+
----------
|
|
923
|
+
minor : boolean, default: False
|
|
924
|
+
if True return the minor ticks.
|
|
925
|
+
"""
|
|
926
|
+
if minor:
|
|
927
|
+
return self.long_axis.get_minorticklocs()
|
|
928
|
+
else:
|
|
929
|
+
return self.long_axis.get_majorticklocs()
|
|
930
|
+
|
|
931
|
+
def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
|
|
932
|
+
"""
|
|
933
|
+
[*Discouraged*] Set tick labels.
|
|
934
|
+
|
|
935
|
+
.. admonition:: Discouraged
|
|
936
|
+
|
|
937
|
+
The use of this method is discouraged, because of the dependency
|
|
938
|
+
on tick positions. In most cases, you'll want to use
|
|
939
|
+
``set_ticks(positions, labels=labels)`` instead.
|
|
940
|
+
|
|
941
|
+
If you are using this method, you should always fix the tick
|
|
942
|
+
positions before, e.g. by using `.Colorbar.set_ticks` or by
|
|
943
|
+
explicitly setting a `~.ticker.FixedLocator` on the long axis
|
|
944
|
+
of the colorbar. Otherwise, ticks are free to move and the
|
|
945
|
+
labels may end up in unexpected positions.
|
|
946
|
+
|
|
947
|
+
Parameters
|
|
948
|
+
----------
|
|
949
|
+
ticklabels : sequence of str or of `.Text`
|
|
950
|
+
Texts for labeling each tick location in the sequence set by
|
|
951
|
+
`.Colorbar.set_ticks`; the number of labels must match the number
|
|
952
|
+
of locations.
|
|
953
|
+
|
|
954
|
+
update_ticks : bool, default: True
|
|
955
|
+
This keyword argument is ignored and will be removed.
|
|
956
|
+
Deprecated
|
|
957
|
+
|
|
958
|
+
minor : bool
|
|
959
|
+
If True, set minor ticks instead of major ticks.
|
|
960
|
+
|
|
961
|
+
**kwargs
|
|
962
|
+
`.Text` properties for the labels.
|
|
963
|
+
"""
|
|
964
|
+
self.long_axis.set_ticklabels(ticklabels, minor=minor, **kwargs)
|
|
965
|
+
|
|
966
|
+
def minorticks_on(self):
|
|
967
|
+
"""
|
|
968
|
+
Turn on colorbar minor ticks.
|
|
969
|
+
"""
|
|
970
|
+
self.ax.minorticks_on()
|
|
971
|
+
self._short_axis().set_minor_locator(ticker.NullLocator())
|
|
972
|
+
|
|
973
|
+
def minorticks_off(self):
|
|
974
|
+
"""Turn the minor ticks of the colorbar off."""
|
|
975
|
+
self._minorlocator = ticker.NullLocator()
|
|
976
|
+
self.long_axis.set_minor_locator(self._minorlocator)
|
|
977
|
+
|
|
978
|
+
def set_label(self, label, *, loc=None, **kwargs):
|
|
979
|
+
"""
|
|
980
|
+
Add a label to the long axis of the colorbar.
|
|
981
|
+
|
|
982
|
+
Parameters
|
|
983
|
+
----------
|
|
984
|
+
label : str
|
|
985
|
+
The label text.
|
|
986
|
+
loc : str, optional
|
|
987
|
+
The location of the label.
|
|
988
|
+
|
|
989
|
+
- For horizontal orientation one of {'left', 'center', 'right'}
|
|
990
|
+
- For vertical orientation one of {'bottom', 'center', 'top'}
|
|
991
|
+
|
|
992
|
+
Defaults to :rc:`xaxis.labellocation` or :rc:`yaxis.labellocation`
|
|
993
|
+
depending on the orientation.
|
|
994
|
+
**kwargs
|
|
995
|
+
Keyword arguments are passed to `~.Axes.set_xlabel` /
|
|
996
|
+
`~.Axes.set_ylabel`.
|
|
997
|
+
Supported keywords are *labelpad* and `.Text` properties.
|
|
998
|
+
"""
|
|
999
|
+
if self.orientation == "vertical":
|
|
1000
|
+
self.ax.set_ylabel(label, loc=loc, **kwargs)
|
|
1001
|
+
else:
|
|
1002
|
+
self.ax.set_xlabel(label, loc=loc, **kwargs)
|
|
1003
|
+
self.stale = True
|
|
1004
|
+
|
|
1005
|
+
def set_alpha(self, alpha):
|
|
1006
|
+
"""
|
|
1007
|
+
Set the transparency between 0 (transparent) and 1 (opaque).
|
|
1008
|
+
|
|
1009
|
+
If an array is provided, *alpha* will be set to None to use the
|
|
1010
|
+
transparency values associated with the colormap.
|
|
1011
|
+
"""
|
|
1012
|
+
self.alpha = None if isinstance(alpha, np.ndarray) else alpha
|
|
1013
|
+
|
|
1014
|
+
def _set_scale(self, scale, **kwargs):
|
|
1015
|
+
"""
|
|
1016
|
+
Set the colorbar long axis scale.
|
|
1017
|
+
|
|
1018
|
+
Parameters
|
|
1019
|
+
----------
|
|
1020
|
+
scale : {"linear", "log", "symlog", "logit", ...} or `.ScaleBase`
|
|
1021
|
+
The axis scale type to apply.
|
|
1022
|
+
|
|
1023
|
+
**kwargs
|
|
1024
|
+
Different keyword arguments are accepted, depending on the scale.
|
|
1025
|
+
See the respective class keyword arguments:
|
|
1026
|
+
|
|
1027
|
+
- `matplotlib.scale.LinearScale`
|
|
1028
|
+
- `matplotlib.scale.LogScale`
|
|
1029
|
+
- `matplotlib.scale.SymmetricalLogScale`
|
|
1030
|
+
- `matplotlib.scale.LogitScale`
|
|
1031
|
+
- `matplotlib.scale.FuncScale`
|
|
1032
|
+
- `matplotlib.scale.AsinhScale`
|
|
1033
|
+
|
|
1034
|
+
Notes
|
|
1035
|
+
-----
|
|
1036
|
+
By default, Matplotlib supports the above-mentioned scales.
|
|
1037
|
+
Additionally, custom scales may be registered using
|
|
1038
|
+
`matplotlib.scale.register_scale`. These scales can then also
|
|
1039
|
+
be used here.
|
|
1040
|
+
"""
|
|
1041
|
+
self.long_axis._set_axes_scale(scale, **kwargs)
|
|
1042
|
+
|
|
1043
|
+
def remove(self):
|
|
1044
|
+
"""
|
|
1045
|
+
Remove this colorbar from the figure.
|
|
1046
|
+
|
|
1047
|
+
If the colorbar was created with ``use_gridspec=True`` the previous
|
|
1048
|
+
gridspec is restored.
|
|
1049
|
+
"""
|
|
1050
|
+
if hasattr(self.ax, '_colorbar_info'):
|
|
1051
|
+
parents = self.ax._colorbar_info['parents']
|
|
1052
|
+
for a in parents:
|
|
1053
|
+
if self.ax in a._colorbars:
|
|
1054
|
+
a._colorbars.remove(self.ax)
|
|
1055
|
+
|
|
1056
|
+
self._ax_remove(self.ax)
|
|
1057
|
+
|
|
1058
|
+
self.mappable.callbacks.disconnect(self.mappable.colorbar_cid)
|
|
1059
|
+
self.mappable.colorbar = None
|
|
1060
|
+
self.mappable.colorbar_cid = None
|
|
1061
|
+
# Remove the extension callbacks
|
|
1062
|
+
self.ax.callbacks.disconnect(self._extend_cid1)
|
|
1063
|
+
self.ax.callbacks.disconnect(self._extend_cid2)
|
|
1064
|
+
|
|
1065
|
+
try:
|
|
1066
|
+
ax = self.mappable.axes
|
|
1067
|
+
except AttributeError:
|
|
1068
|
+
return
|
|
1069
|
+
try:
|
|
1070
|
+
subplotspec = self.ax.get_subplotspec().get_gridspec()._subplot_spec
|
|
1071
|
+
except AttributeError: # use_gridspec was False
|
|
1072
|
+
pos = ax.get_position(original=True)
|
|
1073
|
+
ax._set_position(pos)
|
|
1074
|
+
else: # use_gridspec was True
|
|
1075
|
+
ax.set_subplotspec(subplotspec)
|
|
1076
|
+
|
|
1077
|
+
def _process_values(self):
|
|
1078
|
+
"""
|
|
1079
|
+
Set `_boundaries` and `_values` based on the self.boundaries and
|
|
1080
|
+
self.values if not None, or based on the size of the colormap and
|
|
1081
|
+
the vmin/vmax of the norm.
|
|
1082
|
+
"""
|
|
1083
|
+
if self.values is not None:
|
|
1084
|
+
# set self._boundaries from the values...
|
|
1085
|
+
self._values = np.array(self.values)
|
|
1086
|
+
if self.boundaries is None:
|
|
1087
|
+
# bracket values by 1/2 dv:
|
|
1088
|
+
b = np.zeros(len(self.values) + 1)
|
|
1089
|
+
b[1:-1] = 0.5 * (self._values[:-1] + self._values[1:])
|
|
1090
|
+
b[0] = 2.0 * b[1] - b[2]
|
|
1091
|
+
b[-1] = 2.0 * b[-2] - b[-3]
|
|
1092
|
+
self._boundaries = b
|
|
1093
|
+
return
|
|
1094
|
+
self._boundaries = np.array(self.boundaries)
|
|
1095
|
+
return
|
|
1096
|
+
|
|
1097
|
+
# otherwise values are set from the boundaries
|
|
1098
|
+
if isinstance(self.norm, colors.BoundaryNorm):
|
|
1099
|
+
b = self.norm.boundaries
|
|
1100
|
+
elif isinstance(self.norm, colors.NoNorm):
|
|
1101
|
+
# NoNorm has N blocks, so N+1 boundaries, centered on integers:
|
|
1102
|
+
b = np.arange(self.cmap.N + 1) - .5
|
|
1103
|
+
elif self.boundaries is not None:
|
|
1104
|
+
b = self.boundaries
|
|
1105
|
+
else:
|
|
1106
|
+
# otherwise make the boundaries from the size of the cmap:
|
|
1107
|
+
N = self.cmap.N + 1
|
|
1108
|
+
b, _ = self._uniform_y(N)
|
|
1109
|
+
# add extra boundaries if needed:
|
|
1110
|
+
if self._extend_lower():
|
|
1111
|
+
b = np.hstack((b[0] - 1, b))
|
|
1112
|
+
if self._extend_upper():
|
|
1113
|
+
b = np.hstack((b, b[-1] + 1))
|
|
1114
|
+
|
|
1115
|
+
# transform from 0-1 to vmin-vmax:
|
|
1116
|
+
if self.mappable.get_array() is not None:
|
|
1117
|
+
self.mappable.autoscale_None()
|
|
1118
|
+
if not self.norm.scaled():
|
|
1119
|
+
# If we still aren't scaled after autoscaling, use 0, 1 as default
|
|
1120
|
+
self.norm.vmin = 0
|
|
1121
|
+
self.norm.vmax = 1
|
|
1122
|
+
self.norm.vmin, self.norm.vmax = mtransforms._nonsingular(
|
|
1123
|
+
self.norm.vmin, self.norm.vmax, expander=0.1)
|
|
1124
|
+
if (not isinstance(self.norm, colors.BoundaryNorm) and
|
|
1125
|
+
(self.boundaries is None)):
|
|
1126
|
+
b = self.norm.inverse(b)
|
|
1127
|
+
|
|
1128
|
+
self._boundaries = np.asarray(b, dtype=float)
|
|
1129
|
+
self._values = 0.5 * (self._boundaries[:-1] + self._boundaries[1:])
|
|
1130
|
+
if isinstance(self.norm, colors.NoNorm):
|
|
1131
|
+
self._values = (self._values + 0.00001).astype(np.int16)
|
|
1132
|
+
|
|
1133
|
+
def _mesh(self):
|
|
1134
|
+
"""
|
|
1135
|
+
Return the coordinate arrays for the colorbar pcolormesh/patches.
|
|
1136
|
+
|
|
1137
|
+
These are scaled between vmin and vmax, and already handle colorbar
|
|
1138
|
+
orientation.
|
|
1139
|
+
"""
|
|
1140
|
+
y, _ = self._proportional_y()
|
|
1141
|
+
# Use the vmin and vmax of the colorbar, which may not be the same
|
|
1142
|
+
# as the norm. There are situations where the colormap has a
|
|
1143
|
+
# narrower range than the colorbar and we want to accommodate the
|
|
1144
|
+
# extra contours.
|
|
1145
|
+
if (isinstance(self.norm, (colors.BoundaryNorm, colors.NoNorm))
|
|
1146
|
+
or self.boundaries is not None):
|
|
1147
|
+
# not using a norm.
|
|
1148
|
+
y = y * (self.vmax - self.vmin) + self.vmin
|
|
1149
|
+
else:
|
|
1150
|
+
# Update the norm values in a context manager as it is only
|
|
1151
|
+
# a temporary change and we don't want to propagate any signals
|
|
1152
|
+
# attached to the norm (callbacks.blocked).
|
|
1153
|
+
with (self.norm.callbacks.blocked(),
|
|
1154
|
+
cbook._setattr_cm(self.norm, vmin=self.vmin, vmax=self.vmax)):
|
|
1155
|
+
y = self.norm.inverse(y)
|
|
1156
|
+
self._y = y
|
|
1157
|
+
X, Y = np.meshgrid([0., 1.], y)
|
|
1158
|
+
if self.orientation == 'vertical':
|
|
1159
|
+
return (X, Y)
|
|
1160
|
+
else:
|
|
1161
|
+
return (Y, X)
|
|
1162
|
+
|
|
1163
|
+
def _forward_boundaries(self, x):
|
|
1164
|
+
# map boundaries equally between 0 and 1...
|
|
1165
|
+
b = self._boundaries
|
|
1166
|
+
y = np.interp(x, b, np.linspace(0, 1, len(b)))
|
|
1167
|
+
# the following avoids ticks in the extends:
|
|
1168
|
+
eps = (b[-1] - b[0]) * 1e-6
|
|
1169
|
+
# map these _well_ out of bounds to keep any ticks out
|
|
1170
|
+
# of the extends region...
|
|
1171
|
+
y[x < b[0]-eps] = -1
|
|
1172
|
+
y[x > b[-1]+eps] = 2
|
|
1173
|
+
return y
|
|
1174
|
+
|
|
1175
|
+
def _inverse_boundaries(self, x):
|
|
1176
|
+
# invert the above...
|
|
1177
|
+
b = self._boundaries
|
|
1178
|
+
return np.interp(x, np.linspace(0, 1, len(b)), b)
|
|
1179
|
+
|
|
1180
|
+
def _reset_locator_formatter_scale(self):
|
|
1181
|
+
"""
|
|
1182
|
+
Reset the locator et al to defaults. Any user-hardcoded changes
|
|
1183
|
+
need to be re-entered if this gets called (either at init, or when
|
|
1184
|
+
the mappable normal gets changed: Colorbar.update_normal)
|
|
1185
|
+
"""
|
|
1186
|
+
self._process_values()
|
|
1187
|
+
self._locator = None
|
|
1188
|
+
self._minorlocator = None
|
|
1189
|
+
self._formatter = None
|
|
1190
|
+
self._minorformatter = None
|
|
1191
|
+
if (isinstance(self.mappable, contour.ContourSet) and
|
|
1192
|
+
isinstance(self.norm, colors.LogNorm)):
|
|
1193
|
+
# if contours have lognorm, give them a log scale...
|
|
1194
|
+
self._set_scale('log')
|
|
1195
|
+
elif (self.boundaries is not None or
|
|
1196
|
+
isinstance(self.norm, colors.BoundaryNorm)):
|
|
1197
|
+
if self.spacing == 'uniform':
|
|
1198
|
+
funcs = (self._forward_boundaries, self._inverse_boundaries)
|
|
1199
|
+
self._set_scale('function', functions=funcs)
|
|
1200
|
+
elif self.spacing == 'proportional':
|
|
1201
|
+
self._set_scale('linear')
|
|
1202
|
+
elif getattr(self.norm, '_scale', None):
|
|
1203
|
+
# use the norm's scale (if it exists and is not None):
|
|
1204
|
+
self._set_scale(self.norm._scale)
|
|
1205
|
+
elif type(self.norm) is colors.Normalize:
|
|
1206
|
+
# plain Normalize:
|
|
1207
|
+
self._set_scale('linear')
|
|
1208
|
+
else:
|
|
1209
|
+
# norm._scale is None or not an attr: derive the scale from
|
|
1210
|
+
# the Norm:
|
|
1211
|
+
funcs = (self.norm, self.norm.inverse)
|
|
1212
|
+
self._set_scale('function', functions=funcs)
|
|
1213
|
+
|
|
1214
|
+
def _locate(self, x):
|
|
1215
|
+
"""
|
|
1216
|
+
Given a set of color data values, return their
|
|
1217
|
+
corresponding colorbar data coordinates.
|
|
1218
|
+
"""
|
|
1219
|
+
if isinstance(self.norm, (colors.NoNorm, colors.BoundaryNorm)):
|
|
1220
|
+
b = self._boundaries
|
|
1221
|
+
xn = x
|
|
1222
|
+
else:
|
|
1223
|
+
# Do calculations using normalized coordinates so
|
|
1224
|
+
# as to make the interpolation more accurate.
|
|
1225
|
+
b = self.norm(self._boundaries, clip=False).filled()
|
|
1226
|
+
xn = self.norm(x, clip=False).filled()
|
|
1227
|
+
|
|
1228
|
+
bunique = b[self._inside]
|
|
1229
|
+
yunique = self._y
|
|
1230
|
+
|
|
1231
|
+
z = np.interp(xn, bunique, yunique)
|
|
1232
|
+
return z
|
|
1233
|
+
|
|
1234
|
+
# trivial helpers
|
|
1235
|
+
|
|
1236
|
+
def _uniform_y(self, N):
|
|
1237
|
+
"""
|
|
1238
|
+
Return colorbar data coordinates for *N* uniformly
|
|
1239
|
+
spaced boundaries, plus extension lengths if required.
|
|
1240
|
+
"""
|
|
1241
|
+
automin = automax = 1. / (N - 1.)
|
|
1242
|
+
extendlength = self._get_extension_lengths(self.extendfrac,
|
|
1243
|
+
automin, automax,
|
|
1244
|
+
default=0.05)
|
|
1245
|
+
y = np.linspace(0, 1, N)
|
|
1246
|
+
return y, extendlength
|
|
1247
|
+
|
|
1248
|
+
def _proportional_y(self):
|
|
1249
|
+
"""
|
|
1250
|
+
Return colorbar data coordinates for the boundaries of
|
|
1251
|
+
a proportional colorbar, plus extension lengths if required:
|
|
1252
|
+
"""
|
|
1253
|
+
if (isinstance(self.norm, colors.BoundaryNorm) or
|
|
1254
|
+
self.boundaries is not None):
|
|
1255
|
+
y = (self._boundaries - self._boundaries[self._inside][0])
|
|
1256
|
+
y = y / (self._boundaries[self._inside][-1] -
|
|
1257
|
+
self._boundaries[self._inside][0])
|
|
1258
|
+
# need yscaled the same as the axes scale to get
|
|
1259
|
+
# the extend lengths.
|
|
1260
|
+
if self.spacing == 'uniform':
|
|
1261
|
+
yscaled = self._forward_boundaries(self._boundaries)
|
|
1262
|
+
else:
|
|
1263
|
+
yscaled = y
|
|
1264
|
+
else:
|
|
1265
|
+
y = self.norm(self._boundaries.copy())
|
|
1266
|
+
y = np.ma.filled(y, np.nan)
|
|
1267
|
+
# the norm and the scale should be the same...
|
|
1268
|
+
yscaled = y
|
|
1269
|
+
y = y[self._inside]
|
|
1270
|
+
yscaled = yscaled[self._inside]
|
|
1271
|
+
# normalize from 0..1:
|
|
1272
|
+
norm = colors.Normalize(y[0], y[-1])
|
|
1273
|
+
y = np.ma.filled(norm(y), np.nan)
|
|
1274
|
+
norm = colors.Normalize(yscaled[0], yscaled[-1])
|
|
1275
|
+
yscaled = np.ma.filled(norm(yscaled), np.nan)
|
|
1276
|
+
# make the lower and upper extend lengths proportional to the lengths
|
|
1277
|
+
# of the first and last boundary spacing (if extendfrac='auto'):
|
|
1278
|
+
automin = yscaled[1] - yscaled[0]
|
|
1279
|
+
automax = yscaled[-1] - yscaled[-2]
|
|
1280
|
+
extendlength = [0, 0]
|
|
1281
|
+
if self._extend_lower() or self._extend_upper():
|
|
1282
|
+
extendlength = self._get_extension_lengths(
|
|
1283
|
+
self.extendfrac, automin, automax, default=0.05)
|
|
1284
|
+
return y, extendlength
|
|
1285
|
+
|
|
1286
|
+
def _get_extension_lengths(self, frac, automin, automax, default=0.05):
|
|
1287
|
+
"""
|
|
1288
|
+
Return the lengths of colorbar extensions.
|
|
1289
|
+
|
|
1290
|
+
This is a helper method for _uniform_y and _proportional_y.
|
|
1291
|
+
"""
|
|
1292
|
+
# Set the default value.
|
|
1293
|
+
extendlength = np.array([default, default])
|
|
1294
|
+
if isinstance(frac, str):
|
|
1295
|
+
_api.check_in_list(['auto'], extendfrac=frac.lower())
|
|
1296
|
+
# Use the provided values when 'auto' is required.
|
|
1297
|
+
extendlength[:] = [automin, automax]
|
|
1298
|
+
elif frac is not None:
|
|
1299
|
+
try:
|
|
1300
|
+
# Try to set min and max extension fractions directly.
|
|
1301
|
+
extendlength[:] = frac
|
|
1302
|
+
# If frac is a sequence containing None then NaN may
|
|
1303
|
+
# be encountered. This is an error.
|
|
1304
|
+
if np.isnan(extendlength).any():
|
|
1305
|
+
raise ValueError()
|
|
1306
|
+
except (TypeError, ValueError) as err:
|
|
1307
|
+
# Raise an error on encountering an invalid value for frac.
|
|
1308
|
+
raise ValueError('invalid value for extendfrac') from err
|
|
1309
|
+
return extendlength
|
|
1310
|
+
|
|
1311
|
+
def _extend_lower(self):
|
|
1312
|
+
"""Return whether the lower limit is open ended."""
|
|
1313
|
+
minmax = "max" if self.long_axis.get_inverted() else "min"
|
|
1314
|
+
return self.extend in ('both', minmax)
|
|
1315
|
+
|
|
1316
|
+
def _extend_upper(self):
|
|
1317
|
+
"""Return whether the upper limit is open ended."""
|
|
1318
|
+
minmax = "min" if self.long_axis.get_inverted() else "max"
|
|
1319
|
+
return self.extend in ('both', minmax)
|
|
1320
|
+
|
|
1321
|
+
def _short_axis(self):
|
|
1322
|
+
"""Return the short axis"""
|
|
1323
|
+
if self.orientation == 'vertical':
|
|
1324
|
+
return self.ax.xaxis
|
|
1325
|
+
return self.ax.yaxis
|
|
1326
|
+
|
|
1327
|
+
def _get_view(self):
|
|
1328
|
+
# docstring inherited
|
|
1329
|
+
# An interactive view for a colorbar is the norm's vmin/vmax
|
|
1330
|
+
return self.norm.vmin, self.norm.vmax
|
|
1331
|
+
|
|
1332
|
+
def _set_view(self, view):
|
|
1333
|
+
# docstring inherited
|
|
1334
|
+
# An interactive view for a colorbar is the norm's vmin/vmax
|
|
1335
|
+
self.norm.vmin, self.norm.vmax = view
|
|
1336
|
+
|
|
1337
|
+
def _set_view_from_bbox(self, bbox, direction='in',
|
|
1338
|
+
mode=None, twinx=False, twiny=False):
|
|
1339
|
+
# docstring inherited
|
|
1340
|
+
# For colorbars, we use the zoom bbox to scale the norm's vmin/vmax
|
|
1341
|
+
new_xbound, new_ybound = self.ax._prepare_view_from_bbox(
|
|
1342
|
+
bbox, direction=direction, mode=mode, twinx=twinx, twiny=twiny)
|
|
1343
|
+
if self.orientation == 'horizontal':
|
|
1344
|
+
self.norm.vmin, self.norm.vmax = new_xbound
|
|
1345
|
+
elif self.orientation == 'vertical':
|
|
1346
|
+
self.norm.vmin, self.norm.vmax = new_ybound
|
|
1347
|
+
|
|
1348
|
+
def drag_pan(self, button, key, x, y):
|
|
1349
|
+
# docstring inherited
|
|
1350
|
+
points = self.ax._get_pan_points(button, key, x, y)
|
|
1351
|
+
if points is not None:
|
|
1352
|
+
if self.orientation == 'horizontal':
|
|
1353
|
+
self.norm.vmin, self.norm.vmax = points[:, 0]
|
|
1354
|
+
elif self.orientation == 'vertical':
|
|
1355
|
+
self.norm.vmin, self.norm.vmax = points[:, 1]
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
ColorbarBase = Colorbar # Backcompat API
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
def _normalize_location_orientation(location, orientation):
|
|
1362
|
+
if location is None:
|
|
1363
|
+
location = _get_ticklocation_from_orientation(orientation)
|
|
1364
|
+
loc_settings = _api.getitem_checked({
|
|
1365
|
+
"left": {"location": "left", "anchor": (1.0, 0.5),
|
|
1366
|
+
"panchor": (0.0, 0.5), "pad": 0.10},
|
|
1367
|
+
"right": {"location": "right", "anchor": (0.0, 0.5),
|
|
1368
|
+
"panchor": (1.0, 0.5), "pad": 0.05},
|
|
1369
|
+
"top": {"location": "top", "anchor": (0.5, 0.0),
|
|
1370
|
+
"panchor": (0.5, 1.0), "pad": 0.05},
|
|
1371
|
+
"bottom": {"location": "bottom", "anchor": (0.5, 1.0),
|
|
1372
|
+
"panchor": (0.5, 0.0), "pad": 0.15},
|
|
1373
|
+
}, location=location)
|
|
1374
|
+
loc_settings["orientation"] = _get_orientation_from_location(location)
|
|
1375
|
+
if orientation is not None and orientation != loc_settings["orientation"]:
|
|
1376
|
+
# Allow the user to pass both if they are consistent.
|
|
1377
|
+
raise TypeError("location and orientation are mutually exclusive")
|
|
1378
|
+
return loc_settings
|
|
1379
|
+
|
|
1380
|
+
|
|
1381
|
+
def _get_orientation_from_location(location):
|
|
1382
|
+
return _api.getitem_checked(
|
|
1383
|
+
{None: None, "left": "vertical", "right": "vertical",
|
|
1384
|
+
"top": "horizontal", "bottom": "horizontal"}, location=location)
|
|
1385
|
+
|
|
1386
|
+
|
|
1387
|
+
def _get_ticklocation_from_orientation(orientation):
|
|
1388
|
+
return _api.getitem_checked(
|
|
1389
|
+
{None: "right", "vertical": "right", "horizontal": "bottom"},
|
|
1390
|
+
orientation=orientation)
|
|
1391
|
+
|
|
1392
|
+
|
|
1393
|
+
@_docstring.interpd
|
|
1394
|
+
def make_axes(parents, location=None, orientation=None, fraction=0.15,
|
|
1395
|
+
shrink=1.0, aspect=20, **kwargs):
|
|
1396
|
+
"""
|
|
1397
|
+
Create an `~.axes.Axes` suitable for a colorbar.
|
|
1398
|
+
|
|
1399
|
+
The Axes is placed in the figure of the *parents* Axes, by resizing and
|
|
1400
|
+
repositioning *parents*.
|
|
1401
|
+
|
|
1402
|
+
Parameters
|
|
1403
|
+
----------
|
|
1404
|
+
parents : `~matplotlib.axes.Axes` or iterable or `numpy.ndarray` of `~.axes.Axes`
|
|
1405
|
+
The Axes to use as parents for placing the colorbar.
|
|
1406
|
+
%(_make_axes_kw_doc)s
|
|
1407
|
+
|
|
1408
|
+
Returns
|
|
1409
|
+
-------
|
|
1410
|
+
cax : `~matplotlib.axes.Axes`
|
|
1411
|
+
The child Axes.
|
|
1412
|
+
kwargs : dict
|
|
1413
|
+
The reduced keyword dictionary to be passed when creating the colorbar
|
|
1414
|
+
instance.
|
|
1415
|
+
"""
|
|
1416
|
+
loc_settings = _normalize_location_orientation(location, orientation)
|
|
1417
|
+
# put appropriate values into the kwargs dict for passing back to
|
|
1418
|
+
# the Colorbar class
|
|
1419
|
+
kwargs['orientation'] = loc_settings['orientation']
|
|
1420
|
+
location = kwargs['ticklocation'] = loc_settings['location']
|
|
1421
|
+
|
|
1422
|
+
anchor = kwargs.pop('anchor', loc_settings['anchor'])
|
|
1423
|
+
panchor = kwargs.pop('panchor', loc_settings['panchor'])
|
|
1424
|
+
aspect0 = aspect
|
|
1425
|
+
# turn parents into a list if it is not already. Note we cannot
|
|
1426
|
+
# use .flatten or .ravel as these copy the references rather than
|
|
1427
|
+
# reuse them, leading to a memory leak
|
|
1428
|
+
if isinstance(parents, np.ndarray):
|
|
1429
|
+
parents = list(parents.flat)
|
|
1430
|
+
elif np.iterable(parents):
|
|
1431
|
+
parents = list(parents)
|
|
1432
|
+
else:
|
|
1433
|
+
parents = [parents]
|
|
1434
|
+
|
|
1435
|
+
fig = parents[0].get_figure()
|
|
1436
|
+
|
|
1437
|
+
pad0 = 0.05 if fig.get_constrained_layout() else loc_settings['pad']
|
|
1438
|
+
pad = kwargs.pop('pad', pad0)
|
|
1439
|
+
|
|
1440
|
+
if not all(fig is ax.get_figure() for ax in parents):
|
|
1441
|
+
raise ValueError('Unable to create a colorbar Axes as not all '
|
|
1442
|
+
'parents share the same figure.')
|
|
1443
|
+
|
|
1444
|
+
# take a bounding box around all of the given Axes
|
|
1445
|
+
parents_bbox = mtransforms.Bbox.union(
|
|
1446
|
+
[ax.get_position(original=True).frozen() for ax in parents])
|
|
1447
|
+
|
|
1448
|
+
pb = parents_bbox
|
|
1449
|
+
if location in ('left', 'right'):
|
|
1450
|
+
if location == 'left':
|
|
1451
|
+
pbcb, _, pb1 = pb.splitx(fraction, fraction + pad)
|
|
1452
|
+
else:
|
|
1453
|
+
pb1, _, pbcb = pb.splitx(1 - fraction - pad, 1 - fraction)
|
|
1454
|
+
pbcb = pbcb.shrunk(1.0, shrink).anchored(anchor, pbcb)
|
|
1455
|
+
else:
|
|
1456
|
+
if location == 'bottom':
|
|
1457
|
+
pbcb, _, pb1 = pb.splity(fraction, fraction + pad)
|
|
1458
|
+
else:
|
|
1459
|
+
pb1, _, pbcb = pb.splity(1 - fraction - pad, 1 - fraction)
|
|
1460
|
+
pbcb = pbcb.shrunk(shrink, 1.0).anchored(anchor, pbcb)
|
|
1461
|
+
|
|
1462
|
+
# define the aspect ratio in terms of y's per x rather than x's per y
|
|
1463
|
+
aspect = 1.0 / aspect
|
|
1464
|
+
|
|
1465
|
+
# define a transform which takes us from old axes coordinates to
|
|
1466
|
+
# new axes coordinates
|
|
1467
|
+
shrinking_trans = mtransforms.BboxTransform(parents_bbox, pb1)
|
|
1468
|
+
|
|
1469
|
+
# transform each of the Axes in parents using the new transform
|
|
1470
|
+
for ax in parents:
|
|
1471
|
+
new_posn = shrinking_trans.transform(ax.get_position(original=True))
|
|
1472
|
+
new_posn = mtransforms.Bbox(new_posn)
|
|
1473
|
+
ax._set_position(new_posn)
|
|
1474
|
+
if panchor is not False:
|
|
1475
|
+
ax.set_anchor(panchor)
|
|
1476
|
+
|
|
1477
|
+
cax = fig.add_axes(pbcb, label="<colorbar>")
|
|
1478
|
+
for a in parents:
|
|
1479
|
+
a._colorbars.append(cax) # tell the parent it has a colorbar
|
|
1480
|
+
cax._colorbar_info = dict(
|
|
1481
|
+
parents=parents,
|
|
1482
|
+
location=location,
|
|
1483
|
+
shrink=shrink,
|
|
1484
|
+
anchor=anchor,
|
|
1485
|
+
panchor=panchor,
|
|
1486
|
+
fraction=fraction,
|
|
1487
|
+
aspect=aspect0,
|
|
1488
|
+
pad=pad)
|
|
1489
|
+
# and we need to set the aspect ratio by hand...
|
|
1490
|
+
cax.set_anchor(anchor)
|
|
1491
|
+
cax.set_box_aspect(aspect)
|
|
1492
|
+
cax.set_aspect('auto')
|
|
1493
|
+
|
|
1494
|
+
return cax, kwargs
|
|
1495
|
+
|
|
1496
|
+
|
|
1497
|
+
@_docstring.interpd
|
|
1498
|
+
def make_axes_gridspec(parent, *, location=None, orientation=None,
|
|
1499
|
+
fraction=0.15, shrink=1.0, aspect=20, **kwargs):
|
|
1500
|
+
"""
|
|
1501
|
+
Create an `~.axes.Axes` suitable for a colorbar.
|
|
1502
|
+
|
|
1503
|
+
The Axes is placed in the figure of the *parent* Axes, by resizing and
|
|
1504
|
+
repositioning *parent*.
|
|
1505
|
+
|
|
1506
|
+
This function is similar to `.make_axes` and mostly compatible with it.
|
|
1507
|
+
Primary differences are
|
|
1508
|
+
|
|
1509
|
+
- `.make_axes_gridspec` requires the *parent* to have a subplotspec.
|
|
1510
|
+
- `.make_axes` positions the Axes in figure coordinates;
|
|
1511
|
+
`.make_axes_gridspec` positions it using a subplotspec.
|
|
1512
|
+
- `.make_axes` updates the position of the parent. `.make_axes_gridspec`
|
|
1513
|
+
replaces the parent gridspec with a new one.
|
|
1514
|
+
|
|
1515
|
+
Parameters
|
|
1516
|
+
----------
|
|
1517
|
+
parent : `~matplotlib.axes.Axes`
|
|
1518
|
+
The Axes to use as parent for placing the colorbar.
|
|
1519
|
+
%(_make_axes_kw_doc)s
|
|
1520
|
+
|
|
1521
|
+
Returns
|
|
1522
|
+
-------
|
|
1523
|
+
cax : `~matplotlib.axes.Axes`
|
|
1524
|
+
The child Axes.
|
|
1525
|
+
kwargs : dict
|
|
1526
|
+
The reduced keyword dictionary to be passed when creating the colorbar
|
|
1527
|
+
instance.
|
|
1528
|
+
"""
|
|
1529
|
+
|
|
1530
|
+
loc_settings = _normalize_location_orientation(location, orientation)
|
|
1531
|
+
kwargs['orientation'] = loc_settings['orientation']
|
|
1532
|
+
location = kwargs['ticklocation'] = loc_settings['location']
|
|
1533
|
+
|
|
1534
|
+
aspect0 = aspect
|
|
1535
|
+
anchor = kwargs.pop('anchor', loc_settings['anchor'])
|
|
1536
|
+
panchor = kwargs.pop('panchor', loc_settings['panchor'])
|
|
1537
|
+
pad = kwargs.pop('pad', loc_settings["pad"])
|
|
1538
|
+
wh_space = 2 * pad / (1 - pad)
|
|
1539
|
+
|
|
1540
|
+
if location in ('left', 'right'):
|
|
1541
|
+
gs = parent.get_subplotspec().subgridspec(
|
|
1542
|
+
3, 2, wspace=wh_space, hspace=0,
|
|
1543
|
+
height_ratios=[(1-anchor[1])*(1-shrink), shrink, anchor[1]*(1-shrink)])
|
|
1544
|
+
if location == 'left':
|
|
1545
|
+
gs.set_width_ratios([fraction, 1 - fraction - pad])
|
|
1546
|
+
ss_main = gs[:, 1]
|
|
1547
|
+
ss_cb = gs[1, 0]
|
|
1548
|
+
else:
|
|
1549
|
+
gs.set_width_ratios([1 - fraction - pad, fraction])
|
|
1550
|
+
ss_main = gs[:, 0]
|
|
1551
|
+
ss_cb = gs[1, 1]
|
|
1552
|
+
else:
|
|
1553
|
+
gs = parent.get_subplotspec().subgridspec(
|
|
1554
|
+
2, 3, hspace=wh_space, wspace=0,
|
|
1555
|
+
width_ratios=[anchor[0]*(1-shrink), shrink, (1-anchor[0])*(1-shrink)])
|
|
1556
|
+
if location == 'top':
|
|
1557
|
+
gs.set_height_ratios([fraction, 1 - fraction - pad])
|
|
1558
|
+
ss_main = gs[1, :]
|
|
1559
|
+
ss_cb = gs[0, 1]
|
|
1560
|
+
else:
|
|
1561
|
+
gs.set_height_ratios([1 - fraction - pad, fraction])
|
|
1562
|
+
ss_main = gs[0, :]
|
|
1563
|
+
ss_cb = gs[1, 1]
|
|
1564
|
+
aspect = 1 / aspect
|
|
1565
|
+
|
|
1566
|
+
parent.set_subplotspec(ss_main)
|
|
1567
|
+
if panchor is not False:
|
|
1568
|
+
parent.set_anchor(panchor)
|
|
1569
|
+
|
|
1570
|
+
fig = parent.get_figure()
|
|
1571
|
+
cax = fig.add_subplot(ss_cb, label="<colorbar>")
|
|
1572
|
+
parent._colorbars.append(cax) # tell the parent it has a colorbar
|
|
1573
|
+
cax.set_anchor(anchor)
|
|
1574
|
+
cax.set_box_aspect(aspect)
|
|
1575
|
+
cax.set_aspect('auto')
|
|
1576
|
+
cax._colorbar_info = dict(
|
|
1577
|
+
location=location,
|
|
1578
|
+
parents=[parent],
|
|
1579
|
+
shrink=shrink,
|
|
1580
|
+
anchor=anchor,
|
|
1581
|
+
panchor=panchor,
|
|
1582
|
+
fraction=fraction,
|
|
1583
|
+
aspect=aspect0,
|
|
1584
|
+
pad=pad)
|
|
1585
|
+
|
|
1586
|
+
return cax, kwargs
|