matplotlib-rs 0.0.8__cp315-cp315-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.cp315-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,1758 @@
|
|
|
1
|
+
# Vendored from matplotlib 3.11 (see licenses/LICENSE_MATPLOTLIB), adapted for matplotlib_rs.
|
|
2
|
+
# art3d.py, original mplot3d version by John Porter
|
|
3
|
+
# Parts rewritten by Reinier Heeres <reinier@heeres.eu>
|
|
4
|
+
# Minor additions by Ben Axelrod <baxelrod@coroware.com>
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
Module containing 3D artist code and functions to convert 2D
|
|
8
|
+
artists into 3D versions which can be added to an Axes3D.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import math
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
|
|
15
|
+
from contextlib import contextmanager
|
|
16
|
+
|
|
17
|
+
from matplotlib_rs import (
|
|
18
|
+
_api, artist, cbook, colors as mcolors, lines, text as mtext,
|
|
19
|
+
path as mpath, rcParams)
|
|
20
|
+
from matplotlib_rs.collections import (
|
|
21
|
+
Collection, LineCollection, PolyCollection, PatchCollection, PathCollection)
|
|
22
|
+
from matplotlib_rs.patches import Patch
|
|
23
|
+
from . import proj3d
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _norm_angle(a):
|
|
27
|
+
"""Return the given angle normalized to -180 < *a* <= 180 degrees."""
|
|
28
|
+
a = (a + 360) % 360
|
|
29
|
+
if a > 180:
|
|
30
|
+
a = a - 360
|
|
31
|
+
return a
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _norm_text_angle(a):
|
|
35
|
+
"""Return the given angle normalized to -90 < *a* <= 90 degrees."""
|
|
36
|
+
a = (a + 180) % 180
|
|
37
|
+
if a > 90:
|
|
38
|
+
a = a - 180
|
|
39
|
+
return a
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def get_dir_vector(zdir):
|
|
43
|
+
"""
|
|
44
|
+
Return a direction vector.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
zdir : {'x', 'y', 'z', None, 3-tuple}
|
|
49
|
+
The direction. Possible values are:
|
|
50
|
+
|
|
51
|
+
- 'x': equivalent to (1, 0, 0)
|
|
52
|
+
- 'y': equivalent to (0, 1, 0)
|
|
53
|
+
- 'z': equivalent to (0, 0, 1)
|
|
54
|
+
- *None*: equivalent to (0, 0, 0)
|
|
55
|
+
- an iterable (x, y, z) is converted to an array
|
|
56
|
+
|
|
57
|
+
Returns
|
|
58
|
+
-------
|
|
59
|
+
x, y, z : array
|
|
60
|
+
The direction vector.
|
|
61
|
+
"""
|
|
62
|
+
if cbook._str_equal(zdir, 'x'):
|
|
63
|
+
return np.array((1, 0, 0))
|
|
64
|
+
elif cbook._str_equal(zdir, 'y'):
|
|
65
|
+
return np.array((0, 1, 0))
|
|
66
|
+
elif cbook._str_equal(zdir, 'z'):
|
|
67
|
+
return np.array((0, 0, 1))
|
|
68
|
+
elif zdir is None:
|
|
69
|
+
return np.array((0, 0, 0))
|
|
70
|
+
elif np.iterable(zdir) and len(zdir) == 3:
|
|
71
|
+
return np.array(zdir)
|
|
72
|
+
else:
|
|
73
|
+
raise ValueError("'x', 'y', 'z', None or vector of length 3 expected")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _viewlim_mask(xs, ys, zs, axes):
|
|
77
|
+
"""
|
|
78
|
+
Return the mask of the points outside the axes view limits.
|
|
79
|
+
|
|
80
|
+
Parameters
|
|
81
|
+
----------
|
|
82
|
+
xs, ys, zs : array-like
|
|
83
|
+
The points to mask. These should be in data coordinates.
|
|
84
|
+
axes : Axes3D
|
|
85
|
+
The axes to use for the view limits.
|
|
86
|
+
|
|
87
|
+
Returns
|
|
88
|
+
-------
|
|
89
|
+
mask : np.array
|
|
90
|
+
The mask of the points as a bool array.
|
|
91
|
+
"""
|
|
92
|
+
mask = np.logical_or.reduce((xs < axes.xy_viewLim.xmin,
|
|
93
|
+
xs > axes.xy_viewLim.xmax,
|
|
94
|
+
ys < axes.xy_viewLim.ymin,
|
|
95
|
+
ys > axes.xy_viewLim.ymax,
|
|
96
|
+
zs < axes.zz_viewLim.xmin,
|
|
97
|
+
zs > axes.zz_viewLim.xmax))
|
|
98
|
+
return mask
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _scale_invalid_mask(xs, ys, zs, axes):
|
|
102
|
+
"""
|
|
103
|
+
Return the mask of points whose coordinates are invalid for the axis
|
|
104
|
+
scale they live on (e.g. <=0 on a log axis).
|
|
105
|
+
|
|
106
|
+
Parameters
|
|
107
|
+
----------
|
|
108
|
+
xs, ys, zs : array-like
|
|
109
|
+
The points to check, in data coordinates.
|
|
110
|
+
axes : Axes3D
|
|
111
|
+
The axes whose scales are queried.
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
mask : np.ndarray
|
|
116
|
+
Boolean array, ``True`` where any of x/y/z is out of its scale's
|
|
117
|
+
valid domain.
|
|
118
|
+
"""
|
|
119
|
+
return np.logical_or.reduce((
|
|
120
|
+
np.logical_not(axes.xaxis._scale.val_in_range(xs)),
|
|
121
|
+
np.logical_not(axes.yaxis._scale.val_in_range(ys)),
|
|
122
|
+
np.logical_not(axes.zaxis._scale.val_in_range(zs))))
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class Text3D(mtext.Text):
|
|
126
|
+
"""
|
|
127
|
+
Text object with 3D position and direction.
|
|
128
|
+
|
|
129
|
+
Parameters
|
|
130
|
+
----------
|
|
131
|
+
x, y, z : float
|
|
132
|
+
The position of the text.
|
|
133
|
+
text : str
|
|
134
|
+
The text string to display.
|
|
135
|
+
zdir : {'x', 'y', 'z', None, 3-tuple}
|
|
136
|
+
The direction of the text. See `.get_dir_vector` for a description of
|
|
137
|
+
the values.
|
|
138
|
+
axlim_clip : bool, default: False
|
|
139
|
+
Whether to hide text outside the axes view limits.
|
|
140
|
+
|
|
141
|
+
.. versionadded:: 3.10
|
|
142
|
+
|
|
143
|
+
Other Parameters
|
|
144
|
+
----------------
|
|
145
|
+
**kwargs
|
|
146
|
+
All other parameters are passed on to `~matplotlib.text.Text`.
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
def __init__(self, x=0, y=0, z=0, text='', zdir='z', axlim_clip=False,
|
|
150
|
+
**kwargs):
|
|
151
|
+
if 'rotation' in kwargs:
|
|
152
|
+
_api.warn_external(
|
|
153
|
+
"The `rotation` parameter has not yet been implemented "
|
|
154
|
+
"and is currently ignored."
|
|
155
|
+
)
|
|
156
|
+
if 'rotation_mode' in kwargs:
|
|
157
|
+
_api.warn_external(
|
|
158
|
+
"The `rotation_mode` parameter has not yet been implemented "
|
|
159
|
+
"and is currently ignored."
|
|
160
|
+
)
|
|
161
|
+
mtext.Text.__init__(self, x, y, text, **kwargs)
|
|
162
|
+
self.set_3d_properties(z, zdir, axlim_clip)
|
|
163
|
+
|
|
164
|
+
def get_position_3d(self):
|
|
165
|
+
"""Return the (x, y, z) position of the text."""
|
|
166
|
+
return self._x, self._y, self._z
|
|
167
|
+
|
|
168
|
+
def set_position_3d(self, xyz, zdir=None):
|
|
169
|
+
"""
|
|
170
|
+
Set the (*x*, *y*, *z*) position of the text.
|
|
171
|
+
|
|
172
|
+
Parameters
|
|
173
|
+
----------
|
|
174
|
+
xyz : (float, float, float)
|
|
175
|
+
The position in 3D space.
|
|
176
|
+
zdir : {'x', 'y', 'z', None, 3-tuple}
|
|
177
|
+
The direction of the text. If unspecified, the *zdir* will not be
|
|
178
|
+
changed. See `.get_dir_vector` for a description of the values.
|
|
179
|
+
"""
|
|
180
|
+
super().set_position(xyz[:2])
|
|
181
|
+
self.set_z(xyz[2])
|
|
182
|
+
if zdir is not None:
|
|
183
|
+
self._dir_vec = get_dir_vector(zdir)
|
|
184
|
+
|
|
185
|
+
def set_z(self, z):
|
|
186
|
+
"""
|
|
187
|
+
Set the *z* position of the text.
|
|
188
|
+
|
|
189
|
+
Parameters
|
|
190
|
+
----------
|
|
191
|
+
z : float
|
|
192
|
+
"""
|
|
193
|
+
self._z = z
|
|
194
|
+
self.stale = True
|
|
195
|
+
|
|
196
|
+
def set_3d_properties(self, z=0, zdir='z', axlim_clip=False):
|
|
197
|
+
"""
|
|
198
|
+
Set the *z* position and direction of the text.
|
|
199
|
+
|
|
200
|
+
Parameters
|
|
201
|
+
----------
|
|
202
|
+
z : float
|
|
203
|
+
The z-position in 3D space.
|
|
204
|
+
zdir : {'x', 'y', 'z', 3-tuple}
|
|
205
|
+
The direction of the text. Default: 'z'.
|
|
206
|
+
See `.get_dir_vector` for a description of the values.
|
|
207
|
+
axlim_clip : bool, default: False
|
|
208
|
+
Whether to hide text outside the axes view limits.
|
|
209
|
+
|
|
210
|
+
.. versionadded:: 3.10
|
|
211
|
+
"""
|
|
212
|
+
self._z = z
|
|
213
|
+
self._dir_vec = get_dir_vector(zdir)
|
|
214
|
+
self._axlim_clip = axlim_clip
|
|
215
|
+
self.stale = True
|
|
216
|
+
|
|
217
|
+
@artist.allow_rasterization
|
|
218
|
+
def draw(self, renderer):
|
|
219
|
+
mask = _scale_invalid_mask(self._x, self._y, self._z, self.axes)
|
|
220
|
+
if self._axlim_clip:
|
|
221
|
+
mask |= _viewlim_mask(self._x, self._y, self._z, self.axes)
|
|
222
|
+
if np.any(mask):
|
|
223
|
+
pos3d = np.ma.array([self._x, self._y, self._z],
|
|
224
|
+
mask=mask, dtype=float).filled(np.nan)
|
|
225
|
+
else:
|
|
226
|
+
pos3d = np.array([self._x, self._y, self._z], dtype=float)
|
|
227
|
+
|
|
228
|
+
dir_end = pos3d + self._dir_vec
|
|
229
|
+
points = np.asarray([pos3d, dir_end])
|
|
230
|
+
proj = proj3d._scale_proj_transform(
|
|
231
|
+
points[:, 0], points[:, 1], points[:, 2], self.axes)
|
|
232
|
+
dx = proj[0][1] - proj[0][0]
|
|
233
|
+
dy = proj[1][1] - proj[1][0]
|
|
234
|
+
angle = math.degrees(math.atan2(dy, dx))
|
|
235
|
+
with cbook._setattr_cm(self, _x=proj[0][0], _y=proj[1][0],
|
|
236
|
+
_rotation=_norm_text_angle(angle)):
|
|
237
|
+
mtext.Text.draw(self, renderer)
|
|
238
|
+
self.stale = False
|
|
239
|
+
|
|
240
|
+
def get_tightbbox(self, renderer=None):
|
|
241
|
+
# Overwriting the 2d Text behavior which is not valid for 3d.
|
|
242
|
+
# For now, just return None to exclude from layout calculation.
|
|
243
|
+
return None
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def text_2d_to_3d(obj, z=0, zdir='z', axlim_clip=False):
|
|
247
|
+
"""
|
|
248
|
+
Convert a `.Text` to a `.Text3D` object.
|
|
249
|
+
|
|
250
|
+
Parameters
|
|
251
|
+
----------
|
|
252
|
+
z : float
|
|
253
|
+
The z-position in 3D space.
|
|
254
|
+
zdir : {'x', 'y', 'z', 3-tuple}
|
|
255
|
+
The direction of the text. Default: 'z'.
|
|
256
|
+
See `.get_dir_vector` for a description of the values.
|
|
257
|
+
axlim_clip : bool, default: False
|
|
258
|
+
Whether to hide text outside the axes view limits.
|
|
259
|
+
|
|
260
|
+
.. versionadded:: 3.10
|
|
261
|
+
"""
|
|
262
|
+
obj.__class__ = Text3D
|
|
263
|
+
obj.set_3d_properties(z, zdir, axlim_clip)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
class Line3D(lines.Line2D):
|
|
267
|
+
"""
|
|
268
|
+
3D line object.
|
|
269
|
+
|
|
270
|
+
.. note:: Use `get_data_3d` to obtain the data associated with the line.
|
|
271
|
+
`~.Line2D.get_data`, `~.Line2D.get_xdata`, and `~.Line2D.get_ydata` return
|
|
272
|
+
the x- and y-coordinates of the projected 2D-line, not the x- and y-data of
|
|
273
|
+
the 3D-line. Similarly, use `set_data_3d` to set the data, not
|
|
274
|
+
`~.Line2D.set_data`, `~.Line2D.set_xdata`, and `~.Line2D.set_ydata`.
|
|
275
|
+
"""
|
|
276
|
+
|
|
277
|
+
def __init__(self, xs, ys, zs, *args, axlim_clip=False, **kwargs):
|
|
278
|
+
"""
|
|
279
|
+
|
|
280
|
+
Parameters
|
|
281
|
+
----------
|
|
282
|
+
xs : array-like
|
|
283
|
+
The x-data to be plotted.
|
|
284
|
+
ys : array-like
|
|
285
|
+
The y-data to be plotted.
|
|
286
|
+
zs : array-like
|
|
287
|
+
The z-data to be plotted.
|
|
288
|
+
*args, **kwargs
|
|
289
|
+
Additional arguments are passed to `~matplotlib.lines.Line2D`.
|
|
290
|
+
"""
|
|
291
|
+
super().__init__([], [], *args, **kwargs)
|
|
292
|
+
self.set_data_3d(xs, ys, zs)
|
|
293
|
+
self._axlim_clip = axlim_clip
|
|
294
|
+
|
|
295
|
+
def set_3d_properties(self, zs=0, zdir='z', axlim_clip=False):
|
|
296
|
+
"""
|
|
297
|
+
Set the *z* position and direction of the line.
|
|
298
|
+
|
|
299
|
+
Parameters
|
|
300
|
+
----------
|
|
301
|
+
zs : float or array of floats
|
|
302
|
+
The location along the *zdir* axis in 3D space to position the
|
|
303
|
+
line.
|
|
304
|
+
zdir : {'x', 'y', 'z'}
|
|
305
|
+
Plane to plot line orthogonal to. Default: 'z'.
|
|
306
|
+
See `.get_dir_vector` for a description of the values.
|
|
307
|
+
axlim_clip : bool, default: False
|
|
308
|
+
Whether to hide lines with an endpoint outside the axes view limits.
|
|
309
|
+
|
|
310
|
+
.. versionadded:: 3.10
|
|
311
|
+
"""
|
|
312
|
+
xs = self.get_xdata()
|
|
313
|
+
ys = self.get_ydata()
|
|
314
|
+
zs = cbook._to_unmasked_float_array(zs).ravel()
|
|
315
|
+
zs = np.broadcast_to(zs, len(xs))
|
|
316
|
+
self._verts3d = juggle_axes(xs, ys, zs, zdir)
|
|
317
|
+
self._axlim_clip = axlim_clip
|
|
318
|
+
self.stale = True
|
|
319
|
+
|
|
320
|
+
def set_data_3d(self, *args):
|
|
321
|
+
"""
|
|
322
|
+
Set the x, y and z data
|
|
323
|
+
|
|
324
|
+
Parameters
|
|
325
|
+
----------
|
|
326
|
+
x : array-like
|
|
327
|
+
The x-data to be plotted.
|
|
328
|
+
y : array-like
|
|
329
|
+
The y-data to be plotted.
|
|
330
|
+
z : array-like
|
|
331
|
+
The z-data to be plotted.
|
|
332
|
+
|
|
333
|
+
Notes
|
|
334
|
+
-----
|
|
335
|
+
Accepts x, y, z arguments or a single array-like (x, y, z)
|
|
336
|
+
"""
|
|
337
|
+
if len(args) == 1:
|
|
338
|
+
args = args[0]
|
|
339
|
+
for name, xyz in zip('xyz', args):
|
|
340
|
+
if not np.iterable(xyz):
|
|
341
|
+
raise RuntimeError(f'{name} must be a sequence')
|
|
342
|
+
self._verts3d = args
|
|
343
|
+
self.stale = True
|
|
344
|
+
|
|
345
|
+
def get_data_3d(self):
|
|
346
|
+
"""
|
|
347
|
+
Get the current data
|
|
348
|
+
|
|
349
|
+
Returns
|
|
350
|
+
-------
|
|
351
|
+
verts3d : length-3 tuple or array-like
|
|
352
|
+
The current data as a tuple or array-like.
|
|
353
|
+
"""
|
|
354
|
+
return self._verts3d
|
|
355
|
+
|
|
356
|
+
@artist.allow_rasterization
|
|
357
|
+
def draw(self, renderer):
|
|
358
|
+
scale_mask = _scale_invalid_mask(*self._verts3d, self.axes)
|
|
359
|
+
if self._axlim_clip:
|
|
360
|
+
scale_mask |= _viewlim_mask(*self._verts3d, self.axes)
|
|
361
|
+
if np.any(scale_mask):
|
|
362
|
+
mask = np.broadcast_to(
|
|
363
|
+
scale_mask,
|
|
364
|
+
(len(self._verts3d), *self._verts3d[0].shape)
|
|
365
|
+
)
|
|
366
|
+
xs3d, ys3d, zs3d = np.ma.array(self._verts3d,
|
|
367
|
+
dtype=float, mask=mask).filled(np.nan)
|
|
368
|
+
else:
|
|
369
|
+
xs3d, ys3d, zs3d = self._verts3d
|
|
370
|
+
xs, ys, zs, tis = proj3d._scale_proj_transform_clip(xs3d, ys3d, zs3d, self.axes)
|
|
371
|
+
self.set_data(xs, ys)
|
|
372
|
+
super().draw(renderer)
|
|
373
|
+
self.stale = False
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def line_2d_to_3d(line, zs=0, zdir='z', axlim_clip=False):
|
|
377
|
+
"""
|
|
378
|
+
Convert a `.Line2D` to a `.Line3D` object.
|
|
379
|
+
|
|
380
|
+
Parameters
|
|
381
|
+
----------
|
|
382
|
+
zs : float
|
|
383
|
+
The location along the *zdir* axis in 3D space to position the line.
|
|
384
|
+
zdir : {'x', 'y', 'z'}
|
|
385
|
+
Plane to plot line orthogonal to. Default: 'z'.
|
|
386
|
+
See `.get_dir_vector` for a description of the values.
|
|
387
|
+
axlim_clip : bool, default: False
|
|
388
|
+
Whether to hide lines with an endpoint outside the axes view limits.
|
|
389
|
+
|
|
390
|
+
.. versionadded:: 3.10
|
|
391
|
+
"""
|
|
392
|
+
|
|
393
|
+
line.__class__ = Line3D
|
|
394
|
+
line.set_3d_properties(zs, zdir, axlim_clip)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def _path_to_3d_segment(path, zs=0, zdir='z'):
|
|
398
|
+
"""Convert a path to a 3D segment."""
|
|
399
|
+
|
|
400
|
+
zs = np.broadcast_to(zs, len(path))
|
|
401
|
+
pathsegs = path.iter_segments(simplify=False, curves=False)
|
|
402
|
+
seg = [(x, y, z) for (((x, y), code), z) in zip(pathsegs, zs)]
|
|
403
|
+
seg3d = [juggle_axes(x, y, z, zdir) for (x, y, z) in seg]
|
|
404
|
+
return seg3d
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def _paths_to_3d_segments(paths, zs=0, zdir='z'):
|
|
408
|
+
"""Convert paths from a collection object to 3D segments."""
|
|
409
|
+
|
|
410
|
+
if not np.iterable(zs):
|
|
411
|
+
zs = np.broadcast_to(zs, len(paths))
|
|
412
|
+
else:
|
|
413
|
+
if len(zs) != len(paths):
|
|
414
|
+
raise ValueError('Number of z-coordinates does not match paths.')
|
|
415
|
+
|
|
416
|
+
segs = [_path_to_3d_segment(path, pathz, zdir)
|
|
417
|
+
for path, pathz in zip(paths, zs)]
|
|
418
|
+
return segs
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
def _path_to_3d_segment_with_codes(path, zs=0, zdir='z'):
|
|
422
|
+
"""Convert a path to a 3D segment with path codes."""
|
|
423
|
+
|
|
424
|
+
zs = np.broadcast_to(zs, len(path))
|
|
425
|
+
pathsegs = path.iter_segments(simplify=False, curves=False)
|
|
426
|
+
seg_codes = [((x, y, z), code) for ((x, y), code), z in zip(pathsegs, zs)]
|
|
427
|
+
if seg_codes:
|
|
428
|
+
seg, codes = zip(*seg_codes)
|
|
429
|
+
seg3d = [juggle_axes(x, y, z, zdir) for (x, y, z) in seg]
|
|
430
|
+
else:
|
|
431
|
+
seg3d = []
|
|
432
|
+
codes = []
|
|
433
|
+
return seg3d, list(codes)
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def _paths_to_3d_segments_with_codes(paths, zs=0, zdir='z'):
|
|
437
|
+
"""
|
|
438
|
+
Convert paths from a collection object to 3D segments with path codes.
|
|
439
|
+
"""
|
|
440
|
+
|
|
441
|
+
zs = np.broadcast_to(zs, len(paths))
|
|
442
|
+
segments_codes = [_path_to_3d_segment_with_codes(path, pathz, zdir)
|
|
443
|
+
for path, pathz in zip(paths, zs)]
|
|
444
|
+
if segments_codes:
|
|
445
|
+
segments, codes = zip(*segments_codes)
|
|
446
|
+
else:
|
|
447
|
+
segments, codes = [], []
|
|
448
|
+
return list(segments), list(codes)
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
class Collection3D(Collection):
|
|
452
|
+
"""A collection of 3D paths."""
|
|
453
|
+
|
|
454
|
+
def do_3d_projection(self):
|
|
455
|
+
"""Project the points according to renderer matrix."""
|
|
456
|
+
vs_list = [vs for vs, _ in self._3dverts_codes]
|
|
457
|
+
masks = [_scale_invalid_mask(*vs.T, self.axes) for vs in vs_list]
|
|
458
|
+
if self._axlim_clip:
|
|
459
|
+
masks = [m | _viewlim_mask(*vs.T, self.axes)
|
|
460
|
+
for m, vs in zip(masks, vs_list)]
|
|
461
|
+
vs_list = [np.ma.array(vs, mask=np.broadcast_to(m, vs.shape))
|
|
462
|
+
if np.any(m) else vs
|
|
463
|
+
for vs, m in zip(vs_list, masks)]
|
|
464
|
+
xyzs_list = [proj3d._scale_proj_transform(
|
|
465
|
+
vs[:, 0], vs[:, 1], vs[:, 2], self.axes) for vs in vs_list]
|
|
466
|
+
self._paths = [mpath.Path(np.ma.column_stack([xs, ys]), cs)
|
|
467
|
+
for (xs, ys, _), (_, cs) in zip(xyzs_list, self._3dverts_codes)]
|
|
468
|
+
zs = np.concatenate([zs for _, _, zs in xyzs_list])
|
|
469
|
+
return zs.min() if len(zs) else 1e9
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def collection_2d_to_3d(col, zs=0, zdir='z', axlim_clip=False):
|
|
473
|
+
"""Convert a `.Collection` to a `.Collection3D` object."""
|
|
474
|
+
zs = np.broadcast_to(zs, len(col.get_paths()))
|
|
475
|
+
col._3dverts_codes = [
|
|
476
|
+
(np.column_stack(juggle_axes(
|
|
477
|
+
*np.column_stack([p.vertices, np.broadcast_to(z, len(p.vertices))]).T,
|
|
478
|
+
zdir)),
|
|
479
|
+
p.codes)
|
|
480
|
+
for p, z in zip(col.get_paths(), zs)]
|
|
481
|
+
col.__class__ = cbook._make_class_factory(Collection3D, "{}3D")(type(col))
|
|
482
|
+
col._axlim_clip = axlim_clip
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
class Line3DCollection(LineCollection):
|
|
486
|
+
"""
|
|
487
|
+
A collection of 3D lines.
|
|
488
|
+
"""
|
|
489
|
+
def __init__(self, lines, axlim_clip=False, **kwargs):
|
|
490
|
+
super().__init__(lines, **kwargs)
|
|
491
|
+
self._axlim_clip = axlim_clip
|
|
492
|
+
"""
|
|
493
|
+
Parameters
|
|
494
|
+
----------
|
|
495
|
+
lines : list of (N, 3) array-like
|
|
496
|
+
A sequence ``[line0, line1, ...]`` where each line is a (N, 3)-shape
|
|
497
|
+
array-like containing points:: line0 = [(x0, y0, z0), (x1, y1, z1), ...]
|
|
498
|
+
Each line can contain a different number of points.
|
|
499
|
+
linewidths : float or list of float, default: :rc:`lines.linewidth`
|
|
500
|
+
The width of each line in points.
|
|
501
|
+
colors : :mpltype:`color` or list of color, default: :rc:`lines.color`
|
|
502
|
+
A sequence of RGBA tuples (e.g., arbitrary color strings, etc, not
|
|
503
|
+
allowed).
|
|
504
|
+
antialiaseds : bool or list of bool, default: :rc:`lines.antialiased`
|
|
505
|
+
Whether to use antialiasing for each line.
|
|
506
|
+
facecolors : :mpltype:`color` or list of :mpltype:`color`, default: 'none'
|
|
507
|
+
When setting *facecolors*, each line is interpreted as a boundary
|
|
508
|
+
for an area, implicitly closing the path from the last point to the
|
|
509
|
+
first point. The enclosed area is filled with *facecolor*.
|
|
510
|
+
In order to manually specify what should count as the "interior" of
|
|
511
|
+
each line, please use `.PathCollection` instead, where the
|
|
512
|
+
"interior" can be specified by appropriate usage of
|
|
513
|
+
`~.path.Path.CLOSEPOLY`.
|
|
514
|
+
**kwargs : Forwarded to `.Collection`.
|
|
515
|
+
"""
|
|
516
|
+
|
|
517
|
+
def set_sort_zpos(self, val):
|
|
518
|
+
"""Set the position to use for z-sorting."""
|
|
519
|
+
self._sort_zpos = val
|
|
520
|
+
self.stale = True
|
|
521
|
+
|
|
522
|
+
def set_segments(self, segments):
|
|
523
|
+
"""
|
|
524
|
+
Set 3D segments.
|
|
525
|
+
"""
|
|
526
|
+
self._segments3d = segments
|
|
527
|
+
super().set_segments([])
|
|
528
|
+
|
|
529
|
+
def do_3d_projection(self):
|
|
530
|
+
"""
|
|
531
|
+
Project the points according to renderer matrix.
|
|
532
|
+
"""
|
|
533
|
+
segments = self._segments3d
|
|
534
|
+
|
|
535
|
+
# Handle ragged inputs, but prefer a faster path for same-length segments
|
|
536
|
+
segment_lengths = [len(segment) for segment in segments]
|
|
537
|
+
ragged = len(set(segment_lengths)) > 1
|
|
538
|
+
if ragged:
|
|
539
|
+
# Branch masked / non-masked for speed
|
|
540
|
+
if any(np.ma.isMA(segment) for segment in segments):
|
|
541
|
+
segments = np.ma.concatenate(segments)
|
|
542
|
+
else:
|
|
543
|
+
segments = np.concatenate(segments)
|
|
544
|
+
else:
|
|
545
|
+
segments = np.asanyarray(segments)
|
|
546
|
+
|
|
547
|
+
# Handle empty segments
|
|
548
|
+
if segments.size == 0:
|
|
549
|
+
LineCollection.set_segments(self, [])
|
|
550
|
+
return np.nan
|
|
551
|
+
|
|
552
|
+
mask = False
|
|
553
|
+
if np.ma.isMA(segments) and segments.mask is not np.ma.nomask:
|
|
554
|
+
mask = segments.mask
|
|
555
|
+
|
|
556
|
+
scale_mask = _scale_invalid_mask(segments[..., 0],
|
|
557
|
+
segments[..., 1],
|
|
558
|
+
segments[..., 2],
|
|
559
|
+
self.axes)
|
|
560
|
+
if np.any(scale_mask):
|
|
561
|
+
mask |= np.broadcast_to(scale_mask[..., np.newaxis],
|
|
562
|
+
(*scale_mask.shape, 3))
|
|
563
|
+
|
|
564
|
+
if self._axlim_clip:
|
|
565
|
+
viewlim_mask = _viewlim_mask(segments[..., 0],
|
|
566
|
+
segments[..., 1],
|
|
567
|
+
segments[..., 2],
|
|
568
|
+
self.axes)
|
|
569
|
+
if np.any(viewlim_mask):
|
|
570
|
+
# broadcast mask to 3D
|
|
571
|
+
viewlim_mask = np.broadcast_to(viewlim_mask[..., np.newaxis],
|
|
572
|
+
(*viewlim_mask.shape, 3))
|
|
573
|
+
mask = mask | viewlim_mask
|
|
574
|
+
|
|
575
|
+
xyzs = proj3d._scale_proj_transform_vectors(segments, self.axes)
|
|
576
|
+
if mask is not False:
|
|
577
|
+
xyzs = np.ma.array(xyzs, mask=mask)
|
|
578
|
+
segments_2d = xyzs[..., 0:2]
|
|
579
|
+
if ragged:
|
|
580
|
+
segments_2d = np.split(segments_2d, np.cumsum(segment_lengths[:-1]))
|
|
581
|
+
LineCollection.set_segments(self, segments_2d)
|
|
582
|
+
|
|
583
|
+
# FIXME
|
|
584
|
+
if len(xyzs) > 0:
|
|
585
|
+
minz = min(xyzs[..., 2].min(), 1e9)
|
|
586
|
+
else:
|
|
587
|
+
minz = np.nan
|
|
588
|
+
return minz
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def line_collection_2d_to_3d(col, zs=0, zdir='z', axlim_clip=False):
|
|
592
|
+
"""Convert a `.LineCollection` to a `.Line3DCollection` object."""
|
|
593
|
+
segments3d = _paths_to_3d_segments(col.get_paths(), zs, zdir)
|
|
594
|
+
col.__class__ = Line3DCollection
|
|
595
|
+
col.set_segments(segments3d)
|
|
596
|
+
col._axlim_clip = axlim_clip
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
class Patch3D(Patch):
|
|
600
|
+
"""
|
|
601
|
+
3D patch object.
|
|
602
|
+
"""
|
|
603
|
+
|
|
604
|
+
def __init__(self, *args, zs=(), zdir='z', axlim_clip=False, **kwargs):
|
|
605
|
+
"""
|
|
606
|
+
Parameters
|
|
607
|
+
----------
|
|
608
|
+
verts :
|
|
609
|
+
zs : float
|
|
610
|
+
The location along the *zdir* axis in 3D space to position the
|
|
611
|
+
patch.
|
|
612
|
+
zdir : {'x', 'y', 'z'}
|
|
613
|
+
Plane to plot patch orthogonal to. Default: 'z'.
|
|
614
|
+
See `.get_dir_vector` for a description of the values.
|
|
615
|
+
axlim_clip : bool, default: False
|
|
616
|
+
Whether to hide patches with a vertex outside the axes view limits.
|
|
617
|
+
|
|
618
|
+
.. versionadded:: 3.10
|
|
619
|
+
"""
|
|
620
|
+
super().__init__(*args, **kwargs)
|
|
621
|
+
self.set_3d_properties(zs, zdir, axlim_clip)
|
|
622
|
+
|
|
623
|
+
def set_3d_properties(self, verts, zs=0, zdir='z', axlim_clip=False):
|
|
624
|
+
"""
|
|
625
|
+
Set the *z* position and direction of the patch.
|
|
626
|
+
|
|
627
|
+
Parameters
|
|
628
|
+
----------
|
|
629
|
+
verts :
|
|
630
|
+
zs : float
|
|
631
|
+
The location along the *zdir* axis in 3D space to position the
|
|
632
|
+
patch.
|
|
633
|
+
zdir : {'x', 'y', 'z'}
|
|
634
|
+
Plane to plot patch orthogonal to. Default: 'z'.
|
|
635
|
+
See `.get_dir_vector` for a description of the values.
|
|
636
|
+
axlim_clip : bool, default: False
|
|
637
|
+
Whether to hide patches with a vertex outside the axes view limits.
|
|
638
|
+
|
|
639
|
+
.. versionadded:: 3.10
|
|
640
|
+
"""
|
|
641
|
+
zs = np.broadcast_to(zs, len(verts))
|
|
642
|
+
self._segment3d = [juggle_axes(x, y, z, zdir)
|
|
643
|
+
for ((x, y), z) in zip(verts, zs)]
|
|
644
|
+
self._axlim_clip = axlim_clip
|
|
645
|
+
|
|
646
|
+
def get_path(self):
|
|
647
|
+
# docstring inherited
|
|
648
|
+
# self._path2d is not initialized until do_3d_projection
|
|
649
|
+
if not hasattr(self, '_path2d'):
|
|
650
|
+
self.axes.M = self.axes.get_proj()
|
|
651
|
+
self.do_3d_projection()
|
|
652
|
+
return self._path2d
|
|
653
|
+
|
|
654
|
+
def do_3d_projection(self):
|
|
655
|
+
s = self._segment3d
|
|
656
|
+
xs0, ys0, zs0 = zip(*s)
|
|
657
|
+
mask = _scale_invalid_mask(xs0, ys0, zs0, self.axes)
|
|
658
|
+
if self._axlim_clip:
|
|
659
|
+
mask |= _viewlim_mask(xs0, ys0, zs0, self.axes)
|
|
660
|
+
if np.any(mask):
|
|
661
|
+
xs, ys, zs = np.ma.array(zip(*s),
|
|
662
|
+
dtype=float, mask=mask).filled(np.nan)
|
|
663
|
+
else:
|
|
664
|
+
xs, ys, zs = xs0, ys0, zs0
|
|
665
|
+
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(xs, ys, zs, self.axes)
|
|
666
|
+
self._path2d = mpath.Path(np.ma.column_stack([vxs, vys]))
|
|
667
|
+
return min(vzs)
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
class PathPatch3D(Patch3D):
|
|
671
|
+
"""
|
|
672
|
+
3D PathPatch object.
|
|
673
|
+
"""
|
|
674
|
+
|
|
675
|
+
def __init__(self, path, *, zs=(), zdir='z', axlim_clip=False, **kwargs):
|
|
676
|
+
"""
|
|
677
|
+
Parameters
|
|
678
|
+
----------
|
|
679
|
+
path :
|
|
680
|
+
zs : float
|
|
681
|
+
The location along the *zdir* axis in 3D space to position the
|
|
682
|
+
path patch.
|
|
683
|
+
zdir : {'x', 'y', 'z', 3-tuple}
|
|
684
|
+
Plane to plot path patch orthogonal to. Default: 'z'.
|
|
685
|
+
See `.get_dir_vector` for a description of the values.
|
|
686
|
+
axlim_clip : bool, default: False
|
|
687
|
+
Whether to hide path patches with a point outside the axes view limits.
|
|
688
|
+
|
|
689
|
+
.. versionadded:: 3.10
|
|
690
|
+
"""
|
|
691
|
+
# Not super().__init__!
|
|
692
|
+
Patch.__init__(self, **kwargs)
|
|
693
|
+
self.set_3d_properties(path, zs, zdir, axlim_clip)
|
|
694
|
+
|
|
695
|
+
def set_3d_properties(self, path, zs=0, zdir='z', axlim_clip=False):
|
|
696
|
+
"""
|
|
697
|
+
Set the *z* position and direction of the path patch.
|
|
698
|
+
|
|
699
|
+
Parameters
|
|
700
|
+
----------
|
|
701
|
+
path :
|
|
702
|
+
zs : float
|
|
703
|
+
The location along the *zdir* axis in 3D space to position the
|
|
704
|
+
path patch.
|
|
705
|
+
zdir : {'x', 'y', 'z', 3-tuple}
|
|
706
|
+
Plane to plot path patch orthogonal to. Default: 'z'.
|
|
707
|
+
See `.get_dir_vector` for a description of the values.
|
|
708
|
+
axlim_clip : bool, default: False
|
|
709
|
+
Whether to hide path patches with a point outside the axes view limits.
|
|
710
|
+
|
|
711
|
+
.. versionadded:: 3.10
|
|
712
|
+
"""
|
|
713
|
+
Patch3D.set_3d_properties(self, path.vertices, zs=zs, zdir=zdir,
|
|
714
|
+
axlim_clip=axlim_clip)
|
|
715
|
+
self._code3d = path.codes
|
|
716
|
+
|
|
717
|
+
def do_3d_projection(self):
|
|
718
|
+
s = self._segment3d
|
|
719
|
+
xs0, ys0, zs0 = zip(*s)
|
|
720
|
+
mask = _scale_invalid_mask(xs0, ys0, zs0, self.axes)
|
|
721
|
+
if self._axlim_clip:
|
|
722
|
+
mask |= _viewlim_mask(xs0, ys0, zs0, self.axes)
|
|
723
|
+
if np.any(mask):
|
|
724
|
+
xs, ys, zs = np.ma.array(zip(*s),
|
|
725
|
+
dtype=float, mask=mask).filled(np.nan)
|
|
726
|
+
else:
|
|
727
|
+
xs, ys, zs = xs0, ys0, zs0
|
|
728
|
+
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(xs, ys, zs, self.axes)
|
|
729
|
+
self._path2d = mpath.Path(np.ma.column_stack([vxs, vys]), self._code3d)
|
|
730
|
+
return min(vzs)
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
def _get_patch_verts(patch):
|
|
734
|
+
"""Return a list of vertices for the path of a patch."""
|
|
735
|
+
trans = patch.get_patch_transform()
|
|
736
|
+
path = patch.get_path()
|
|
737
|
+
polygons = path.to_polygons(trans)
|
|
738
|
+
return polygons[0] if len(polygons) else np.array([])
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
def patch_2d_to_3d(patch, z=0, zdir='z', axlim_clip=False):
|
|
742
|
+
"""Convert a `.Patch` to a `.Patch3D` object."""
|
|
743
|
+
verts = _get_patch_verts(patch)
|
|
744
|
+
patch.__class__ = Patch3D
|
|
745
|
+
patch.set_3d_properties(verts, z, zdir, axlim_clip)
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
def pathpatch_2d_to_3d(pathpatch, z=0, zdir='z'):
|
|
749
|
+
"""Convert a `.PathPatch` to a `.PathPatch3D` object."""
|
|
750
|
+
path = pathpatch.get_path()
|
|
751
|
+
trans = pathpatch.get_patch_transform()
|
|
752
|
+
|
|
753
|
+
mpath = trans.transform_path(path)
|
|
754
|
+
pathpatch.__class__ = PathPatch3D
|
|
755
|
+
pathpatch.set_3d_properties(mpath, z, zdir)
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
class Patch3DCollection(PatchCollection):
|
|
759
|
+
"""
|
|
760
|
+
A collection of 3D patches.
|
|
761
|
+
"""
|
|
762
|
+
|
|
763
|
+
def __init__(
|
|
764
|
+
self,
|
|
765
|
+
*args,
|
|
766
|
+
zs=0,
|
|
767
|
+
zdir="z",
|
|
768
|
+
depthshade=None,
|
|
769
|
+
depthshade_minalpha=None,
|
|
770
|
+
axlim_clip=False,
|
|
771
|
+
**kwargs
|
|
772
|
+
):
|
|
773
|
+
"""
|
|
774
|
+
Create a collection of flat 3D patches with its normal vector
|
|
775
|
+
pointed in *zdir* direction, and located at *zs* on the *zdir*
|
|
776
|
+
axis. 'zs' can be a scalar or an array-like of the same length as
|
|
777
|
+
the number of patches in the collection.
|
|
778
|
+
|
|
779
|
+
Constructor arguments are the same as for
|
|
780
|
+
:class:`~matplotlib.collections.PatchCollection`. In addition,
|
|
781
|
+
keywords *zs=0* and *zdir='z'* are available.
|
|
782
|
+
|
|
783
|
+
The keyword argument *depthshade* is available to
|
|
784
|
+
indicate whether or not to shade the patches in order to
|
|
785
|
+
give the appearance of depth (default is *True*).
|
|
786
|
+
This is typically desired in scatter plots.
|
|
787
|
+
|
|
788
|
+
*depthshade_minalpha* sets the minimum alpha value applied by
|
|
789
|
+
depth-shading.
|
|
790
|
+
"""
|
|
791
|
+
if depthshade is None:
|
|
792
|
+
depthshade = rcParams['axes3d.depthshade']
|
|
793
|
+
if depthshade_minalpha is None:
|
|
794
|
+
depthshade_minalpha = rcParams['axes3d.depthshade_minalpha']
|
|
795
|
+
self._depthshade = depthshade
|
|
796
|
+
self._depthshade_minalpha = depthshade_minalpha
|
|
797
|
+
super().__init__(*args, **kwargs)
|
|
798
|
+
self.set_3d_properties(zs, zdir, axlim_clip)
|
|
799
|
+
|
|
800
|
+
def get_depthshade(self):
|
|
801
|
+
return self._depthshade
|
|
802
|
+
|
|
803
|
+
def set_depthshade(
|
|
804
|
+
self,
|
|
805
|
+
depthshade,
|
|
806
|
+
depthshade_minalpha=None,
|
|
807
|
+
):
|
|
808
|
+
"""
|
|
809
|
+
Set whether depth shading is performed on collection members.
|
|
810
|
+
|
|
811
|
+
Parameters
|
|
812
|
+
----------
|
|
813
|
+
depthshade : bool
|
|
814
|
+
Whether to shade the patches in order to give the appearance of
|
|
815
|
+
depth.
|
|
816
|
+
depthshade_minalpha : float, default: :rc:`axes3d.depthshade_minalpha`
|
|
817
|
+
Sets the minimum alpha value used by depth-shading.
|
|
818
|
+
|
|
819
|
+
.. versionadded:: 3.11
|
|
820
|
+
"""
|
|
821
|
+
if depthshade_minalpha is None:
|
|
822
|
+
depthshade_minalpha = rcParams['axes3d.depthshade_minalpha']
|
|
823
|
+
self._depthshade = depthshade
|
|
824
|
+
self._depthshade_minalpha = depthshade_minalpha
|
|
825
|
+
self.stale = True
|
|
826
|
+
|
|
827
|
+
def set_sort_zpos(self, val):
|
|
828
|
+
"""Set the position to use for z-sorting."""
|
|
829
|
+
self._sort_zpos = val
|
|
830
|
+
self.stale = True
|
|
831
|
+
|
|
832
|
+
def set_3d_properties(self, zs, zdir, axlim_clip=False):
|
|
833
|
+
"""
|
|
834
|
+
Set the *z* positions and direction of the patches.
|
|
835
|
+
|
|
836
|
+
Parameters
|
|
837
|
+
----------
|
|
838
|
+
zs : float or array of floats
|
|
839
|
+
The location or locations to place the patches in the collection
|
|
840
|
+
along the *zdir* axis.
|
|
841
|
+
zdir : {'x', 'y', 'z'}
|
|
842
|
+
Plane to plot patches orthogonal to.
|
|
843
|
+
All patches must have the same direction.
|
|
844
|
+
See `.get_dir_vector` for a description of the values.
|
|
845
|
+
axlim_clip : bool, default: False
|
|
846
|
+
Whether to hide patches with a vertex outside the axes view limits.
|
|
847
|
+
|
|
848
|
+
.. versionadded:: 3.10
|
|
849
|
+
"""
|
|
850
|
+
# Force the collection to initialize the face and edgecolors
|
|
851
|
+
# just in case it is a scalarmappable with a colormap.
|
|
852
|
+
self.update_scalarmappable()
|
|
853
|
+
offsets = self.get_offsets()
|
|
854
|
+
if len(offsets) > 0:
|
|
855
|
+
xs, ys = offsets.T
|
|
856
|
+
else:
|
|
857
|
+
xs = []
|
|
858
|
+
ys = []
|
|
859
|
+
self._offsets3d = juggle_axes(xs, ys, np.atleast_1d(zs), zdir)
|
|
860
|
+
self._z_markers_idx = slice(-1)
|
|
861
|
+
self._vzs = None
|
|
862
|
+
self._axlim_clip = axlim_clip
|
|
863
|
+
self.stale = True
|
|
864
|
+
|
|
865
|
+
def do_3d_projection(self):
|
|
866
|
+
mask = _scale_invalid_mask(*self._offsets3d, self.axes)
|
|
867
|
+
if self._axlim_clip:
|
|
868
|
+
mask |= _viewlim_mask(*self._offsets3d, self.axes)
|
|
869
|
+
if np.any(mask):
|
|
870
|
+
xs, ys, zs = np.ma.array(self._offsets3d, mask=mask)
|
|
871
|
+
else:
|
|
872
|
+
xs, ys, zs = self._offsets3d
|
|
873
|
+
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(xs, ys, zs, self.axes)
|
|
874
|
+
self._vzs = vzs
|
|
875
|
+
if np.ma.isMA(vxs):
|
|
876
|
+
super().set_offsets(np.ma.column_stack([vxs, vys]))
|
|
877
|
+
else:
|
|
878
|
+
super().set_offsets(np.column_stack([vxs, vys]))
|
|
879
|
+
|
|
880
|
+
if vzs.size > 0:
|
|
881
|
+
return min(vzs)
|
|
882
|
+
else:
|
|
883
|
+
return np.nan
|
|
884
|
+
|
|
885
|
+
def _maybe_depth_shade_and_sort_colors(self, color_array):
|
|
886
|
+
# Adjust the color_array alpha values if point depths are defined
|
|
887
|
+
# and depth shading is active
|
|
888
|
+
alpha = self._alpha
|
|
889
|
+
if self._vzs is not None and self._depthshade:
|
|
890
|
+
color_array = _zalpha(
|
|
891
|
+
color_array,
|
|
892
|
+
self._vzs,
|
|
893
|
+
min_alpha=self._depthshade_minalpha,
|
|
894
|
+
)
|
|
895
|
+
if alpha is not None and color_array.shape[1] == 4: # RGBA, not RGB
|
|
896
|
+
alpha = alpha * color_array[:, 3]
|
|
897
|
+
|
|
898
|
+
# Adjust the order of the color_array using the _z_markers_idx,
|
|
899
|
+
# which has been sorted by z-depth
|
|
900
|
+
if len(color_array) > 1:
|
|
901
|
+
color_array = color_array[self._z_markers_idx]
|
|
902
|
+
if np.ndim(alpha) > 0:
|
|
903
|
+
alpha = np.asarray(alpha)[self._z_markers_idx]
|
|
904
|
+
|
|
905
|
+
return mcolors.to_rgba_array(color_array, alpha)
|
|
906
|
+
|
|
907
|
+
def get_facecolor(self):
|
|
908
|
+
return self._maybe_depth_shade_and_sort_colors(super().get_facecolor())
|
|
909
|
+
|
|
910
|
+
def get_edgecolor(self):
|
|
911
|
+
# We need this check here to make sure we do not double-apply the depth
|
|
912
|
+
# based alpha shading when the edge color is "face" which means the
|
|
913
|
+
# edge colour should be identical to the face colour.
|
|
914
|
+
if cbook._str_equal(self._edgecolors, 'face'):
|
|
915
|
+
return self.get_facecolor()
|
|
916
|
+
return self._maybe_depth_shade_and_sort_colors(super().get_edgecolor())
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
def _get_data_scale(X, Y, Z):
|
|
920
|
+
"""
|
|
921
|
+
Estimate the scale of the 3D data for use in depth shading
|
|
922
|
+
|
|
923
|
+
Parameters
|
|
924
|
+
----------
|
|
925
|
+
X, Y, Z : masked arrays
|
|
926
|
+
The data to estimate the scale of.
|
|
927
|
+
"""
|
|
928
|
+
# Account for empty datasets. Assume that X Y and Z have the same number
|
|
929
|
+
# of elements.
|
|
930
|
+
if not np.ma.count(X):
|
|
931
|
+
return 0
|
|
932
|
+
|
|
933
|
+
# Estimate the scale using the RSS of the ranges of the dimensions
|
|
934
|
+
# Note that we don't use np.ma.ptp() because we otherwise get a build
|
|
935
|
+
# warning about handing empty arrays.
|
|
936
|
+
ptp_x = X.max() - X.min()
|
|
937
|
+
ptp_y = Y.max() - Y.min()
|
|
938
|
+
ptp_z = Z.max() - Z.min()
|
|
939
|
+
return np.sqrt(ptp_x ** 2 + ptp_y ** 2 + ptp_z ** 2)
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
class Path3DCollection(PathCollection):
|
|
943
|
+
"""
|
|
944
|
+
A collection of 3D paths.
|
|
945
|
+
"""
|
|
946
|
+
|
|
947
|
+
def __init__(
|
|
948
|
+
self,
|
|
949
|
+
*args,
|
|
950
|
+
zs=0,
|
|
951
|
+
zdir="z",
|
|
952
|
+
depthshade=None,
|
|
953
|
+
depthshade_minalpha=None,
|
|
954
|
+
axlim_clip=False,
|
|
955
|
+
**kwargs
|
|
956
|
+
):
|
|
957
|
+
"""
|
|
958
|
+
Create a collection of flat 3D paths with its normal vector
|
|
959
|
+
pointed in *zdir* direction, and located at *zs* on the *zdir*
|
|
960
|
+
axis. 'zs' can be a scalar or an array-like of the same length as
|
|
961
|
+
the number of paths in the collection.
|
|
962
|
+
|
|
963
|
+
Constructor arguments are the same as for
|
|
964
|
+
:class:`~matplotlib.collections.PathCollection`. In addition,
|
|
965
|
+
keywords *zs=0* and *zdir='z'* are available.
|
|
966
|
+
|
|
967
|
+
Also, the keyword argument *depthshade* is available to
|
|
968
|
+
indicate whether or not to shade the patches in order to
|
|
969
|
+
give the appearance of depth (default is *True*).
|
|
970
|
+
This is typically desired in scatter plots.
|
|
971
|
+
|
|
972
|
+
*depthshade_minalpha* sets the minimum alpha value applied by
|
|
973
|
+
depth-shading.
|
|
974
|
+
"""
|
|
975
|
+
if depthshade is None:
|
|
976
|
+
depthshade = rcParams['axes3d.depthshade']
|
|
977
|
+
if depthshade_minalpha is None:
|
|
978
|
+
depthshade_minalpha = rcParams['axes3d.depthshade_minalpha']
|
|
979
|
+
self._depthshade = depthshade
|
|
980
|
+
self._depthshade_minalpha = depthshade_minalpha
|
|
981
|
+
self._in_draw = False
|
|
982
|
+
super().__init__(*args, **kwargs)
|
|
983
|
+
self.set_3d_properties(zs, zdir, axlim_clip)
|
|
984
|
+
self._offset_zordered = None
|
|
985
|
+
|
|
986
|
+
def draw(self, renderer):
|
|
987
|
+
with self._use_zordered_offset():
|
|
988
|
+
with cbook._setattr_cm(self, _in_draw=True):
|
|
989
|
+
super().draw(renderer)
|
|
990
|
+
|
|
991
|
+
def set_sort_zpos(self, val):
|
|
992
|
+
"""Set the position to use for z-sorting."""
|
|
993
|
+
self._sort_zpos = val
|
|
994
|
+
self.stale = True
|
|
995
|
+
|
|
996
|
+
def set_3d_properties(self, zs, zdir, axlim_clip=False):
|
|
997
|
+
"""
|
|
998
|
+
Set the *z* positions and direction of the paths.
|
|
999
|
+
|
|
1000
|
+
Parameters
|
|
1001
|
+
----------
|
|
1002
|
+
zs : float or array of floats
|
|
1003
|
+
The location or locations to place the paths in the collection
|
|
1004
|
+
along the *zdir* axis.
|
|
1005
|
+
zdir : {'x', 'y', 'z'}
|
|
1006
|
+
Plane to plot paths orthogonal to.
|
|
1007
|
+
All paths must have the same direction.
|
|
1008
|
+
See `.get_dir_vector` for a description of the values.
|
|
1009
|
+
axlim_clip : bool, default: False
|
|
1010
|
+
Whether to hide paths with a vertex outside the axes view limits.
|
|
1011
|
+
|
|
1012
|
+
.. versionadded:: 3.10
|
|
1013
|
+
"""
|
|
1014
|
+
# Force the collection to initialize the face and edgecolors
|
|
1015
|
+
# just in case it is a scalarmappable with a colormap.
|
|
1016
|
+
self.update_scalarmappable()
|
|
1017
|
+
offsets = self.get_offsets()
|
|
1018
|
+
if len(offsets) > 0:
|
|
1019
|
+
xs, ys = offsets.T
|
|
1020
|
+
else:
|
|
1021
|
+
xs = []
|
|
1022
|
+
ys = []
|
|
1023
|
+
self._zdir = zdir
|
|
1024
|
+
self._offsets3d = juggle_axes(xs, ys, np.atleast_1d(zs), zdir)
|
|
1025
|
+
# In the base draw methods we access the attributes directly which
|
|
1026
|
+
# means we cannot resolve the shuffling in the getter methods like
|
|
1027
|
+
# we do for the edge and face colors.
|
|
1028
|
+
#
|
|
1029
|
+
# This means we need to carry around a cache of the unsorted sizes and
|
|
1030
|
+
# widths (postfixed with 3d) and in `do_3d_projection` set the
|
|
1031
|
+
# depth-sorted version of that data into the private state used by the
|
|
1032
|
+
# base collection class in its draw method.
|
|
1033
|
+
#
|
|
1034
|
+
# Grab the current sizes and linewidths to preserve them.
|
|
1035
|
+
self._sizes3d = self._sizes
|
|
1036
|
+
self._linewidths3d = np.array(self._linewidths)
|
|
1037
|
+
xs, ys, zs = self._offsets3d
|
|
1038
|
+
|
|
1039
|
+
# Sort the points based on z coordinates
|
|
1040
|
+
# Performance optimization: Create a sorted index array and reorder
|
|
1041
|
+
# points and point properties according to the index array
|
|
1042
|
+
self._z_markers_idx = slice(-1)
|
|
1043
|
+
self._vzs = None
|
|
1044
|
+
|
|
1045
|
+
self._axlim_clip = axlim_clip
|
|
1046
|
+
self.stale = True
|
|
1047
|
+
|
|
1048
|
+
def set_sizes(self, sizes, dpi=72.0):
|
|
1049
|
+
super().set_sizes(sizes, dpi)
|
|
1050
|
+
if not self._in_draw:
|
|
1051
|
+
self._sizes3d = sizes
|
|
1052
|
+
|
|
1053
|
+
def set_linewidth(self, lw):
|
|
1054
|
+
super().set_linewidth(lw)
|
|
1055
|
+
if not self._in_draw:
|
|
1056
|
+
self._linewidths3d = np.array(self._linewidths)
|
|
1057
|
+
|
|
1058
|
+
def get_depthshade(self):
|
|
1059
|
+
return self._depthshade
|
|
1060
|
+
|
|
1061
|
+
def set_depthshade(
|
|
1062
|
+
self,
|
|
1063
|
+
depthshade,
|
|
1064
|
+
depthshade_minalpha=None,
|
|
1065
|
+
):
|
|
1066
|
+
"""
|
|
1067
|
+
Set whether depth shading is performed on collection members.
|
|
1068
|
+
|
|
1069
|
+
Parameters
|
|
1070
|
+
----------
|
|
1071
|
+
depthshade : bool
|
|
1072
|
+
Whether to shade the patches in order to give the appearance of
|
|
1073
|
+
depth.
|
|
1074
|
+
depthshade_minalpha : float
|
|
1075
|
+
Sets the minimum alpha value used by depth-shading.
|
|
1076
|
+
|
|
1077
|
+
.. versionadded:: 3.11
|
|
1078
|
+
"""
|
|
1079
|
+
if depthshade_minalpha is None:
|
|
1080
|
+
depthshade_minalpha = rcParams['axes3d.depthshade_minalpha']
|
|
1081
|
+
self._depthshade = depthshade
|
|
1082
|
+
self._depthshade_minalpha = depthshade_minalpha
|
|
1083
|
+
self.stale = True
|
|
1084
|
+
|
|
1085
|
+
def do_3d_projection(self):
|
|
1086
|
+
mask = False
|
|
1087
|
+
for xyz in self._offsets3d:
|
|
1088
|
+
if np.ma.isMA(xyz):
|
|
1089
|
+
mask = mask | xyz.mask
|
|
1090
|
+
mask = mask | _scale_invalid_mask(*self._offsets3d, self.axes)
|
|
1091
|
+
if self._axlim_clip:
|
|
1092
|
+
mask = mask | _viewlim_mask(*self._offsets3d, self.axes)
|
|
1093
|
+
if np.any(mask):
|
|
1094
|
+
mask = np.broadcast_to(mask,
|
|
1095
|
+
(len(self._offsets3d), *self._offsets3d[0].shape))
|
|
1096
|
+
xyzs = np.ma.array(self._offsets3d, mask=mask)
|
|
1097
|
+
else:
|
|
1098
|
+
xyzs = self._offsets3d
|
|
1099
|
+
vxs, vys, vzs, vis = proj3d._scale_proj_transform_clip(*xyzs, self.axes)
|
|
1100
|
+
self._data_scale = _get_data_scale(vxs, vys, vzs)
|
|
1101
|
+
# Sort the points based on z coordinates
|
|
1102
|
+
# Performance optimization: Create a sorted index array and reorder
|
|
1103
|
+
# points and point properties according to the index array
|
|
1104
|
+
z_markers_idx = self._z_markers_idx = np.ma.argsort(vzs)[::-1]
|
|
1105
|
+
self._vzs = vzs
|
|
1106
|
+
|
|
1107
|
+
# we have to special case the sizes because of code in collections.py
|
|
1108
|
+
# as the draw method does
|
|
1109
|
+
# self.set_sizes(self._sizes, self.figure.dpi)
|
|
1110
|
+
# so we cannot rely on doing the sorting on the way out via get_*
|
|
1111
|
+
|
|
1112
|
+
if len(self._sizes3d) > 1:
|
|
1113
|
+
self._sizes = self._sizes3d[z_markers_idx]
|
|
1114
|
+
|
|
1115
|
+
if len(self._linewidths3d) > 1:
|
|
1116
|
+
self._linewidths = self._linewidths3d[z_markers_idx]
|
|
1117
|
+
|
|
1118
|
+
PathCollection.set_offsets(self, np.ma.column_stack((vxs, vys)))
|
|
1119
|
+
|
|
1120
|
+
# Re-order items
|
|
1121
|
+
vzs = vzs[z_markers_idx]
|
|
1122
|
+
vxs = vxs[z_markers_idx]
|
|
1123
|
+
vys = vys[z_markers_idx]
|
|
1124
|
+
|
|
1125
|
+
# Store ordered offset for drawing purpose
|
|
1126
|
+
self._offset_zordered = np.ma.column_stack((vxs, vys))
|
|
1127
|
+
|
|
1128
|
+
return np.min(vzs) if vzs.size else np.nan
|
|
1129
|
+
|
|
1130
|
+
@contextmanager
|
|
1131
|
+
def _use_zordered_offset(self):
|
|
1132
|
+
if self._offset_zordered is None:
|
|
1133
|
+
# Do nothing
|
|
1134
|
+
yield
|
|
1135
|
+
else:
|
|
1136
|
+
# Swap offset with z-ordered offset
|
|
1137
|
+
old_offset = self._offsets
|
|
1138
|
+
super().set_offsets(self._offset_zordered)
|
|
1139
|
+
try:
|
|
1140
|
+
yield
|
|
1141
|
+
finally:
|
|
1142
|
+
self._offsets = old_offset
|
|
1143
|
+
|
|
1144
|
+
def _maybe_depth_shade_and_sort_colors(self, color_array):
|
|
1145
|
+
# Adjust the color_array alpha values if point depths are defined
|
|
1146
|
+
# and depth shading is active
|
|
1147
|
+
alpha = self._alpha
|
|
1148
|
+
if self._vzs is not None and self._depthshade:
|
|
1149
|
+
color_array = _zalpha(
|
|
1150
|
+
color_array,
|
|
1151
|
+
self._vzs,
|
|
1152
|
+
min_alpha=self._depthshade_minalpha,
|
|
1153
|
+
_data_scale=self._data_scale,
|
|
1154
|
+
)
|
|
1155
|
+
if alpha is not None and color_array.shape[1] == 4: # RGBA, not RGB
|
|
1156
|
+
alpha = alpha * color_array[:, 3]
|
|
1157
|
+
|
|
1158
|
+
# Adjust the order of the color_array using the _z_markers_idx,
|
|
1159
|
+
# which has been sorted by z-depth
|
|
1160
|
+
if len(color_array) > 1:
|
|
1161
|
+
color_array = color_array[self._z_markers_idx]
|
|
1162
|
+
if np.ndim(alpha) > 0:
|
|
1163
|
+
alpha = np.asarray(alpha)[self._z_markers_idx]
|
|
1164
|
+
|
|
1165
|
+
return mcolors.to_rgba_array(color_array, alpha)
|
|
1166
|
+
|
|
1167
|
+
def get_facecolor(self):
|
|
1168
|
+
return self._maybe_depth_shade_and_sort_colors(super().get_facecolor())
|
|
1169
|
+
|
|
1170
|
+
def get_edgecolor(self):
|
|
1171
|
+
# We need this check here to make sure we do not double-apply the depth
|
|
1172
|
+
# based alpha shading when the edge color is "face" which means the
|
|
1173
|
+
# edge colour should be identical to the face colour.
|
|
1174
|
+
if cbook._str_equal(self._edgecolors, 'face'):
|
|
1175
|
+
return self.get_facecolor()
|
|
1176
|
+
return self._maybe_depth_shade_and_sort_colors(super().get_edgecolor())
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
def patch_collection_2d_to_3d(
|
|
1180
|
+
col,
|
|
1181
|
+
zs=0,
|
|
1182
|
+
zdir="z",
|
|
1183
|
+
depthshade=None,
|
|
1184
|
+
axlim_clip=False,
|
|
1185
|
+
*args,
|
|
1186
|
+
depthshade_minalpha=None,
|
|
1187
|
+
):
|
|
1188
|
+
"""
|
|
1189
|
+
Convert a `.PatchCollection` into a `.Patch3DCollection` object
|
|
1190
|
+
(or a `.PathCollection` into a `.Path3DCollection` object).
|
|
1191
|
+
|
|
1192
|
+
Parameters
|
|
1193
|
+
----------
|
|
1194
|
+
col : `~matplotlib.collections.PatchCollection` or \
|
|
1195
|
+
`~matplotlib.collections.PathCollection`
|
|
1196
|
+
The collection to convert.
|
|
1197
|
+
zs : float or array of floats
|
|
1198
|
+
The location or locations to place the patches in the collection along
|
|
1199
|
+
the *zdir* axis. Default: 0.
|
|
1200
|
+
zdir : {'x', 'y', 'z'}
|
|
1201
|
+
The axis in which to place the patches. Default: "z".
|
|
1202
|
+
See `.get_dir_vector` for a description of the values.
|
|
1203
|
+
depthshade : bool, default: :rc:`axes3d.depthshade`
|
|
1204
|
+
Whether to shade the patches to give a sense of depth.
|
|
1205
|
+
axlim_clip : bool, default: False
|
|
1206
|
+
Whether to hide patches with a vertex outside the axes view limits.
|
|
1207
|
+
|
|
1208
|
+
.. versionadded:: 3.10
|
|
1209
|
+
|
|
1210
|
+
depthshade_minalpha : float, default: :rc:`axes3d.depthshade_minalpha`
|
|
1211
|
+
Sets the minimum alpha value used by depth-shading.
|
|
1212
|
+
|
|
1213
|
+
.. versionadded:: 3.11
|
|
1214
|
+
"""
|
|
1215
|
+
if isinstance(col, PathCollection):
|
|
1216
|
+
col.__class__ = Path3DCollection
|
|
1217
|
+
col._offset_zordered = None
|
|
1218
|
+
elif isinstance(col, PatchCollection):
|
|
1219
|
+
col.__class__ = Patch3DCollection
|
|
1220
|
+
if depthshade is None:
|
|
1221
|
+
depthshade = rcParams['axes3d.depthshade']
|
|
1222
|
+
if depthshade_minalpha is None:
|
|
1223
|
+
depthshade_minalpha = rcParams['axes3d.depthshade_minalpha']
|
|
1224
|
+
col._depthshade = depthshade
|
|
1225
|
+
col._depthshade_minalpha = depthshade_minalpha
|
|
1226
|
+
col._in_draw = False
|
|
1227
|
+
col.set_3d_properties(zs, zdir, axlim_clip)
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
class Poly3DCollection(PolyCollection):
|
|
1231
|
+
"""
|
|
1232
|
+
A collection of 3D polygons.
|
|
1233
|
+
|
|
1234
|
+
.. note::
|
|
1235
|
+
**Filling of 3D polygons**
|
|
1236
|
+
|
|
1237
|
+
There is no simple definition of the enclosed surface of a 3D polygon
|
|
1238
|
+
unless the polygon is planar.
|
|
1239
|
+
|
|
1240
|
+
In practice, Matplotlib fills the 2D projection of the polygon. This
|
|
1241
|
+
gives a correct filling appearance only for planar polygons. For all
|
|
1242
|
+
other polygons, you'll find orientations in which the edges of the
|
|
1243
|
+
polygon intersect in the projection. This will lead to an incorrect
|
|
1244
|
+
visualization of the 3D area.
|
|
1245
|
+
|
|
1246
|
+
If you need filled areas, it is recommended to create them via
|
|
1247
|
+
`~mpl_toolkits.mplot3d.axes3d.Axes3D.plot_trisurf`, which creates a
|
|
1248
|
+
triangulation and thus generates consistent surfaces.
|
|
1249
|
+
"""
|
|
1250
|
+
|
|
1251
|
+
def __init__(self, verts, *args, zsort='average', shade=False,
|
|
1252
|
+
lightsource=None, axlim_clip=False, **kwargs):
|
|
1253
|
+
"""
|
|
1254
|
+
Parameters
|
|
1255
|
+
----------
|
|
1256
|
+
verts : list of (N, 3) array-like
|
|
1257
|
+
The sequence of polygons [*verts0*, *verts1*, ...] where each
|
|
1258
|
+
element *verts_i* defines the vertices of polygon *i* as a 2D
|
|
1259
|
+
array-like of shape (N, 3).
|
|
1260
|
+
zsort : {'average', 'min', 'max'}, default: 'average'
|
|
1261
|
+
The calculation method for the z-order.
|
|
1262
|
+
See `~.Poly3DCollection.set_zsort` for details.
|
|
1263
|
+
shade : bool, default: False
|
|
1264
|
+
Whether to shade *facecolors* and *edgecolors*. When activating
|
|
1265
|
+
*shade*, *facecolors* and/or *edgecolors* must be provided.
|
|
1266
|
+
|
|
1267
|
+
.. versionadded:: 3.7
|
|
1268
|
+
|
|
1269
|
+
lightsource : `~matplotlib.colors.LightSource`, optional
|
|
1270
|
+
The lightsource to use when *shade* is True.
|
|
1271
|
+
|
|
1272
|
+
.. versionadded:: 3.7
|
|
1273
|
+
|
|
1274
|
+
axlim_clip : bool, default: False
|
|
1275
|
+
Whether to hide polygons with a vertex outside the view limits.
|
|
1276
|
+
|
|
1277
|
+
.. versionadded:: 3.10
|
|
1278
|
+
|
|
1279
|
+
*args, **kwargs
|
|
1280
|
+
All other parameters are forwarded to `.PolyCollection`.
|
|
1281
|
+
|
|
1282
|
+
Notes
|
|
1283
|
+
-----
|
|
1284
|
+
Note that this class does a bit of magic with the _facecolors
|
|
1285
|
+
and _edgecolors properties.
|
|
1286
|
+
"""
|
|
1287
|
+
if shade:
|
|
1288
|
+
normals = _generate_normals(verts)
|
|
1289
|
+
facecolors = kwargs.get('facecolors', None)
|
|
1290
|
+
if facecolors is not None:
|
|
1291
|
+
kwargs['facecolors'] = _shade_colors(
|
|
1292
|
+
facecolors, normals, lightsource
|
|
1293
|
+
)
|
|
1294
|
+
|
|
1295
|
+
edgecolors = kwargs.get('edgecolors', None)
|
|
1296
|
+
if edgecolors is not None:
|
|
1297
|
+
kwargs['edgecolors'] = _shade_colors(
|
|
1298
|
+
edgecolors, normals, lightsource
|
|
1299
|
+
)
|
|
1300
|
+
if facecolors is None and edgecolors is None:
|
|
1301
|
+
raise ValueError(
|
|
1302
|
+
"You must provide facecolors, edgecolors, or both for "
|
|
1303
|
+
"shade to work.")
|
|
1304
|
+
super().__init__(verts, *args, **kwargs)
|
|
1305
|
+
if isinstance(verts, np.ndarray):
|
|
1306
|
+
if verts.ndim != 3:
|
|
1307
|
+
raise ValueError('verts must be a list of (N, 3) array-like')
|
|
1308
|
+
else:
|
|
1309
|
+
if any(len(np.shape(vert)) != 2 for vert in verts):
|
|
1310
|
+
raise ValueError('verts must be a list of (N, 3) array-like')
|
|
1311
|
+
self.set_zsort(zsort)
|
|
1312
|
+
self._codes3d = None
|
|
1313
|
+
self._axlim_clip = axlim_clip
|
|
1314
|
+
|
|
1315
|
+
_zsort_functions = {
|
|
1316
|
+
'average': np.average,
|
|
1317
|
+
'min': np.min,
|
|
1318
|
+
'max': np.max,
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
def set_zsort(self, zsort):
|
|
1322
|
+
"""
|
|
1323
|
+
Set the calculation method for the z-order.
|
|
1324
|
+
|
|
1325
|
+
Parameters
|
|
1326
|
+
----------
|
|
1327
|
+
zsort : {'average', 'min', 'max'}
|
|
1328
|
+
The function applied on the z-coordinates of the vertices in the
|
|
1329
|
+
viewer's coordinate system, to determine the z-order.
|
|
1330
|
+
"""
|
|
1331
|
+
self._zsortfunc = self._zsort_functions[zsort]
|
|
1332
|
+
self._sort_zpos = None
|
|
1333
|
+
self.stale = True
|
|
1334
|
+
|
|
1335
|
+
@_api.deprecated("3.10")
|
|
1336
|
+
def get_vector(self, segments3d):
|
|
1337
|
+
return self._get_vector(segments3d)
|
|
1338
|
+
|
|
1339
|
+
def _get_vector(self, segments3d):
|
|
1340
|
+
"""
|
|
1341
|
+
Optimize points for projection.
|
|
1342
|
+
|
|
1343
|
+
Parameters
|
|
1344
|
+
----------
|
|
1345
|
+
segments3d : NumPy array or list of NumPy arrays
|
|
1346
|
+
List of vertices of the boundary of every segment. If all paths are
|
|
1347
|
+
of equal length and this argument is a NumPy array, then it should
|
|
1348
|
+
be of shape (num_faces, num_vertices, 3).
|
|
1349
|
+
"""
|
|
1350
|
+
if isinstance(segments3d, np.ndarray):
|
|
1351
|
+
_api.check_shape((None, None, 3), segments3d=segments3d)
|
|
1352
|
+
if isinstance(segments3d, np.ma.MaskedArray):
|
|
1353
|
+
self._faces = segments3d.data
|
|
1354
|
+
self._invalid_vertices = segments3d.mask.any(axis=-1)
|
|
1355
|
+
else:
|
|
1356
|
+
self._faces = segments3d
|
|
1357
|
+
self._invalid_vertices = False
|
|
1358
|
+
else:
|
|
1359
|
+
# Turn the potentially ragged list into a numpy array for later speedups
|
|
1360
|
+
# If it is ragged, set the unused vertices per face as invalid
|
|
1361
|
+
num_faces = len(segments3d)
|
|
1362
|
+
num_verts = np.fromiter(map(len, segments3d), dtype=np.intp)
|
|
1363
|
+
max_verts = num_verts.max(initial=0)
|
|
1364
|
+
segments = np.empty((num_faces, max_verts, 3))
|
|
1365
|
+
for i, face in enumerate(segments3d):
|
|
1366
|
+
segments[i, :len(face)] = face
|
|
1367
|
+
self._faces = segments
|
|
1368
|
+
self._invalid_vertices = np.arange(max_verts) >= num_verts[:, None]
|
|
1369
|
+
|
|
1370
|
+
def set_verts(self, verts, closed=True):
|
|
1371
|
+
"""
|
|
1372
|
+
Set 3D vertices.
|
|
1373
|
+
|
|
1374
|
+
Parameters
|
|
1375
|
+
----------
|
|
1376
|
+
verts : list of (N, 3) array-like
|
|
1377
|
+
The sequence of polygons [*verts0*, *verts1*, ...] where each
|
|
1378
|
+
element *verts_i* defines the vertices of polygon *i* as a 2D
|
|
1379
|
+
array-like of shape (N, 3).
|
|
1380
|
+
closed : bool, default: True
|
|
1381
|
+
Whether the polygon should be closed by adding a CLOSEPOLY
|
|
1382
|
+
connection at the end.
|
|
1383
|
+
"""
|
|
1384
|
+
self._get_vector(verts)
|
|
1385
|
+
# 2D verts will be updated at draw time
|
|
1386
|
+
super().set_verts([], False)
|
|
1387
|
+
self._closed = closed
|
|
1388
|
+
|
|
1389
|
+
def set_verts_and_codes(self, verts, codes):
|
|
1390
|
+
"""Set 3D vertices with path codes."""
|
|
1391
|
+
# set vertices with closed=False to prevent PolyCollection from
|
|
1392
|
+
# setting path codes
|
|
1393
|
+
self.set_verts(verts, closed=False)
|
|
1394
|
+
# and set our own codes instead.
|
|
1395
|
+
self._codes3d = codes
|
|
1396
|
+
|
|
1397
|
+
def set_3d_properties(self, axlim_clip=False):
|
|
1398
|
+
# Force the collection to initialize the face and edgecolors
|
|
1399
|
+
# just in case it is a scalarmappable with a colormap.
|
|
1400
|
+
self.update_scalarmappable()
|
|
1401
|
+
self._sort_zpos = None
|
|
1402
|
+
self.set_zsort('average')
|
|
1403
|
+
self._facecolor3d = PolyCollection.get_facecolor(self)
|
|
1404
|
+
self._edgecolor3d = PolyCollection.get_edgecolor(self)
|
|
1405
|
+
self._alpha3d = PolyCollection.get_alpha(self)
|
|
1406
|
+
self.stale = True
|
|
1407
|
+
|
|
1408
|
+
def set_sort_zpos(self, val):
|
|
1409
|
+
"""Set the position to use for z-sorting."""
|
|
1410
|
+
self._sort_zpos = val
|
|
1411
|
+
self.stale = True
|
|
1412
|
+
|
|
1413
|
+
def do_3d_projection(self):
|
|
1414
|
+
"""
|
|
1415
|
+
Perform the 3D projection for this object.
|
|
1416
|
+
"""
|
|
1417
|
+
if self._A is not None:
|
|
1418
|
+
# force update of color mapping because we re-order them
|
|
1419
|
+
# below. If we do not do this here, the 2D draw will call
|
|
1420
|
+
# this, but we will never port the color mapped values back
|
|
1421
|
+
# to the 3D versions.
|
|
1422
|
+
#
|
|
1423
|
+
# We hold the 3D versions in a fixed order (the order the user
|
|
1424
|
+
# passed in) and sort the 2D version by view depth.
|
|
1425
|
+
self.update_scalarmappable()
|
|
1426
|
+
if self._face_is_mapped:
|
|
1427
|
+
self._facecolor3d = self._facecolors
|
|
1428
|
+
if self._edge_is_mapped:
|
|
1429
|
+
self._edgecolor3d = self._edgecolors
|
|
1430
|
+
|
|
1431
|
+
num_faces = len(self._faces)
|
|
1432
|
+
mask = self._invalid_vertices | _scale_invalid_mask(
|
|
1433
|
+
self._faces[..., 0], self._faces[..., 1],
|
|
1434
|
+
self._faces[..., 2], self.axes)
|
|
1435
|
+
needs_masking = np.any(mask)
|
|
1436
|
+
|
|
1437
|
+
# Some faces might contain masked vertices, so we want to ignore any
|
|
1438
|
+
# errors that those might cause
|
|
1439
|
+
with np.errstate(invalid='ignore', divide='ignore'):
|
|
1440
|
+
pfaces = proj3d._scale_proj_transform_vectors(self._faces, self.axes)
|
|
1441
|
+
|
|
1442
|
+
if self._axlim_clip:
|
|
1443
|
+
viewlim_mask = _viewlim_mask(self._faces[..., 0], self._faces[..., 1],
|
|
1444
|
+
self._faces[..., 2], self.axes)
|
|
1445
|
+
if np.any(viewlim_mask):
|
|
1446
|
+
needs_masking = True
|
|
1447
|
+
mask = mask | viewlim_mask
|
|
1448
|
+
|
|
1449
|
+
pzs = pfaces[..., 2]
|
|
1450
|
+
if needs_masking:
|
|
1451
|
+
pzs = np.ma.MaskedArray(pzs, mask=mask)
|
|
1452
|
+
|
|
1453
|
+
# This extra fuss is to re-order face / edge colors
|
|
1454
|
+
cface = self._facecolor3d
|
|
1455
|
+
cedge = self._edgecolor3d
|
|
1456
|
+
if len(cface) != num_faces:
|
|
1457
|
+
cface = cface.repeat(num_faces, axis=0)
|
|
1458
|
+
if len(cedge) != num_faces:
|
|
1459
|
+
if len(cedge) == 0:
|
|
1460
|
+
cedge = cface
|
|
1461
|
+
else:
|
|
1462
|
+
cedge = cedge.repeat(num_faces, axis=0)
|
|
1463
|
+
|
|
1464
|
+
if len(pzs) > 0:
|
|
1465
|
+
face_z = self._zsortfunc(pzs, axis=-1)
|
|
1466
|
+
else:
|
|
1467
|
+
face_z = pzs
|
|
1468
|
+
if needs_masking:
|
|
1469
|
+
face_z = face_z.data
|
|
1470
|
+
face_order = np.argsort(face_z, axis=-1)[::-1]
|
|
1471
|
+
|
|
1472
|
+
if len(pfaces) > 0:
|
|
1473
|
+
faces_2d = pfaces[face_order, :, :2]
|
|
1474
|
+
else:
|
|
1475
|
+
faces_2d = pfaces
|
|
1476
|
+
if self._codes3d is not None and len(self._codes3d) > 0:
|
|
1477
|
+
if needs_masking:
|
|
1478
|
+
segment_mask = ~mask[face_order, :]
|
|
1479
|
+
faces_2d = [face[mask, :] for face, mask
|
|
1480
|
+
in zip(faces_2d, segment_mask)]
|
|
1481
|
+
codes = [self._codes3d[idx] for idx in face_order]
|
|
1482
|
+
PolyCollection.set_verts_and_codes(self, faces_2d, codes)
|
|
1483
|
+
else:
|
|
1484
|
+
if needs_masking and len(faces_2d) > 0:
|
|
1485
|
+
invalid_vertices_2d = np.broadcast_to(
|
|
1486
|
+
mask[face_order, :, None],
|
|
1487
|
+
faces_2d.shape)
|
|
1488
|
+
faces_2d = np.ma.MaskedArray(
|
|
1489
|
+
faces_2d, mask=invalid_vertices_2d)
|
|
1490
|
+
PolyCollection.set_verts(self, faces_2d, self._closed)
|
|
1491
|
+
|
|
1492
|
+
if len(cface) > 0:
|
|
1493
|
+
self._facecolors2d = cface[face_order]
|
|
1494
|
+
else:
|
|
1495
|
+
self._facecolors2d = cface
|
|
1496
|
+
if len(self._edgecolor3d) == len(cface) and len(cedge) > 0:
|
|
1497
|
+
self._edgecolors2d = cedge[face_order]
|
|
1498
|
+
else:
|
|
1499
|
+
self._edgecolors2d = self._edgecolor3d
|
|
1500
|
+
|
|
1501
|
+
# Return zorder value
|
|
1502
|
+
if self._sort_zpos is not None:
|
|
1503
|
+
zvec = np.array([[0], [0], [self._sort_zpos], [1]])
|
|
1504
|
+
ztrans = proj3d._proj_transform_vec(zvec, self.axes.M)
|
|
1505
|
+
return ztrans[2][0]
|
|
1506
|
+
elif pzs.size > 0:
|
|
1507
|
+
# FIXME: Some results still don't look quite right.
|
|
1508
|
+
# In particular, examine contourf3d_demo2.py
|
|
1509
|
+
# with az = -54 and elev = -45.
|
|
1510
|
+
return np.min(pzs)
|
|
1511
|
+
else:
|
|
1512
|
+
return np.nan
|
|
1513
|
+
|
|
1514
|
+
def set_facecolor(self, colors):
|
|
1515
|
+
# docstring inherited
|
|
1516
|
+
super().set_facecolor(colors)
|
|
1517
|
+
self._facecolor3d = PolyCollection.get_facecolor(self)
|
|
1518
|
+
|
|
1519
|
+
def set_edgecolor(self, colors):
|
|
1520
|
+
# docstring inherited
|
|
1521
|
+
super().set_edgecolor(colors)
|
|
1522
|
+
self._edgecolor3d = PolyCollection.get_edgecolor(self)
|
|
1523
|
+
|
|
1524
|
+
def set_alpha(self, alpha):
|
|
1525
|
+
# docstring inherited
|
|
1526
|
+
artist.Artist.set_alpha(self, alpha)
|
|
1527
|
+
try:
|
|
1528
|
+
self._facecolor3d = mcolors.to_rgba_array(
|
|
1529
|
+
self._facecolor3d, self._alpha)
|
|
1530
|
+
except (AttributeError, TypeError, IndexError):
|
|
1531
|
+
pass
|
|
1532
|
+
try:
|
|
1533
|
+
self._edgecolors = mcolors.to_rgba_array(
|
|
1534
|
+
self._edgecolor3d, self._alpha)
|
|
1535
|
+
except (AttributeError, TypeError, IndexError):
|
|
1536
|
+
pass
|
|
1537
|
+
self.stale = True
|
|
1538
|
+
|
|
1539
|
+
def get_facecolor(self):
|
|
1540
|
+
# docstring inherited
|
|
1541
|
+
# self._facecolors2d is not initialized until do_3d_projection
|
|
1542
|
+
if not hasattr(self, '_facecolors2d'):
|
|
1543
|
+
self.axes.M = self.axes.get_proj()
|
|
1544
|
+
self.do_3d_projection()
|
|
1545
|
+
return np.asarray(self._facecolors2d)
|
|
1546
|
+
|
|
1547
|
+
def get_edgecolor(self):
|
|
1548
|
+
# docstring inherited
|
|
1549
|
+
# self._edgecolors2d is not initialized until do_3d_projection
|
|
1550
|
+
if not hasattr(self, '_edgecolors2d'):
|
|
1551
|
+
self.axes.M = self.axes.get_proj()
|
|
1552
|
+
self.do_3d_projection()
|
|
1553
|
+
return np.asarray(self._edgecolors2d)
|
|
1554
|
+
|
|
1555
|
+
|
|
1556
|
+
def poly_collection_2d_to_3d(col, zs=0, zdir='z', axlim_clip=False):
|
|
1557
|
+
"""
|
|
1558
|
+
Convert a `.PolyCollection` into a `.Poly3DCollection` object.
|
|
1559
|
+
|
|
1560
|
+
Parameters
|
|
1561
|
+
----------
|
|
1562
|
+
col : `~matplotlib.collections.PolyCollection`
|
|
1563
|
+
The collection to convert.
|
|
1564
|
+
zs : float or array of floats
|
|
1565
|
+
The location or locations to place the polygons in the collection along
|
|
1566
|
+
the *zdir* axis. Default: 0.
|
|
1567
|
+
zdir : {'x', 'y', 'z'}
|
|
1568
|
+
The axis in which to place the patches. Default: 'z'.
|
|
1569
|
+
See `.get_dir_vector` for a description of the values.
|
|
1570
|
+
"""
|
|
1571
|
+
segments_3d, codes = _paths_to_3d_segments_with_codes(
|
|
1572
|
+
col.get_paths(), zs, zdir)
|
|
1573
|
+
col.__class__ = Poly3DCollection
|
|
1574
|
+
col.set_verts_and_codes(segments_3d, codes)
|
|
1575
|
+
col.set_3d_properties()
|
|
1576
|
+
col._axlim_clip = axlim_clip
|
|
1577
|
+
|
|
1578
|
+
|
|
1579
|
+
def juggle_axes(xs, ys, zs, zdir):
|
|
1580
|
+
"""
|
|
1581
|
+
Reorder coordinates so that 2D *xs*, *ys* can be plotted in the plane
|
|
1582
|
+
orthogonal to *zdir*. *zdir* is normally 'x', 'y' or 'z'. However, if
|
|
1583
|
+
*zdir* starts with a '-' it is interpreted as a compensation for
|
|
1584
|
+
`rotate_axes`.
|
|
1585
|
+
"""
|
|
1586
|
+
if zdir == 'x':
|
|
1587
|
+
return zs, xs, ys
|
|
1588
|
+
elif zdir == 'y':
|
|
1589
|
+
return xs, zs, ys
|
|
1590
|
+
elif zdir[0] == '-':
|
|
1591
|
+
return rotate_axes(xs, ys, zs, zdir)
|
|
1592
|
+
else:
|
|
1593
|
+
return xs, ys, zs
|
|
1594
|
+
|
|
1595
|
+
|
|
1596
|
+
def rotate_axes(xs, ys, zs, zdir):
|
|
1597
|
+
"""
|
|
1598
|
+
Reorder coordinates so that the axes are rotated with *zdir* along
|
|
1599
|
+
the original z axis. Prepending the axis with a '-' does the
|
|
1600
|
+
inverse transform, so *zdir* can be 'x', '-x', 'y', '-y', 'z' or '-z'.
|
|
1601
|
+
"""
|
|
1602
|
+
if zdir in ('x', '-y'):
|
|
1603
|
+
return ys, zs, xs
|
|
1604
|
+
elif zdir in ('-x', 'y'):
|
|
1605
|
+
return zs, xs, ys
|
|
1606
|
+
else:
|
|
1607
|
+
return xs, ys, zs
|
|
1608
|
+
|
|
1609
|
+
|
|
1610
|
+
def _zalpha(
|
|
1611
|
+
colors,
|
|
1612
|
+
zs,
|
|
1613
|
+
min_alpha=0.3,
|
|
1614
|
+
_data_scale=None,
|
|
1615
|
+
):
|
|
1616
|
+
"""Modify the alpha values of the color list according to z-depth."""
|
|
1617
|
+
|
|
1618
|
+
if len(colors) == 0 or len(zs) == 0:
|
|
1619
|
+
return np.zeros((0, 4))
|
|
1620
|
+
|
|
1621
|
+
# Alpha values beyond the range 0-1 inclusive make no sense, so clip them
|
|
1622
|
+
min_alpha = np.clip(min_alpha, 0, 1)
|
|
1623
|
+
|
|
1624
|
+
if _data_scale is None or _data_scale == 0:
|
|
1625
|
+
# Don't scale the alpha values since we have no valid data scale for reference
|
|
1626
|
+
sats = np.ones_like(zs)
|
|
1627
|
+
|
|
1628
|
+
else:
|
|
1629
|
+
# Deeper points have an increasingly transparent appearance
|
|
1630
|
+
sats = np.clip(1 - (zs - np.min(zs)) / _data_scale, min_alpha, 1)
|
|
1631
|
+
|
|
1632
|
+
rgba = np.broadcast_to(mcolors.to_rgba_array(colors), (len(zs), 4))
|
|
1633
|
+
|
|
1634
|
+
# Change the alpha values of the colors using the generated alpha multipliers
|
|
1635
|
+
return np.column_stack([rgba[:, :3], rgba[:, 3] * sats])
|
|
1636
|
+
|
|
1637
|
+
|
|
1638
|
+
def _all_points_on_plane(xs, ys, zs, atol=1e-8):
|
|
1639
|
+
"""
|
|
1640
|
+
Check if all points are on the same plane. Note that NaN values are
|
|
1641
|
+
ignored.
|
|
1642
|
+
|
|
1643
|
+
Parameters
|
|
1644
|
+
----------
|
|
1645
|
+
xs, ys, zs : array-like
|
|
1646
|
+
The x, y, and z coordinates of the points.
|
|
1647
|
+
atol : float, default: 1e-8
|
|
1648
|
+
The tolerance for the equality check.
|
|
1649
|
+
"""
|
|
1650
|
+
xs, ys, zs = np.asarray(xs), np.asarray(ys), np.asarray(zs)
|
|
1651
|
+
points = np.column_stack([xs, ys, zs])
|
|
1652
|
+
points = points[~np.isnan(points).any(axis=1)]
|
|
1653
|
+
# Check for the case where we have less than 3 unique points
|
|
1654
|
+
points = np.unique(points, axis=0)
|
|
1655
|
+
if len(points) <= 3:
|
|
1656
|
+
return True
|
|
1657
|
+
# Calculate the vectors from the first point to all other points
|
|
1658
|
+
vs = (points - points[0])[1:]
|
|
1659
|
+
vs = vs / np.linalg.norm(vs, axis=1)[:, np.newaxis]
|
|
1660
|
+
# Filter out parallel vectors
|
|
1661
|
+
vs = np.unique(vs, axis=0)
|
|
1662
|
+
if len(vs) <= 2:
|
|
1663
|
+
return True
|
|
1664
|
+
# Filter out parallel and antiparallel vectors to the first vector
|
|
1665
|
+
cross_norms = np.linalg.norm(np.cross(vs[0], vs[1:]), axis=1)
|
|
1666
|
+
zero_cross_norms = np.where(np.isclose(cross_norms, 0, atol=atol))[0] + 1
|
|
1667
|
+
vs = np.delete(vs, zero_cross_norms, axis=0)
|
|
1668
|
+
if len(vs) <= 2:
|
|
1669
|
+
return True
|
|
1670
|
+
# Calculate the normal vector from the first three points
|
|
1671
|
+
n = np.cross(vs[0], vs[1])
|
|
1672
|
+
n = n / np.linalg.norm(n)
|
|
1673
|
+
# If the dot product of the normal vector and all other vectors is zero,
|
|
1674
|
+
# all points are on the same plane
|
|
1675
|
+
dots = np.dot(n, vs.transpose())
|
|
1676
|
+
return np.allclose(dots, 0, atol=atol)
|
|
1677
|
+
|
|
1678
|
+
|
|
1679
|
+
def _generate_normals(polygons):
|
|
1680
|
+
"""
|
|
1681
|
+
Compute the normals of a list of polygons, one normal per polygon.
|
|
1682
|
+
|
|
1683
|
+
Normals point towards the viewer for a face with its vertices in
|
|
1684
|
+
counterclockwise order, following the right hand rule.
|
|
1685
|
+
|
|
1686
|
+
Uses three points equally spaced around the polygon. This method assumes
|
|
1687
|
+
that the points are in a plane. Otherwise, more than one shade is required,
|
|
1688
|
+
which is not supported.
|
|
1689
|
+
|
|
1690
|
+
Parameters
|
|
1691
|
+
----------
|
|
1692
|
+
polygons : list of (M_i, 3) array-like, or (..., M, 3) array-like
|
|
1693
|
+
A sequence of polygons to compute normals for, which can have
|
|
1694
|
+
varying numbers of vertices. If the polygons all have the same
|
|
1695
|
+
number of vertices and array is passed, then the operation will
|
|
1696
|
+
be vectorized.
|
|
1697
|
+
|
|
1698
|
+
Returns
|
|
1699
|
+
-------
|
|
1700
|
+
normals : (..., 3) array
|
|
1701
|
+
A normal vector estimated for the polygon.
|
|
1702
|
+
"""
|
|
1703
|
+
if isinstance(polygons, np.ndarray):
|
|
1704
|
+
# optimization: polygons all have the same number of points, so can
|
|
1705
|
+
# vectorize
|
|
1706
|
+
n = polygons.shape[-2]
|
|
1707
|
+
i1, i2, i3 = 0, n//3, 2*n//3
|
|
1708
|
+
v1 = polygons[..., i1, :] - polygons[..., i2, :]
|
|
1709
|
+
v2 = polygons[..., i2, :] - polygons[..., i3, :]
|
|
1710
|
+
else:
|
|
1711
|
+
# The subtraction doesn't vectorize because polygons is jagged.
|
|
1712
|
+
v1 = np.empty((len(polygons), 3))
|
|
1713
|
+
v2 = np.empty((len(polygons), 3))
|
|
1714
|
+
for poly_i, ps in enumerate(polygons):
|
|
1715
|
+
n = len(ps)
|
|
1716
|
+
ps = np.asarray(ps)
|
|
1717
|
+
i1, i2, i3 = 0, n//3, 2*n//3
|
|
1718
|
+
v1[poly_i, :] = ps[i1, :] - ps[i2, :]
|
|
1719
|
+
v2[poly_i, :] = ps[i2, :] - ps[i3, :]
|
|
1720
|
+
return np.cross(v1, v2)
|
|
1721
|
+
|
|
1722
|
+
|
|
1723
|
+
def _shade_colors(color, normals, lightsource=None):
|
|
1724
|
+
"""
|
|
1725
|
+
Shade *color* using normal vectors given by *normals*,
|
|
1726
|
+
assuming a *lightsource* (using default position if not given).
|
|
1727
|
+
*color* can also be an array of the same length as *normals*.
|
|
1728
|
+
"""
|
|
1729
|
+
if lightsource is None:
|
|
1730
|
+
# chosen for backwards-compatibility
|
|
1731
|
+
lightsource = mcolors.LightSource(azdeg=225, altdeg=19.4712)
|
|
1732
|
+
|
|
1733
|
+
with np.errstate(invalid="ignore"):
|
|
1734
|
+
shade = ((normals / np.linalg.norm(normals, axis=1, keepdims=True))
|
|
1735
|
+
@ lightsource.direction)
|
|
1736
|
+
mask = ~np.isnan(shade)
|
|
1737
|
+
|
|
1738
|
+
if mask.any():
|
|
1739
|
+
# convert dot product to allowed shading fractions
|
|
1740
|
+
in_norm = mcolors.Normalize(-1, 1)
|
|
1741
|
+
out_norm = mcolors.Normalize(0.3, 1).inverse
|
|
1742
|
+
|
|
1743
|
+
def norm(x):
|
|
1744
|
+
return out_norm(in_norm(x))
|
|
1745
|
+
|
|
1746
|
+
shade[~mask] = 0
|
|
1747
|
+
|
|
1748
|
+
color = mcolors.to_rgba_array(color)
|
|
1749
|
+
# shape of color should be (M, 4) (where M is number of faces)
|
|
1750
|
+
# shape of shade should be (M,)
|
|
1751
|
+
# colors should have final shape of (M, 4)
|
|
1752
|
+
alpha = color[:, 3]
|
|
1753
|
+
colors = norm(shade)[:, np.newaxis] * color
|
|
1754
|
+
colors[:, 3] = alpha
|
|
1755
|
+
else:
|
|
1756
|
+
colors = np.asanyarray(color).copy()
|
|
1757
|
+
|
|
1758
|
+
return colors
|