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,909 @@
|
|
|
1
|
+
# Vendored from matplotlib 3.11 (see licenses/LICENSE_MATPLOTLIB), adapted for matplotlib_rs.
|
|
2
|
+
"""
|
|
3
|
+
The Colorizer class which handles the data to color pipeline via a
|
|
4
|
+
normalization and a colormap.
|
|
5
|
+
|
|
6
|
+
.. admonition:: Provisional status of colorizer
|
|
7
|
+
|
|
8
|
+
The ``colorizer`` module and classes in this file are considered
|
|
9
|
+
provisional and may change at any time without a deprecation period.
|
|
10
|
+
|
|
11
|
+
.. seealso::
|
|
12
|
+
|
|
13
|
+
:doc:`/gallery/color/colormap_reference` for a list of builtin colormaps.
|
|
14
|
+
|
|
15
|
+
:ref:`colormap-manipulation` for examples of how to make colormaps.
|
|
16
|
+
|
|
17
|
+
:ref:`colormaps` for an in-depth discussion of choosing colormaps.
|
|
18
|
+
|
|
19
|
+
:ref:`colormapnorms` for more details about data normalization.
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import functools
|
|
24
|
+
|
|
25
|
+
import numpy as np
|
|
26
|
+
from numpy import ma
|
|
27
|
+
|
|
28
|
+
from matplotlib_rs import _api, colors, cbook, artist, scale
|
|
29
|
+
import matplotlib_rs as mpl
|
|
30
|
+
|
|
31
|
+
mpl._docstring.interpd.register(
|
|
32
|
+
colorizer_doc="""\
|
|
33
|
+
colorizer : `~matplotlib.colorizer.Colorizer` or None, default: None
|
|
34
|
+
The Colorizer object used to map color to data. If None, a Colorizer
|
|
35
|
+
object is created from a *norm* and *cmap*.""",
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Colorizer:
|
|
40
|
+
"""
|
|
41
|
+
Data to color pipeline.
|
|
42
|
+
|
|
43
|
+
This pipeline is accessible via `.Colorizer.to_rgba` and executed via
|
|
44
|
+
the `.Colorizer.norm` and `.Colorizer.cmap` attributes.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
cmap: colorbar.Colorbar or str or None, default: None
|
|
49
|
+
The colormap used to color data.
|
|
50
|
+
|
|
51
|
+
norm: colors.Normalize or str or None, default: None
|
|
52
|
+
The normalization used to normalize the data
|
|
53
|
+
"""
|
|
54
|
+
def __init__(self, cmap=None, norm=None):
|
|
55
|
+
|
|
56
|
+
self._cmap = None
|
|
57
|
+
self._set_cmap(cmap)
|
|
58
|
+
|
|
59
|
+
self._id_norm = None
|
|
60
|
+
self._norm = None
|
|
61
|
+
self.norm = norm
|
|
62
|
+
|
|
63
|
+
self.callbacks = cbook.CallbackRegistry(signals=["changed"])
|
|
64
|
+
self.colorbar = None
|
|
65
|
+
|
|
66
|
+
def _scale_norm(self, norm, vmin, vmax, A):
|
|
67
|
+
"""
|
|
68
|
+
Helper for initial scaling.
|
|
69
|
+
|
|
70
|
+
Used by public functions that create a ScalarMappable and support
|
|
71
|
+
parameters *vmin*, *vmax* and *norm*. This makes sure that a *norm*
|
|
72
|
+
will take precedence over *vmin*, *vmax*.
|
|
73
|
+
|
|
74
|
+
Note that this method does not set the norm.
|
|
75
|
+
"""
|
|
76
|
+
if vmin is not None or vmax is not None:
|
|
77
|
+
self.set_clim(vmin, vmax)
|
|
78
|
+
if isinstance(norm, colors.Normalize):
|
|
79
|
+
raise ValueError(
|
|
80
|
+
"Passing a Normalize instance simultaneously with "
|
|
81
|
+
"vmin/vmax is not supported. Please pass vmin/vmax "
|
|
82
|
+
"as arguments to the norm object when creating it")
|
|
83
|
+
|
|
84
|
+
# always resolve the autoscaling so we have concrete limits
|
|
85
|
+
# rather than deferring to draw time.
|
|
86
|
+
self.autoscale_None(A)
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def norm(self):
|
|
90
|
+
return self._norm
|
|
91
|
+
|
|
92
|
+
@norm.setter
|
|
93
|
+
def norm(self, norm):
|
|
94
|
+
norm = _ensure_norm(norm, n_components=self.cmap.n_variates)
|
|
95
|
+
if norm is self.norm:
|
|
96
|
+
# We aren't updating anything
|
|
97
|
+
return
|
|
98
|
+
|
|
99
|
+
in_init = self.norm is None
|
|
100
|
+
# Remove the current callback and connect to the new one
|
|
101
|
+
if not in_init:
|
|
102
|
+
self.norm.callbacks.disconnect(self._id_norm)
|
|
103
|
+
self._norm = norm
|
|
104
|
+
self._id_norm = self.norm.callbacks.connect('changed',
|
|
105
|
+
self.changed)
|
|
106
|
+
if not in_init:
|
|
107
|
+
self.changed()
|
|
108
|
+
|
|
109
|
+
def to_rgba(self, x, alpha=None, bytes=False, norm=True):
|
|
110
|
+
"""
|
|
111
|
+
Return a normalized RGBA array corresponding to *x*.
|
|
112
|
+
|
|
113
|
+
In the normal case, *x* is a 1D or 2D sequence of scalars, and
|
|
114
|
+
the corresponding `~numpy.ndarray` of RGBA values will be returned,
|
|
115
|
+
based on the norm and colormap set for this Colorizer.
|
|
116
|
+
|
|
117
|
+
There is one special case, for handling images that are already
|
|
118
|
+
RGB or RGBA, such as might have been read from an image file.
|
|
119
|
+
If *x* is an `~numpy.ndarray` with 3 dimensions,
|
|
120
|
+
and the last dimension is either 3 or 4, then it will be
|
|
121
|
+
treated as an RGB or RGBA array, and no mapping will be done.
|
|
122
|
+
The array can be `~numpy.uint8`, or it can be floats with
|
|
123
|
+
values in the 0-1 range; otherwise a ValueError will be raised.
|
|
124
|
+
Any NaNs or masked elements will be set to 0 alpha.
|
|
125
|
+
If the last dimension is 3, the *alpha* kwarg (defaulting to 1)
|
|
126
|
+
will be used to fill in the transparency. If the last dimension
|
|
127
|
+
is 4, the *alpha* kwarg is ignored; it does not
|
|
128
|
+
replace the preexisting alpha. A ValueError will be raised
|
|
129
|
+
if the third dimension is other than 3 or 4.
|
|
130
|
+
|
|
131
|
+
In either case, if *bytes* is *False* (default), the RGBA
|
|
132
|
+
array will be floats in the 0-1 range; if it is *True*,
|
|
133
|
+
the returned RGBA array will be `~numpy.uint8` in the 0 to 255 range.
|
|
134
|
+
|
|
135
|
+
If norm is False, no normalization of the input data is
|
|
136
|
+
performed, and it is assumed to be in the range (0-1).
|
|
137
|
+
|
|
138
|
+
"""
|
|
139
|
+
# First check for special case, image input:
|
|
140
|
+
if isinstance(x, np.ndarray) and x.ndim == 3:
|
|
141
|
+
return self._pass_image_data(x, alpha, bytes, norm)
|
|
142
|
+
|
|
143
|
+
# Otherwise run norm -> colormap pipeline
|
|
144
|
+
x = ma.asarray(x)
|
|
145
|
+
if norm:
|
|
146
|
+
x = self.norm(x)
|
|
147
|
+
rgba = self.cmap(x, alpha=alpha, bytes=bytes)
|
|
148
|
+
return rgba
|
|
149
|
+
|
|
150
|
+
@staticmethod
|
|
151
|
+
def _pass_image_data(x, alpha=None, bytes=False, norm=True):
|
|
152
|
+
"""
|
|
153
|
+
Helper function to pass ndarray of shape (...,3) or (..., 4)
|
|
154
|
+
through `to_rgba()`, see `to_rgba()` for docstring.
|
|
155
|
+
"""
|
|
156
|
+
if x.shape[2] == 3:
|
|
157
|
+
if alpha is None:
|
|
158
|
+
alpha = 1
|
|
159
|
+
if x.dtype == np.uint8:
|
|
160
|
+
alpha = np.uint8(alpha * 255)
|
|
161
|
+
m, n = x.shape[:2]
|
|
162
|
+
xx = np.empty(shape=(m, n, 4), dtype=x.dtype)
|
|
163
|
+
xx[:, :, :3] = x
|
|
164
|
+
xx[:, :, 3] = alpha
|
|
165
|
+
elif x.shape[2] == 4:
|
|
166
|
+
xx = x
|
|
167
|
+
else:
|
|
168
|
+
raise ValueError("Third dimension must be 3 or 4")
|
|
169
|
+
if xx.dtype.kind == 'f':
|
|
170
|
+
# If any of R, G, B, or A is nan, set to 0
|
|
171
|
+
if np.any(nans := np.isnan(x)):
|
|
172
|
+
if x.shape[2] == 4:
|
|
173
|
+
xx = xx.copy()
|
|
174
|
+
xx[np.any(nans, axis=2), :] = 0
|
|
175
|
+
|
|
176
|
+
if norm and (xx.max() > 1 or xx.min() < 0):
|
|
177
|
+
raise ValueError("Floating point image RGB values "
|
|
178
|
+
"must be in the [0,1] range")
|
|
179
|
+
if bytes:
|
|
180
|
+
xx = (xx * 255).astype(np.uint8)
|
|
181
|
+
elif xx.dtype == np.uint8:
|
|
182
|
+
if not bytes:
|
|
183
|
+
xx = xx.astype(np.float32) / 255
|
|
184
|
+
else:
|
|
185
|
+
raise ValueError("Image RGB array must be uint8 or "
|
|
186
|
+
"floating point; found %s" % xx.dtype)
|
|
187
|
+
# Account for any masked entries in the original array
|
|
188
|
+
# If any of R, G, B, or A are masked for an entry, we set alpha to 0
|
|
189
|
+
if np.ma.is_masked(x):
|
|
190
|
+
xx[np.any(np.ma.getmaskarray(x), axis=2), 3] = 0
|
|
191
|
+
return xx
|
|
192
|
+
|
|
193
|
+
def autoscale(self, A):
|
|
194
|
+
"""
|
|
195
|
+
Autoscale the scalar limits on the norm instance using the
|
|
196
|
+
current array
|
|
197
|
+
"""
|
|
198
|
+
if A is None:
|
|
199
|
+
raise TypeError('You must first set_array for mappable')
|
|
200
|
+
# If the norm's limits are updated self.changed() will be called
|
|
201
|
+
# through the callbacks attached to the norm
|
|
202
|
+
self.norm.autoscale(A)
|
|
203
|
+
|
|
204
|
+
def autoscale_None(self, A):
|
|
205
|
+
"""
|
|
206
|
+
Autoscale the scalar limits on the norm instance using the
|
|
207
|
+
current array, changing only limits that are None
|
|
208
|
+
"""
|
|
209
|
+
if A is None:
|
|
210
|
+
raise TypeError('You must first set_array for mappable')
|
|
211
|
+
# If the norm's limits are updated self.changed() will be called
|
|
212
|
+
# through the callbacks attached to the norm
|
|
213
|
+
self.norm.autoscale_None(A)
|
|
214
|
+
|
|
215
|
+
def _set_cmap(self, cmap):
|
|
216
|
+
"""
|
|
217
|
+
Set the colormap for luminance data.
|
|
218
|
+
|
|
219
|
+
Parameters
|
|
220
|
+
----------
|
|
221
|
+
cmap : `.Colormap` or str or None
|
|
222
|
+
"""
|
|
223
|
+
in_init = self._cmap is None
|
|
224
|
+
cmap_obj = _ensure_cmap(cmap, accept_multivariate=True)
|
|
225
|
+
if not in_init and self.norm.n_components != cmap_obj.n_variates:
|
|
226
|
+
raise ValueError(f"The colormap {cmap} does not support "
|
|
227
|
+
f"{self.norm.n_components} variates as required by "
|
|
228
|
+
f"the {type(self.norm)} on this Colorizer")
|
|
229
|
+
self._cmap = cmap_obj
|
|
230
|
+
if not in_init:
|
|
231
|
+
self.changed() # Things are not set up properly yet.
|
|
232
|
+
|
|
233
|
+
@property
|
|
234
|
+
def cmap(self):
|
|
235
|
+
return self._cmap
|
|
236
|
+
|
|
237
|
+
@cmap.setter
|
|
238
|
+
def cmap(self, cmap):
|
|
239
|
+
self._set_cmap(cmap)
|
|
240
|
+
|
|
241
|
+
def set_clim(self, vmin=None, vmax=None):
|
|
242
|
+
"""
|
|
243
|
+
Set the norm limits for image scaling.
|
|
244
|
+
|
|
245
|
+
Parameters
|
|
246
|
+
----------
|
|
247
|
+
vmin, vmax : float
|
|
248
|
+
The limits.
|
|
249
|
+
|
|
250
|
+
For scalar data, the limits may also be passed as a
|
|
251
|
+
tuple (*vmin*, *vmax*) single positional argument.
|
|
252
|
+
|
|
253
|
+
.. ACCEPTS: (vmin: float, vmax: float)
|
|
254
|
+
"""
|
|
255
|
+
if self.norm.n_components == 1:
|
|
256
|
+
if vmax is None:
|
|
257
|
+
try:
|
|
258
|
+
vmin, vmax = vmin
|
|
259
|
+
except (TypeError, ValueError):
|
|
260
|
+
pass
|
|
261
|
+
|
|
262
|
+
orig_vmin_vmax = self.norm.vmin, self.norm.vmax
|
|
263
|
+
|
|
264
|
+
# Blocked context manager prevents callbacks from being triggered
|
|
265
|
+
# until both vmin and vmax are updated
|
|
266
|
+
with self.norm.callbacks.blocked(signal='changed'):
|
|
267
|
+
# Since the @vmin/vmax.setter invokes colors._sanitize_extrema()
|
|
268
|
+
# to sanitize the input, the input is not sanitized here
|
|
269
|
+
if vmin is not None:
|
|
270
|
+
self.norm.vmin = vmin
|
|
271
|
+
if vmax is not None:
|
|
272
|
+
self.norm.vmax = vmax
|
|
273
|
+
|
|
274
|
+
# emit a update signal if the limits are changed
|
|
275
|
+
if orig_vmin_vmax != (self.norm.vmin, self.norm.vmax):
|
|
276
|
+
self.norm.callbacks.process('changed')
|
|
277
|
+
|
|
278
|
+
def get_clim(self):
|
|
279
|
+
"""
|
|
280
|
+
Return the values (min, max) that are mapped to the colormap limits.
|
|
281
|
+
"""
|
|
282
|
+
return self.norm.vmin, self.norm.vmax
|
|
283
|
+
|
|
284
|
+
def changed(self):
|
|
285
|
+
"""
|
|
286
|
+
Call this whenever the mappable is changed to notify all the
|
|
287
|
+
callbackSM listeners to the 'changed' signal.
|
|
288
|
+
"""
|
|
289
|
+
self.callbacks.process('changed')
|
|
290
|
+
self.stale = True
|
|
291
|
+
|
|
292
|
+
@property
|
|
293
|
+
def vmin(self):
|
|
294
|
+
return self.get_clim()[0]
|
|
295
|
+
|
|
296
|
+
@vmin.setter
|
|
297
|
+
def vmin(self, vmin):
|
|
298
|
+
self.set_clim(vmin=vmin)
|
|
299
|
+
|
|
300
|
+
@property
|
|
301
|
+
def vmax(self):
|
|
302
|
+
return self.get_clim()[1]
|
|
303
|
+
|
|
304
|
+
@vmax.setter
|
|
305
|
+
def vmax(self, vmax):
|
|
306
|
+
self.set_clim(vmax=vmax)
|
|
307
|
+
|
|
308
|
+
@property
|
|
309
|
+
def clip(self):
|
|
310
|
+
return self.norm.clip
|
|
311
|
+
|
|
312
|
+
@clip.setter
|
|
313
|
+
def clip(self, clip):
|
|
314
|
+
self.norm.clip = clip
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
class _ColorizerInterface:
|
|
318
|
+
"""
|
|
319
|
+
Base class that contains the interface to `Colorizer` objects from
|
|
320
|
+
a `ColorizingArtist` or `.cm.ScalarMappable`.
|
|
321
|
+
|
|
322
|
+
Note: This class only contain functions that interface the .colorizer
|
|
323
|
+
attribute. Other functions that as shared between `.ColorizingArtist`
|
|
324
|
+
and `.cm.ScalarMappable` are not included.
|
|
325
|
+
"""
|
|
326
|
+
def _scale_norm(self, norm, vmin, vmax):
|
|
327
|
+
self._colorizer._scale_norm(norm, vmin, vmax, self._A)
|
|
328
|
+
|
|
329
|
+
def to_rgba(self, x, alpha=None, bytes=False, norm=True):
|
|
330
|
+
"""
|
|
331
|
+
Return a normalized RGBA array corresponding to *x*.
|
|
332
|
+
|
|
333
|
+
In the normal case, *x* is a 1D or 2D sequence of scalars, and
|
|
334
|
+
the corresponding `~numpy.ndarray` of RGBA values will be returned,
|
|
335
|
+
based on the norm and colormap set for this Colorizer.
|
|
336
|
+
|
|
337
|
+
There is one special case, for handling images that are already
|
|
338
|
+
RGB or RGBA, such as might have been read from an image file.
|
|
339
|
+
If *x* is an `~numpy.ndarray` with 3 dimensions,
|
|
340
|
+
and the last dimension is either 3 or 4, then it will be
|
|
341
|
+
treated as an RGB or RGBA array, and no mapping will be done.
|
|
342
|
+
The array can be `~numpy.uint8`, or it can be floats with
|
|
343
|
+
values in the 0-1 range; otherwise a ValueError will be raised.
|
|
344
|
+
Any NaNs or masked elements will be set to 0 alpha.
|
|
345
|
+
If the last dimension is 3, the *alpha* kwarg (defaulting to 1)
|
|
346
|
+
will be used to fill in the transparency. If the last dimension
|
|
347
|
+
is 4, the *alpha* kwarg is ignored; it does not
|
|
348
|
+
replace the preexisting alpha. A ValueError will be raised
|
|
349
|
+
if the third dimension is other than 3 or 4.
|
|
350
|
+
|
|
351
|
+
In either case, if *bytes* is *False* (default), the RGBA
|
|
352
|
+
array will be floats in the 0-1 range; if it is *True*,
|
|
353
|
+
the returned RGBA array will be `~numpy.uint8` in the 0 to 255 range.
|
|
354
|
+
|
|
355
|
+
If norm is False, no normalization of the input data is
|
|
356
|
+
performed, and it is assumed to be in the range (0-1).
|
|
357
|
+
|
|
358
|
+
"""
|
|
359
|
+
return self._colorizer.to_rgba(x, alpha=alpha, bytes=bytes, norm=norm)
|
|
360
|
+
|
|
361
|
+
def get_clim(self):
|
|
362
|
+
"""
|
|
363
|
+
Return the values (min, max) that are mapped to the colormap limits.
|
|
364
|
+
"""
|
|
365
|
+
return self._colorizer.get_clim()
|
|
366
|
+
|
|
367
|
+
def set_clim(self, vmin=None, vmax=None):
|
|
368
|
+
"""
|
|
369
|
+
Set the norm limits for image scaling.
|
|
370
|
+
|
|
371
|
+
Parameters
|
|
372
|
+
----------
|
|
373
|
+
vmin, vmax : float
|
|
374
|
+
The limits.
|
|
375
|
+
|
|
376
|
+
For scalar data, the limits may also be passed as a
|
|
377
|
+
tuple (*vmin*, *vmax*) as a single positional argument.
|
|
378
|
+
|
|
379
|
+
.. ACCEPTS: (vmin: float, vmax: float)
|
|
380
|
+
"""
|
|
381
|
+
# If the norm's limits are updated self.changed() will be called
|
|
382
|
+
# through the callbacks attached to the norm
|
|
383
|
+
self._colorizer.set_clim(vmin, vmax)
|
|
384
|
+
|
|
385
|
+
def get_alpha(self):
|
|
386
|
+
try:
|
|
387
|
+
return super().get_alpha()
|
|
388
|
+
except AttributeError:
|
|
389
|
+
return 1
|
|
390
|
+
|
|
391
|
+
@property
|
|
392
|
+
def cmap(self):
|
|
393
|
+
return self._colorizer.cmap
|
|
394
|
+
|
|
395
|
+
@cmap.setter
|
|
396
|
+
def cmap(self, cmap):
|
|
397
|
+
self._colorizer.cmap = cmap
|
|
398
|
+
|
|
399
|
+
def get_cmap(self):
|
|
400
|
+
"""Return the `.Colormap` instance."""
|
|
401
|
+
return self._colorizer.cmap
|
|
402
|
+
|
|
403
|
+
def set_cmap(self, cmap):
|
|
404
|
+
"""
|
|
405
|
+
Set the colormap for luminance data.
|
|
406
|
+
|
|
407
|
+
Parameters
|
|
408
|
+
----------
|
|
409
|
+
cmap : `.Colormap` or str or None
|
|
410
|
+
"""
|
|
411
|
+
self.cmap = cmap
|
|
412
|
+
|
|
413
|
+
@property
|
|
414
|
+
def norm(self):
|
|
415
|
+
return self._colorizer.norm
|
|
416
|
+
|
|
417
|
+
@norm.setter
|
|
418
|
+
def norm(self, norm):
|
|
419
|
+
self._colorizer.norm = norm
|
|
420
|
+
|
|
421
|
+
def set_norm(self, norm):
|
|
422
|
+
"""
|
|
423
|
+
Set the normalization instance.
|
|
424
|
+
|
|
425
|
+
Parameters
|
|
426
|
+
----------
|
|
427
|
+
norm : `.Normalize` or str or None
|
|
428
|
+
|
|
429
|
+
Notes
|
|
430
|
+
-----
|
|
431
|
+
If there are any colorbars using the mappable for this norm, setting
|
|
432
|
+
the norm of the mappable will reset the norm, locator, and formatters
|
|
433
|
+
on the colorbar to default.
|
|
434
|
+
"""
|
|
435
|
+
self.norm = norm
|
|
436
|
+
|
|
437
|
+
def autoscale(self):
|
|
438
|
+
"""
|
|
439
|
+
Autoscale the scalar limits on the norm instance using the
|
|
440
|
+
current array
|
|
441
|
+
"""
|
|
442
|
+
self._colorizer.autoscale(self._A)
|
|
443
|
+
|
|
444
|
+
def autoscale_None(self):
|
|
445
|
+
"""
|
|
446
|
+
Autoscale the scalar limits on the norm instance using the
|
|
447
|
+
current array, changing only limits that are None
|
|
448
|
+
"""
|
|
449
|
+
self._colorizer.autoscale_None(self._A)
|
|
450
|
+
|
|
451
|
+
@property
|
|
452
|
+
def colorbar(self):
|
|
453
|
+
"""
|
|
454
|
+
The last colorbar associated with this object. May be None
|
|
455
|
+
"""
|
|
456
|
+
return self._colorizer.colorbar
|
|
457
|
+
|
|
458
|
+
@colorbar.setter
|
|
459
|
+
def colorbar(self, colorbar):
|
|
460
|
+
self._colorizer.colorbar = colorbar
|
|
461
|
+
|
|
462
|
+
def _format_cursor_data_override(self, data):
|
|
463
|
+
# This function overwrites Artist.format_cursor_data(). We cannot
|
|
464
|
+
# implement cm.ScalarMappable.format_cursor_data() directly, because
|
|
465
|
+
# most cm.ScalarMappable subclasses inherit from Artist first and from
|
|
466
|
+
# cm.ScalarMappable second, so Artist.format_cursor_data would always
|
|
467
|
+
# have precedence over cm.ScalarMappable.format_cursor_data.
|
|
468
|
+
|
|
469
|
+
# Note if cm.ScalarMappable is depreciated, this functionality should be
|
|
470
|
+
# implemented as format_cursor_data() on ColorizingArtist.
|
|
471
|
+
if np.ma.getmask(data) or data is None:
|
|
472
|
+
# NOTE: for multivariate data, if *any* of the fields are masked,
|
|
473
|
+
# "[]" is returned here
|
|
474
|
+
return "[]"
|
|
475
|
+
|
|
476
|
+
if isinstance(self.norm, colors.MultiNorm):
|
|
477
|
+
norms = self.norm.norms
|
|
478
|
+
if isinstance(self.cmap, colors.BivarColormap):
|
|
479
|
+
n_s = (self.cmap.N, self.cmap.M)
|
|
480
|
+
else: # colors.MultivarColormap
|
|
481
|
+
n_s = [part.N for part in self.cmap]
|
|
482
|
+
else: # colors.Colormap
|
|
483
|
+
norms = [self.norm]
|
|
484
|
+
data = [data]
|
|
485
|
+
n_s = [self.cmap.N]
|
|
486
|
+
|
|
487
|
+
os = [f"{d:-#.{self._sig_digits_from_norm(no, d, n)}g}"
|
|
488
|
+
for no, d, n in zip(norms, data, n_s)]
|
|
489
|
+
return f"[{', '.join(os)}]"
|
|
490
|
+
|
|
491
|
+
@staticmethod
|
|
492
|
+
def _sig_digits_from_norm(norm, data, n):
|
|
493
|
+
# Determines the number of significant digits
|
|
494
|
+
# to use for a number given a norm, and n, where n is the
|
|
495
|
+
# number of colors in the colormap.
|
|
496
|
+
normed = norm(data)
|
|
497
|
+
if np.isfinite(normed):
|
|
498
|
+
if isinstance(norm, colors.BoundaryNorm):
|
|
499
|
+
# not an invertible normalization mapping
|
|
500
|
+
cur_idx = np.argmin(np.abs(norm.boundaries - data))
|
|
501
|
+
neigh_idx = max(0, cur_idx - 1)
|
|
502
|
+
# use max diff to prevent delta == 0
|
|
503
|
+
delta = np.diff(norm.boundaries[neigh_idx:cur_idx + 2]).max()
|
|
504
|
+
elif norm.vmin == norm.vmax:
|
|
505
|
+
# singular norms, use delta of 10% of only value
|
|
506
|
+
delta = np.abs(norm.vmin * .1)
|
|
507
|
+
else:
|
|
508
|
+
# Midpoints of neighboring color intervals.
|
|
509
|
+
neighbors = norm.inverse(
|
|
510
|
+
(int(float(normed) * n) + np.array([0, 1])) / n)
|
|
511
|
+
delta = abs(neighbors - data).max()
|
|
512
|
+
|
|
513
|
+
g_sig_digits = cbook._g_sig_digits(data, delta)
|
|
514
|
+
else:
|
|
515
|
+
g_sig_digits = 3 # Consistent with default below.
|
|
516
|
+
return g_sig_digits
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
class _ScalarMappable(_ColorizerInterface):
|
|
520
|
+
"""
|
|
521
|
+
A mixin class to map one or multiple sets of scalar data to RGBA.
|
|
522
|
+
|
|
523
|
+
The ScalarMappable applies data normalization before returning RGBA colors from
|
|
524
|
+
the given `~matplotlib.colors.Colormap`.
|
|
525
|
+
"""
|
|
526
|
+
|
|
527
|
+
# _ScalarMappable exists for compatibility with
|
|
528
|
+
# code written before the introduction of the Colorizer
|
|
529
|
+
# and ColorizingArtist classes.
|
|
530
|
+
|
|
531
|
+
# _ScalarMappable can be depreciated so that ColorizingArtist
|
|
532
|
+
# inherits directly from _ColorizerInterface.
|
|
533
|
+
# in this case, the following changes should occur:
|
|
534
|
+
# __init__() has its functionality moved to ColorizingArtist.
|
|
535
|
+
# set_array(), get_array(), _get_colorizer() and
|
|
536
|
+
# _check_exclusionary_keywords() are moved to ColorizingArtist.
|
|
537
|
+
# changed() can be removed so long as colorbar.Colorbar
|
|
538
|
+
# is changed to connect to the colorizer instead of the
|
|
539
|
+
# ScalarMappable/ColorizingArtist,
|
|
540
|
+
# otherwise changed() can be moved to ColorizingArtist.
|
|
541
|
+
def __init__(self, norm=None, cmap=None, *, colorizer=None, **kwargs):
|
|
542
|
+
"""
|
|
543
|
+
Parameters
|
|
544
|
+
----------
|
|
545
|
+
norm : `.Normalize` (or subclass thereof) or str or None
|
|
546
|
+
The normalizing object which scales data, typically into the
|
|
547
|
+
interval ``[0, 1]``.
|
|
548
|
+
If a `str`, a `.Normalize` subclass is dynamically generated based
|
|
549
|
+
on the scale with the corresponding name.
|
|
550
|
+
If *None*, *norm* defaults to a *colors.Normalize* object which
|
|
551
|
+
initializes its scaling based on the first data processed.
|
|
552
|
+
cmap : str or `~matplotlib.colors.Colormap`
|
|
553
|
+
The colormap used to map normalized data values to RGBA colors.
|
|
554
|
+
"""
|
|
555
|
+
super().__init__(**kwargs)
|
|
556
|
+
self._A = None
|
|
557
|
+
self._colorizer = self._get_colorizer(colorizer=colorizer, norm=norm, cmap=cmap)
|
|
558
|
+
|
|
559
|
+
self.colorbar = None
|
|
560
|
+
self._id_colorizer = self._colorizer.callbacks.connect('changed', self.changed)
|
|
561
|
+
self.callbacks = cbook.CallbackRegistry(signals=["changed"])
|
|
562
|
+
|
|
563
|
+
def set_array(self, A):
|
|
564
|
+
"""
|
|
565
|
+
Set the value array from array-like *A*.
|
|
566
|
+
|
|
567
|
+
Parameters
|
|
568
|
+
----------
|
|
569
|
+
A : array-like or None
|
|
570
|
+
The values that are mapped to colors.
|
|
571
|
+
|
|
572
|
+
The base class `.ScalarMappable` does not make any assumptions on
|
|
573
|
+
the dimensionality and shape of the value array *A*.
|
|
574
|
+
"""
|
|
575
|
+
if A is None:
|
|
576
|
+
self._A = None
|
|
577
|
+
return
|
|
578
|
+
|
|
579
|
+
A = _ensure_multivariate_data(A, self.norm.n_components)
|
|
580
|
+
|
|
581
|
+
A = cbook.safe_masked_invalid(A, copy=True)
|
|
582
|
+
if not np.can_cast(A.dtype, float, "same_kind"):
|
|
583
|
+
if A.dtype.fields is None:
|
|
584
|
+
|
|
585
|
+
raise TypeError(f"Image data of dtype {A.dtype} cannot be "
|
|
586
|
+
f"converted to float")
|
|
587
|
+
else:
|
|
588
|
+
for key in A.dtype.fields:
|
|
589
|
+
if not np.can_cast(A[key].dtype, float, "same_kind"):
|
|
590
|
+
raise TypeError(f"Image data of dtype {A.dtype} cannot be "
|
|
591
|
+
f"converted to a sequence of floats")
|
|
592
|
+
self._A = A
|
|
593
|
+
if not self.norm.scaled():
|
|
594
|
+
self._colorizer.autoscale_None(A)
|
|
595
|
+
|
|
596
|
+
def get_array(self):
|
|
597
|
+
"""
|
|
598
|
+
Return the array of values, that are mapped to colors.
|
|
599
|
+
|
|
600
|
+
The base class `.ScalarMappable` does not make any assumptions on
|
|
601
|
+
the dimensionality and shape of the array.
|
|
602
|
+
"""
|
|
603
|
+
return self._A
|
|
604
|
+
|
|
605
|
+
def changed(self):
|
|
606
|
+
"""
|
|
607
|
+
Call this whenever the mappable is changed to notify all the
|
|
608
|
+
callbackSM listeners to the 'changed' signal.
|
|
609
|
+
"""
|
|
610
|
+
self.callbacks.process('changed', self)
|
|
611
|
+
self.stale = True
|
|
612
|
+
|
|
613
|
+
@staticmethod
|
|
614
|
+
def _check_exclusionary_keywords(colorizer, **kwargs):
|
|
615
|
+
"""
|
|
616
|
+
Raises a ValueError if any kwarg is not None while colorizer is not None
|
|
617
|
+
"""
|
|
618
|
+
if colorizer is not None:
|
|
619
|
+
if any([val is not None for val in kwargs.values()]):
|
|
620
|
+
raise ValueError("The `colorizer` keyword cannot be used simultaneously"
|
|
621
|
+
" with any of the following keywords: "
|
|
622
|
+
+ ", ".join(f'`{key}`' for key in kwargs.keys()))
|
|
623
|
+
|
|
624
|
+
@staticmethod
|
|
625
|
+
def _get_colorizer(cmap, norm, colorizer):
|
|
626
|
+
if isinstance(colorizer, Colorizer):
|
|
627
|
+
_ScalarMappable._check_exclusionary_keywords(
|
|
628
|
+
Colorizer, cmap=cmap, norm=norm
|
|
629
|
+
)
|
|
630
|
+
return colorizer
|
|
631
|
+
return Colorizer(cmap, norm)
|
|
632
|
+
|
|
633
|
+
# The docstrings here must be generic enough to apply to all relevant methods.
|
|
634
|
+
mpl._docstring.interpd.register(
|
|
635
|
+
cmap_doc="""\
|
|
636
|
+
cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
|
|
637
|
+
The Colormap instance or registered colormap name used to map scalar data
|
|
638
|
+
to colors.""",
|
|
639
|
+
multi_cmap_doc="""\
|
|
640
|
+
cmap : str, `~matplotlib.colors.Colormap`, `~matplotlib.colors.BivarColormap`\
|
|
641
|
+
or `~matplotlib.colors.MultivarColormap`, default: :rc:`image.cmap`
|
|
642
|
+
The Colormap instance or registered colormap name used to map
|
|
643
|
+
data values to colors.
|
|
644
|
+
|
|
645
|
+
Multivariate data is only accepted if a multivariate colormap
|
|
646
|
+
(`~matplotlib.colors.BivarColormap` or `~matplotlib.colors.MultivarColormap`)
|
|
647
|
+
is used.""",
|
|
648
|
+
norm_doc="""\
|
|
649
|
+
norm : str or `~matplotlib.colors.Normalize`, optional
|
|
650
|
+
The normalization method used to scale scalar data to the [0, 1] range
|
|
651
|
+
before mapping to colors using *cmap*. By default, a linear scaling is
|
|
652
|
+
used, mapping the lowest value to 0 and the highest to 1.
|
|
653
|
+
|
|
654
|
+
If given, this can be one of the following:
|
|
655
|
+
|
|
656
|
+
- An instance of `.Normalize` or one of its subclasses
|
|
657
|
+
(see :ref:`colormapnorms`).
|
|
658
|
+
- A scale name, i.e. one of "linear", "log", "symlog", "logit", etc. For a
|
|
659
|
+
list of available scales, call `matplotlib.scale.get_scale_names()`.
|
|
660
|
+
In that case, a suitable `.Normalize` subclass is dynamically generated
|
|
661
|
+
and instantiated.""",
|
|
662
|
+
multi_norm_doc="""\
|
|
663
|
+
norm : str, `~matplotlib.colors.Normalize` or list, optional
|
|
664
|
+
The normalization method used to scale data to the [0, 1] range
|
|
665
|
+
before mapping to colors using *cmap*. By default, a linear scaling is
|
|
666
|
+
used, mapping the lowest value to 0 and the highest to 1.
|
|
667
|
+
This can be one of the following:
|
|
668
|
+
- An instance of `.Normalize` or one of its subclasses
|
|
669
|
+
(see :ref:`colormapnorms`).
|
|
670
|
+
- A scale name, i.e. one of "linear", "log", "symlog", "logit", etc. For a
|
|
671
|
+
list of available scales, call `matplotlib.scale.get_scale_names()`.
|
|
672
|
+
In this case, a suitable `.Normalize` subclass is dynamically generated
|
|
673
|
+
and instantiated.
|
|
674
|
+
- A list of scale names or `.Normalize` objects matching the number of
|
|
675
|
+
variates in the colormap, for use with `~matplotlib.colors.BivarColormap`
|
|
676
|
+
or `~matplotlib.colors.MultivarColormap`, i.e. ``["linear", "log"]``.""",
|
|
677
|
+
vmin_vmax_doc="""\
|
|
678
|
+
vmin, vmax : float, optional
|
|
679
|
+
When using scalar data and no explicit *norm*, *vmin* and *vmax* define
|
|
680
|
+
the data range that the colormap covers. By default, the colormap covers
|
|
681
|
+
the complete value range of the supplied data. It is an error to use
|
|
682
|
+
*vmin*/*vmax* when a *norm* instance is given (but using a `str` *norm*
|
|
683
|
+
name together with *vmin*/*vmax* is acceptable).""",
|
|
684
|
+
multi_vmin_vmax_doc="""\
|
|
685
|
+
vmin, vmax : float or list, optional
|
|
686
|
+
When using scalar data and no explicit *norm*, *vmin* and *vmax* define
|
|
687
|
+
the data range that the colormap covers. By default, the colormap covers
|
|
688
|
+
the complete value range of the supplied data. It is an error to use
|
|
689
|
+
*vmin*/*vmax* when a *norm* instance is given (but using a `str` *norm*
|
|
690
|
+
name together with *vmin*/*vmax* is acceptable).
|
|
691
|
+
|
|
692
|
+
A list of values (vmin or vmax) can be used to define independent limits
|
|
693
|
+
for each variate when using a `~matplotlib.colors.BivarColormap` or
|
|
694
|
+
`~matplotlib.colors.MultivarColormap`.""",
|
|
695
|
+
)
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
class ColorizingArtist(_ScalarMappable, artist.Artist):
|
|
699
|
+
"""
|
|
700
|
+
Base class for artists that make map data to color using a `.colorizer.Colorizer`.
|
|
701
|
+
|
|
702
|
+
The `.colorizer.Colorizer` applies data normalization before
|
|
703
|
+
returning RGBA colors from a `~matplotlib.colors.Colormap`.
|
|
704
|
+
|
|
705
|
+
"""
|
|
706
|
+
def __init__(self, colorizer, **kwargs):
|
|
707
|
+
"""
|
|
708
|
+
Parameters
|
|
709
|
+
----------
|
|
710
|
+
colorizer : `.colorizer.Colorizer`
|
|
711
|
+
"""
|
|
712
|
+
_api.check_isinstance(Colorizer, colorizer=colorizer)
|
|
713
|
+
super().__init__(colorizer=colorizer, **kwargs)
|
|
714
|
+
|
|
715
|
+
@property
|
|
716
|
+
def colorizer(self):
|
|
717
|
+
return self._colorizer
|
|
718
|
+
|
|
719
|
+
@colorizer.setter
|
|
720
|
+
def colorizer(self, cl):
|
|
721
|
+
_api.check_isinstance(Colorizer, colorizer=cl)
|
|
722
|
+
self._colorizer.callbacks.disconnect(self._id_colorizer)
|
|
723
|
+
self._colorizer = cl
|
|
724
|
+
self._id_colorizer = cl.callbacks.connect('changed', self.changed)
|
|
725
|
+
|
|
726
|
+
def _set_colorizer_check_keywords(self, colorizer, **kwargs):
|
|
727
|
+
"""
|
|
728
|
+
Raises a ValueError if any kwarg is not None while colorizer is not None.
|
|
729
|
+
"""
|
|
730
|
+
self._check_exclusionary_keywords(colorizer, **kwargs)
|
|
731
|
+
self.colorizer = colorizer
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
def _auto_norm_from_scale(scale_cls):
|
|
735
|
+
"""
|
|
736
|
+
Automatically generate a norm class from *scale_cls*.
|
|
737
|
+
|
|
738
|
+
This differs from `.colors.make_norm_from_scale` in the following points:
|
|
739
|
+
|
|
740
|
+
- This function is not a class decorator, but directly returns a norm class
|
|
741
|
+
(as if decorating `.Normalize`).
|
|
742
|
+
- The scale is automatically constructed with ``nonpositive="mask"``, if it
|
|
743
|
+
supports such a parameter, to work around the difference in defaults
|
|
744
|
+
between standard scales (which use "clip") and norms (which use "mask").
|
|
745
|
+
|
|
746
|
+
Note that ``make_norm_from_scale`` caches the generated norm classes
|
|
747
|
+
(not the instances) and reuses them for later calls. For example,
|
|
748
|
+
``type(_auto_norm_from_scale("log")) == LogNorm``.
|
|
749
|
+
"""
|
|
750
|
+
# Actually try to construct an instance, to verify whether
|
|
751
|
+
# ``nonpositive="mask"`` is supported.
|
|
752
|
+
try:
|
|
753
|
+
norm = colors.make_norm_from_scale(
|
|
754
|
+
functools.partial(scale_cls, nonpositive="mask"))(
|
|
755
|
+
colors.Normalize)()
|
|
756
|
+
except TypeError:
|
|
757
|
+
norm = colors.make_norm_from_scale(scale_cls)(
|
|
758
|
+
colors.Normalize)()
|
|
759
|
+
return type(norm)
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
def _ensure_norm(norm, n_components=1):
|
|
763
|
+
if n_components == 1:
|
|
764
|
+
_api.check_isinstance((colors.Norm, str, None), norm=norm)
|
|
765
|
+
if norm is None:
|
|
766
|
+
norm = colors.Normalize()
|
|
767
|
+
elif isinstance(norm, str):
|
|
768
|
+
scale_cls = _api.getitem_checked(scale._scale_mapping, norm=norm)
|
|
769
|
+
return _auto_norm_from_scale(scale_cls)()
|
|
770
|
+
return norm
|
|
771
|
+
elif n_components > 1:
|
|
772
|
+
if not np.iterable(norm):
|
|
773
|
+
_api.check_isinstance((colors.MultiNorm, None, tuple), norm=norm)
|
|
774
|
+
if norm is None:
|
|
775
|
+
norm = colors.MultiNorm(['linear']*n_components)
|
|
776
|
+
else: # iterable, i.e. multiple strings or Normalize objects
|
|
777
|
+
norm = colors.MultiNorm(norm)
|
|
778
|
+
if isinstance(norm, colors.MultiNorm) and norm.n_components == n_components:
|
|
779
|
+
return norm
|
|
780
|
+
raise ValueError(
|
|
781
|
+
f"Invalid norm for multivariate colormap with {n_components} inputs")
|
|
782
|
+
else: # n_components == 0
|
|
783
|
+
raise ValueError(
|
|
784
|
+
"Invalid cmap. A colorizer object must have a cmap with `n_variates` >= 1")
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
def _ensure_cmap(cmap, accept_multivariate=False):
|
|
788
|
+
"""
|
|
789
|
+
Ensure that we have a `.Colormap` object.
|
|
790
|
+
|
|
791
|
+
For internal use to preserve type stability of errors.
|
|
792
|
+
|
|
793
|
+
Parameters
|
|
794
|
+
----------
|
|
795
|
+
cmap : None, str, Colormap
|
|
796
|
+
|
|
797
|
+
- if a `~matplotlib.colors.Colormap`,
|
|
798
|
+
`~matplotlib.colors.MultivarColormap` or
|
|
799
|
+
`~matplotlib.colors.BivarColormap`,
|
|
800
|
+
return it
|
|
801
|
+
- if a string, look it up in three corresponding databases
|
|
802
|
+
when not found: raise an error based on the expected shape
|
|
803
|
+
- if None, look up the default color map in mpl.colormaps
|
|
804
|
+
accept_multivariate : bool, default False
|
|
805
|
+
- if False, accept only Colormap, string in mpl.colormaps or None
|
|
806
|
+
|
|
807
|
+
Returns
|
|
808
|
+
-------
|
|
809
|
+
Colormap
|
|
810
|
+
|
|
811
|
+
"""
|
|
812
|
+
if accept_multivariate:
|
|
813
|
+
types = (colors.Colormap, colors.BivarColormap, colors.MultivarColormap)
|
|
814
|
+
mappings = (mpl.colormaps, mpl.multivar_colormaps, mpl.bivar_colormaps)
|
|
815
|
+
else:
|
|
816
|
+
types = (colors.Colormap, )
|
|
817
|
+
mappings = (mpl.colormaps, )
|
|
818
|
+
|
|
819
|
+
if isinstance(cmap, types):
|
|
820
|
+
return cmap
|
|
821
|
+
|
|
822
|
+
cmap_name = mpl._val_or_rc(cmap, "image.cmap")
|
|
823
|
+
|
|
824
|
+
for mapping in mappings:
|
|
825
|
+
if cmap_name in mapping:
|
|
826
|
+
return mapping[cmap_name]
|
|
827
|
+
|
|
828
|
+
# this error message is a variant of _api.check_in_list but gives
|
|
829
|
+
# additional hints as to how to access multivariate colormaps
|
|
830
|
+
|
|
831
|
+
raise ValueError(_api.list_suggestion_error_msg('cmap', cmap, mpl.colormaps) +
|
|
832
|
+
"\nSee `matplotlib.bivar_colormaps()` and"
|
|
833
|
+
" `matplotlib.multivar_colormaps()` for"
|
|
834
|
+
" bivariate and multivariate colormaps")
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
def _ensure_multivariate_data(data, n_components):
|
|
838
|
+
"""
|
|
839
|
+
Ensure that the data has dtype with n_components.
|
|
840
|
+
Input data of shape (n_components, n, m) is converted to an array of shape
|
|
841
|
+
(n, m) with data type np.dtype(f'{data.dtype}, ' * n_components)
|
|
842
|
+
Complex data is returned as a view with dtype np.dtype('float64, float64')
|
|
843
|
+
or np.dtype('float32, float32')
|
|
844
|
+
If n_components is 1 and data is not of type np.ndarray (i.e. PIL.Image),
|
|
845
|
+
the data is returned unchanged.
|
|
846
|
+
If data is None, the function returns None
|
|
847
|
+
|
|
848
|
+
Parameters
|
|
849
|
+
----------
|
|
850
|
+
n_components : int
|
|
851
|
+
Number of variates in the data.
|
|
852
|
+
data : np.ndarray, PIL.Image or None
|
|
853
|
+
|
|
854
|
+
Returns
|
|
855
|
+
-------
|
|
856
|
+
np.ndarray, PIL.Image or None
|
|
857
|
+
"""
|
|
858
|
+
|
|
859
|
+
if isinstance(data, np.ndarray):
|
|
860
|
+
if len(data.dtype.descr) == n_components:
|
|
861
|
+
# pass scalar data
|
|
862
|
+
# and already formatted data
|
|
863
|
+
return data
|
|
864
|
+
elif data.dtype in [np.complex64, np.complex128]:
|
|
865
|
+
if n_components != 2:
|
|
866
|
+
raise ValueError("Invalid data entry for multivariate data. "
|
|
867
|
+
"Complex numbers are incompatible with "
|
|
868
|
+
f"{n_components} variates.")
|
|
869
|
+
|
|
870
|
+
# pass complex data
|
|
871
|
+
if data.dtype == np.complex128:
|
|
872
|
+
dt = np.dtype('float64, float64')
|
|
873
|
+
else:
|
|
874
|
+
dt = np.dtype('float32, float32')
|
|
875
|
+
|
|
876
|
+
reconstructed = np.ma.array(np.ma.getdata(data).view(dt))
|
|
877
|
+
if np.ma.is_masked(data):
|
|
878
|
+
for descriptor in dt.descr:
|
|
879
|
+
reconstructed[descriptor[0]][data.mask] = np.ma.masked
|
|
880
|
+
return reconstructed
|
|
881
|
+
|
|
882
|
+
if n_components > 1 and len(data) == n_components:
|
|
883
|
+
# convert data from shape (n_components, n, m)
|
|
884
|
+
# to (n, m) with a new dtype
|
|
885
|
+
data = [np.ma.array(part, copy=False) for part in data]
|
|
886
|
+
dt = np.dtype(', '.join([f'{part.dtype}' for part in data]))
|
|
887
|
+
fields = [descriptor[0] for descriptor in dt.descr]
|
|
888
|
+
reconstructed = np.ma.empty(data[0].shape, dtype=dt)
|
|
889
|
+
for i, f in enumerate(fields):
|
|
890
|
+
if data[i].shape != reconstructed.shape:
|
|
891
|
+
raise ValueError("For multivariate data all variates must have same "
|
|
892
|
+
f"shape, not {data[0].shape} and {data[i].shape}")
|
|
893
|
+
reconstructed[f] = data[i]
|
|
894
|
+
if np.ma.is_masked(data[i]):
|
|
895
|
+
reconstructed[f][data[i].mask] = np.ma.masked
|
|
896
|
+
return reconstructed
|
|
897
|
+
|
|
898
|
+
if n_components == 1:
|
|
899
|
+
# PIL.Image gets passed here
|
|
900
|
+
return data
|
|
901
|
+
|
|
902
|
+
elif n_components == 2:
|
|
903
|
+
raise ValueError("Invalid data entry for multivariate data. The data"
|
|
904
|
+
" must contain complex numbers, or have a first dimension 2,"
|
|
905
|
+
" or be of a dtype with 2 fields")
|
|
906
|
+
else:
|
|
907
|
+
raise ValueError("Invalid data entry for multivariate data. The shape"
|
|
908
|
+
f" of the data must have a first dimension {n_components}"
|
|
909
|
+
f" or be of a dtype with {n_components} fields")
|