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,1395 @@
|
|
|
1
|
+
# Vendored from matplotlib 3.11 (see licenses/LICENSE_MATPLOTLIB), adapted for matplotlib_rs.
|
|
2
|
+
import base64
|
|
3
|
+
import codecs
|
|
4
|
+
import datetime
|
|
5
|
+
import gzip
|
|
6
|
+
import hashlib
|
|
7
|
+
from io import BytesIO
|
|
8
|
+
import itertools
|
|
9
|
+
import logging
|
|
10
|
+
import os
|
|
11
|
+
import re
|
|
12
|
+
import uuid
|
|
13
|
+
|
|
14
|
+
import numpy as np
|
|
15
|
+
|
|
16
|
+
import matplotlib_rs as mpl
|
|
17
|
+
from matplotlib_rs import _png, cbook, font_manager as fm
|
|
18
|
+
from matplotlib_rs.backend_bases import (
|
|
19
|
+
_Backend, FigureCanvasBase, FigureManagerBase, RendererBase)
|
|
20
|
+
from matplotlib_rs.backends.backend_mixed import MixedModeRenderer
|
|
21
|
+
from matplotlib_rs.colors import rgb2hex
|
|
22
|
+
from matplotlib_rs.dates import UTC
|
|
23
|
+
from matplotlib_rs.path import Path
|
|
24
|
+
from matplotlib_rs import _path
|
|
25
|
+
from matplotlib_rs.transforms import Affine2D, Affine2DBase
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
_log = logging.getLogger(__name__)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# ----------------------------------------------------------------------
|
|
32
|
+
# SimpleXMLWriter class
|
|
33
|
+
#
|
|
34
|
+
# Based on an original by Fredrik Lundh, but modified here to:
|
|
35
|
+
# 1. Support modern Python idioms
|
|
36
|
+
# 2. Remove encoding support (it's handled by the file writer instead)
|
|
37
|
+
# 3. Support proper indentation
|
|
38
|
+
# 4. Minify things a little bit
|
|
39
|
+
|
|
40
|
+
# --------------------------------------------------------------------
|
|
41
|
+
# The SimpleXMLWriter module is
|
|
42
|
+
#
|
|
43
|
+
# Copyright (c) 2001-2004 by Fredrik Lundh
|
|
44
|
+
#
|
|
45
|
+
# By obtaining, using, and/or copying this software and/or its
|
|
46
|
+
# associated documentation, you agree that you have read, understood,
|
|
47
|
+
# and will comply with the following terms and conditions:
|
|
48
|
+
#
|
|
49
|
+
# Permission to use, copy, modify, and distribute this software and
|
|
50
|
+
# its associated documentation for any purpose and without fee is
|
|
51
|
+
# hereby granted, provided that the above copyright notice appears in
|
|
52
|
+
# all copies, and that both that copyright notice and this permission
|
|
53
|
+
# notice appear in supporting documentation, and that the name of
|
|
54
|
+
# Secret Labs AB or the author not be used in advertising or publicity
|
|
55
|
+
# pertaining to distribution of the software without specific, written
|
|
56
|
+
# prior permission.
|
|
57
|
+
#
|
|
58
|
+
# SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
|
|
59
|
+
# TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
|
|
60
|
+
# ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR
|
|
61
|
+
# BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
|
|
62
|
+
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
63
|
+
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
64
|
+
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
65
|
+
# OF THIS SOFTWARE.
|
|
66
|
+
# --------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _escape_cdata(s):
|
|
70
|
+
s = s.replace("&", "&")
|
|
71
|
+
s = s.replace("<", "<")
|
|
72
|
+
s = s.replace(">", ">")
|
|
73
|
+
return s
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
_escape_xml_comment = re.compile(r'-(?=-)')
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _escape_comment(s):
|
|
80
|
+
s = _escape_cdata(s)
|
|
81
|
+
return _escape_xml_comment.sub('- ', s)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _escape_attrib(s):
|
|
85
|
+
s = s.replace("&", "&")
|
|
86
|
+
s = s.replace("'", "'")
|
|
87
|
+
s = s.replace('"', """)
|
|
88
|
+
s = s.replace("<", "<")
|
|
89
|
+
s = s.replace(">", ">")
|
|
90
|
+
return s
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _quote_escape_attrib(s):
|
|
94
|
+
return ('"' + _escape_cdata(s) + '"' if '"' not in s else
|
|
95
|
+
"'" + _escape_cdata(s) + "'" if "'" not in s else
|
|
96
|
+
'"' + _escape_attrib(s) + '"')
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _short_float_fmt(x):
|
|
100
|
+
"""
|
|
101
|
+
Create a short string representation of a float, which is %f
|
|
102
|
+
formatting with trailing zeros and the decimal point removed.
|
|
103
|
+
"""
|
|
104
|
+
return f'{x:f}'.rstrip('0').rstrip('.')
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class _XMLWriter:
|
|
108
|
+
"""
|
|
109
|
+
Parameters
|
|
110
|
+
----------
|
|
111
|
+
file : writable text file-like object
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
def __init__(self, file):
|
|
115
|
+
self.__write = file.write
|
|
116
|
+
if hasattr(file, "flush"):
|
|
117
|
+
self.flush = file.flush
|
|
118
|
+
self.__open = 0 # true if start tag is open
|
|
119
|
+
self.__tags = []
|
|
120
|
+
self.__data = []
|
|
121
|
+
self.__indentation = " " * 64
|
|
122
|
+
|
|
123
|
+
def __flush(self, indent=True):
|
|
124
|
+
# flush internal buffers
|
|
125
|
+
if self.__open:
|
|
126
|
+
if indent:
|
|
127
|
+
self.__write(">\n")
|
|
128
|
+
else:
|
|
129
|
+
self.__write(">")
|
|
130
|
+
self.__open = 0
|
|
131
|
+
if self.__data:
|
|
132
|
+
data = ''.join(self.__data)
|
|
133
|
+
self.__write(_escape_cdata(data))
|
|
134
|
+
self.__data = []
|
|
135
|
+
|
|
136
|
+
def start(self, tag, attrib=None, **extra):
|
|
137
|
+
"""
|
|
138
|
+
Open a new element. Attributes can be given as keyword
|
|
139
|
+
arguments, or as a string/string dictionary. The method returns
|
|
140
|
+
an opaque identifier that can be passed to the :meth:`close`
|
|
141
|
+
method, to close all open elements up to and including this one.
|
|
142
|
+
|
|
143
|
+
Parameters
|
|
144
|
+
----------
|
|
145
|
+
tag
|
|
146
|
+
Element tag.
|
|
147
|
+
attrib
|
|
148
|
+
Attribute dictionary. Alternatively, attributes can be given as
|
|
149
|
+
keyword arguments.
|
|
150
|
+
|
|
151
|
+
Returns
|
|
152
|
+
-------
|
|
153
|
+
An element identifier.
|
|
154
|
+
"""
|
|
155
|
+
if attrib is None:
|
|
156
|
+
attrib = {}
|
|
157
|
+
self.__flush()
|
|
158
|
+
tag = _escape_cdata(tag)
|
|
159
|
+
self.__data = []
|
|
160
|
+
self.__tags.append(tag)
|
|
161
|
+
self.__write(self.__indentation[:len(self.__tags) - 1])
|
|
162
|
+
self.__write(f"<{tag}")
|
|
163
|
+
for k, v in {**attrib, **extra}.items():
|
|
164
|
+
if v:
|
|
165
|
+
k = _escape_cdata(k)
|
|
166
|
+
v = _quote_escape_attrib(v)
|
|
167
|
+
self.__write(f' {k}={v}')
|
|
168
|
+
self.__open = 1
|
|
169
|
+
return len(self.__tags) - 1
|
|
170
|
+
|
|
171
|
+
def comment(self, comment):
|
|
172
|
+
"""
|
|
173
|
+
Add a comment to the output stream.
|
|
174
|
+
|
|
175
|
+
Parameters
|
|
176
|
+
----------
|
|
177
|
+
comment : str
|
|
178
|
+
Comment text.
|
|
179
|
+
"""
|
|
180
|
+
self.__flush()
|
|
181
|
+
self.__write(self.__indentation[:len(self.__tags)])
|
|
182
|
+
self.__write(f"<!-- {_escape_comment(comment)} -->\n")
|
|
183
|
+
|
|
184
|
+
def data(self, text):
|
|
185
|
+
"""
|
|
186
|
+
Add character data to the output stream.
|
|
187
|
+
|
|
188
|
+
Parameters
|
|
189
|
+
----------
|
|
190
|
+
text : str
|
|
191
|
+
Character data.
|
|
192
|
+
"""
|
|
193
|
+
self.__data.append(text)
|
|
194
|
+
|
|
195
|
+
def end(self, tag=None, indent=True):
|
|
196
|
+
"""
|
|
197
|
+
Close the current element (opened by the most recent call to
|
|
198
|
+
:meth:`start`).
|
|
199
|
+
|
|
200
|
+
Parameters
|
|
201
|
+
----------
|
|
202
|
+
tag
|
|
203
|
+
Element tag. If given, the tag must match the start tag. If
|
|
204
|
+
omitted, the current element is closed.
|
|
205
|
+
indent : bool, default: True
|
|
206
|
+
"""
|
|
207
|
+
if tag:
|
|
208
|
+
assert self.__tags, f"unbalanced end({tag})"
|
|
209
|
+
assert _escape_cdata(tag) == self.__tags[-1], \
|
|
210
|
+
f"expected end({self.__tags[-1]}), got {tag}"
|
|
211
|
+
else:
|
|
212
|
+
assert self.__tags, "unbalanced end()"
|
|
213
|
+
tag = self.__tags.pop()
|
|
214
|
+
if self.__data:
|
|
215
|
+
self.__flush(indent)
|
|
216
|
+
elif self.__open:
|
|
217
|
+
self.__open = 0
|
|
218
|
+
self.__write("/>\n")
|
|
219
|
+
return
|
|
220
|
+
if indent:
|
|
221
|
+
self.__write(self.__indentation[:len(self.__tags)])
|
|
222
|
+
self.__write(f"</{tag}>\n")
|
|
223
|
+
|
|
224
|
+
def close(self, id):
|
|
225
|
+
"""
|
|
226
|
+
Close open elements, up to (and including) the element identified
|
|
227
|
+
by the given identifier.
|
|
228
|
+
|
|
229
|
+
Parameters
|
|
230
|
+
----------
|
|
231
|
+
id
|
|
232
|
+
Element identifier, as returned by the :meth:`start` method.
|
|
233
|
+
"""
|
|
234
|
+
while len(self.__tags) > id:
|
|
235
|
+
self.end()
|
|
236
|
+
|
|
237
|
+
def element(self, tag, text=None, attrib=None, **extra):
|
|
238
|
+
"""
|
|
239
|
+
Add an entire element. This is the same as calling :meth:`start`,
|
|
240
|
+
:meth:`data`, and :meth:`end` in sequence. The *text* argument can be
|
|
241
|
+
omitted.
|
|
242
|
+
"""
|
|
243
|
+
if attrib is None:
|
|
244
|
+
attrib = {}
|
|
245
|
+
self.start(tag, attrib, **extra)
|
|
246
|
+
if text:
|
|
247
|
+
self.data(text)
|
|
248
|
+
self.end(indent=False)
|
|
249
|
+
|
|
250
|
+
def flush(self):
|
|
251
|
+
"""Flush the output stream."""
|
|
252
|
+
pass # replaced by the constructor
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
@mpl._api.deprecated("3.11")
|
|
256
|
+
class XMLWriter(_XMLWriter):
|
|
257
|
+
"""
|
|
258
|
+
An XML writer class.
|
|
259
|
+
|
|
260
|
+
:meta private:
|
|
261
|
+
"""
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _generate_transform(transform_list):
|
|
265
|
+
parts = []
|
|
266
|
+
for type, value in transform_list:
|
|
267
|
+
if (type == 'scale' and (value == (1,) or value == (1, 1))
|
|
268
|
+
or type == 'translate' and value == (0, 0)
|
|
269
|
+
or type == 'rotate' and value == (0,)):
|
|
270
|
+
continue
|
|
271
|
+
if type == 'matrix' and isinstance(value, Affine2DBase):
|
|
272
|
+
value = value.to_values()
|
|
273
|
+
parts.append('{}({})'.format(
|
|
274
|
+
type, ' '.join(_short_float_fmt(x) for x in value)))
|
|
275
|
+
return ' '.join(parts)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _generate_css(attrib):
|
|
279
|
+
return "; ".join(f"{k}: {v}" for k, v in attrib.items())
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
_capstyle_d = {'projecting': 'square', 'butt': 'butt', 'round': 'round'}
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def _check_is_str(info, key):
|
|
286
|
+
if not isinstance(info, str):
|
|
287
|
+
raise TypeError(f'Invalid type for {key} metadata. Expected str, not '
|
|
288
|
+
f'{type(info)}.')
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def _check_is_iterable_of_str(infos, key):
|
|
292
|
+
if np.iterable(infos):
|
|
293
|
+
for info in infos:
|
|
294
|
+
if not isinstance(info, str):
|
|
295
|
+
raise TypeError(f'Invalid type for {key} metadata. Expected '
|
|
296
|
+
f'iterable of str, not {type(info)}.')
|
|
297
|
+
else:
|
|
298
|
+
raise TypeError(f'Invalid type for {key} metadata. Expected str or '
|
|
299
|
+
f'iterable of str, not {type(infos)}.')
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
class RendererSVG(RendererBase):
|
|
303
|
+
def __init__(self, width, height, svgwriter, basename=None, image_dpi=72,
|
|
304
|
+
*, metadata=None):
|
|
305
|
+
self.width = width
|
|
306
|
+
self.height = height
|
|
307
|
+
self.writer = _XMLWriter(svgwriter)
|
|
308
|
+
self.image_dpi = image_dpi # actual dpi at which we rasterize stuff
|
|
309
|
+
|
|
310
|
+
if basename is None:
|
|
311
|
+
basename = getattr(svgwriter, "name", "")
|
|
312
|
+
if not isinstance(basename, str):
|
|
313
|
+
basename = ""
|
|
314
|
+
self.basename = basename
|
|
315
|
+
|
|
316
|
+
self._groupd = {}
|
|
317
|
+
self._image_counter = itertools.count()
|
|
318
|
+
self._clip_path_ids = {}
|
|
319
|
+
self._clipd = {}
|
|
320
|
+
self._markers = {}
|
|
321
|
+
self._path_collection_id = 0
|
|
322
|
+
self._hatchd = {}
|
|
323
|
+
self._has_gouraud = False
|
|
324
|
+
self._n_gradients = 0
|
|
325
|
+
|
|
326
|
+
super().__init__()
|
|
327
|
+
self._glyph_map = dict()
|
|
328
|
+
str_height = _short_float_fmt(height)
|
|
329
|
+
str_width = _short_float_fmt(width)
|
|
330
|
+
svgwriter.write(svgProlog)
|
|
331
|
+
self._start_id = self.writer.start(
|
|
332
|
+
'svg',
|
|
333
|
+
width=f'{str_width}pt',
|
|
334
|
+
height=f'{str_height}pt',
|
|
335
|
+
viewBox=f'0 0 {str_width} {str_height}',
|
|
336
|
+
xmlns="http://www.w3.org/2000/svg",
|
|
337
|
+
version="1.1",
|
|
338
|
+
id=mpl.rcParams['svg.id'],
|
|
339
|
+
attrib={'xmlns:xlink': "http://www.w3.org/1999/xlink"})
|
|
340
|
+
self._write_metadata(metadata)
|
|
341
|
+
self._write_default_style()
|
|
342
|
+
|
|
343
|
+
def _get_clippath_id(self, clippath):
|
|
344
|
+
"""
|
|
345
|
+
Returns a stable and unique identifier for the *clippath* argument
|
|
346
|
+
object within the current rendering context.
|
|
347
|
+
|
|
348
|
+
This allows plots that include custom clip paths to produce identical
|
|
349
|
+
SVG output on each render, provided that the :rc:`svg.hashsalt` config
|
|
350
|
+
setting and the ``SOURCE_DATE_EPOCH`` build-time environment variable
|
|
351
|
+
are set to fixed values.
|
|
352
|
+
"""
|
|
353
|
+
if clippath not in self._clip_path_ids:
|
|
354
|
+
self._clip_path_ids[clippath] = len(self._clip_path_ids)
|
|
355
|
+
return self._clip_path_ids[clippath]
|
|
356
|
+
|
|
357
|
+
def finalize(self):
|
|
358
|
+
self._write_clips()
|
|
359
|
+
self._write_hatches()
|
|
360
|
+
self.writer.close(self._start_id)
|
|
361
|
+
self.writer.flush()
|
|
362
|
+
|
|
363
|
+
def _write_metadata(self, metadata):
|
|
364
|
+
# Add metadata following the Dublin Core Metadata Initiative, and the
|
|
365
|
+
# Creative Commons Rights Expression Language. This is mainly for
|
|
366
|
+
# compatibility with Inkscape.
|
|
367
|
+
if metadata is None:
|
|
368
|
+
metadata = {}
|
|
369
|
+
metadata = {
|
|
370
|
+
'Format': 'image/svg+xml',
|
|
371
|
+
'Type': 'http://purl.org/dc/dcmitype/StillImage',
|
|
372
|
+
'Creator':
|
|
373
|
+
f'Matplotlib v{mpl.__version__}, https://matplotlib.org/',
|
|
374
|
+
**metadata
|
|
375
|
+
}
|
|
376
|
+
writer = self.writer
|
|
377
|
+
|
|
378
|
+
if 'Title' in metadata:
|
|
379
|
+
title = metadata['Title']
|
|
380
|
+
_check_is_str(title, 'Title')
|
|
381
|
+
writer.element('title', text=title)
|
|
382
|
+
|
|
383
|
+
# Special handling.
|
|
384
|
+
date = metadata.get('Date', None)
|
|
385
|
+
if date is not None:
|
|
386
|
+
if isinstance(date, str):
|
|
387
|
+
dates = [date]
|
|
388
|
+
elif isinstance(date, (datetime.datetime, datetime.date)):
|
|
389
|
+
dates = [date.isoformat()]
|
|
390
|
+
elif np.iterable(date):
|
|
391
|
+
dates = []
|
|
392
|
+
for d in date:
|
|
393
|
+
if isinstance(d, str):
|
|
394
|
+
dates.append(d)
|
|
395
|
+
elif isinstance(d, (datetime.datetime, datetime.date)):
|
|
396
|
+
dates.append(d.isoformat())
|
|
397
|
+
else:
|
|
398
|
+
raise TypeError(
|
|
399
|
+
f'Invalid type for Date metadata. '
|
|
400
|
+
f'Expected iterable of str, date, or datetime, '
|
|
401
|
+
f'not {type(d)}.')
|
|
402
|
+
else:
|
|
403
|
+
raise TypeError(f'Invalid type for Date metadata. '
|
|
404
|
+
f'Expected str, date, datetime, or iterable '
|
|
405
|
+
f'of the same, not {type(date)}.')
|
|
406
|
+
metadata['Date'] = '/'.join(dates)
|
|
407
|
+
elif 'Date' not in metadata:
|
|
408
|
+
# Do not add `Date` if the user explicitly set `Date` to `None`
|
|
409
|
+
# Get source date from SOURCE_DATE_EPOCH, if set.
|
|
410
|
+
# See https://reproducible-builds.org/specs/source-date-epoch/
|
|
411
|
+
date = os.getenv("SOURCE_DATE_EPOCH")
|
|
412
|
+
if date:
|
|
413
|
+
date = datetime.datetime.fromtimestamp(int(date), datetime.timezone.utc)
|
|
414
|
+
metadata['Date'] = date.replace(tzinfo=UTC).isoformat()
|
|
415
|
+
else:
|
|
416
|
+
metadata['Date'] = datetime.datetime.today().isoformat()
|
|
417
|
+
|
|
418
|
+
mid = None
|
|
419
|
+
def ensure_metadata(mid):
|
|
420
|
+
if mid is not None:
|
|
421
|
+
return mid
|
|
422
|
+
mid = writer.start('metadata')
|
|
423
|
+
writer.start('rdf:RDF', attrib={
|
|
424
|
+
'xmlns:dc': "http://purl.org/dc/elements/1.1/",
|
|
425
|
+
'xmlns:cc': "http://creativecommons.org/ns#",
|
|
426
|
+
'xmlns:rdf': "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
|
427
|
+
})
|
|
428
|
+
writer.start('cc:Work')
|
|
429
|
+
return mid
|
|
430
|
+
|
|
431
|
+
uri = metadata.pop('Type', None)
|
|
432
|
+
if uri is not None:
|
|
433
|
+
mid = ensure_metadata(mid)
|
|
434
|
+
writer.element('dc:type', attrib={'rdf:resource': uri})
|
|
435
|
+
|
|
436
|
+
# Single value only.
|
|
437
|
+
for key in ['Title', 'Coverage', 'Date', 'Description', 'Format',
|
|
438
|
+
'Identifier', 'Language', 'Relation', 'Source']:
|
|
439
|
+
info = metadata.pop(key, None)
|
|
440
|
+
if info is not None:
|
|
441
|
+
mid = ensure_metadata(mid)
|
|
442
|
+
_check_is_str(info, key)
|
|
443
|
+
writer.element(f'dc:{key.lower()}', text=info)
|
|
444
|
+
|
|
445
|
+
# Multiple Agent values.
|
|
446
|
+
for key in ['Creator', 'Contributor', 'Publisher', 'Rights']:
|
|
447
|
+
agents = metadata.pop(key, None)
|
|
448
|
+
if agents is None:
|
|
449
|
+
continue
|
|
450
|
+
|
|
451
|
+
if isinstance(agents, str):
|
|
452
|
+
agents = [agents]
|
|
453
|
+
|
|
454
|
+
_check_is_iterable_of_str(agents, key)
|
|
455
|
+
# Now we know that we have an iterable of str
|
|
456
|
+
mid = ensure_metadata(mid)
|
|
457
|
+
writer.start(f'dc:{key.lower()}')
|
|
458
|
+
for agent in agents:
|
|
459
|
+
writer.start('cc:Agent')
|
|
460
|
+
writer.element('dc:title', text=agent)
|
|
461
|
+
writer.end('cc:Agent')
|
|
462
|
+
writer.end(f'dc:{key.lower()}')
|
|
463
|
+
|
|
464
|
+
# Multiple values.
|
|
465
|
+
keywords = metadata.pop('Keywords', None)
|
|
466
|
+
if keywords is not None:
|
|
467
|
+
if isinstance(keywords, str):
|
|
468
|
+
keywords = [keywords]
|
|
469
|
+
_check_is_iterable_of_str(keywords, 'Keywords')
|
|
470
|
+
# Now we know that we have an iterable of str
|
|
471
|
+
mid = ensure_metadata(mid)
|
|
472
|
+
writer.start('dc:subject')
|
|
473
|
+
writer.start('rdf:Bag')
|
|
474
|
+
for keyword in keywords:
|
|
475
|
+
writer.element('rdf:li', text=keyword)
|
|
476
|
+
writer.end('rdf:Bag')
|
|
477
|
+
writer.end('dc:subject')
|
|
478
|
+
|
|
479
|
+
if mid is not None:
|
|
480
|
+
writer.close(mid)
|
|
481
|
+
|
|
482
|
+
if metadata:
|
|
483
|
+
raise ValueError('Unknown metadata key(s) passed to SVG writer: ' +
|
|
484
|
+
','.join(metadata))
|
|
485
|
+
|
|
486
|
+
def _write_default_style(self):
|
|
487
|
+
writer = self.writer
|
|
488
|
+
default_style = _generate_css({
|
|
489
|
+
'stroke-linejoin': 'round',
|
|
490
|
+
'stroke-linecap': 'butt'})
|
|
491
|
+
writer.start('defs')
|
|
492
|
+
writer.element('style', type='text/css', text='*{%s}' % default_style)
|
|
493
|
+
writer.end('defs')
|
|
494
|
+
|
|
495
|
+
def _make_id(self, type, content):
|
|
496
|
+
salt = mpl.rcParams['svg.hashsalt']
|
|
497
|
+
if salt is None:
|
|
498
|
+
salt = str(uuid.uuid4())
|
|
499
|
+
m = hashlib.sha256()
|
|
500
|
+
m.update(salt.encode('utf8'))
|
|
501
|
+
m.update(str(content).encode('utf8'))
|
|
502
|
+
return f'{type}{m.hexdigest()[:10]}'
|
|
503
|
+
|
|
504
|
+
def _make_flip_transform(self, transform):
|
|
505
|
+
return transform + Affine2D().scale(1, -1).translate(0, self.height)
|
|
506
|
+
|
|
507
|
+
def _get_hatch(self, gc, rgbFace):
|
|
508
|
+
"""
|
|
509
|
+
Create a new hatch pattern
|
|
510
|
+
"""
|
|
511
|
+
if rgbFace is not None:
|
|
512
|
+
rgbFace = tuple(rgbFace)
|
|
513
|
+
edge = gc.get_hatch_color()
|
|
514
|
+
if edge is not None:
|
|
515
|
+
edge = tuple(edge)
|
|
516
|
+
lw = gc.get_hatch_linewidth()
|
|
517
|
+
dictkey = (gc.get_hatch(), rgbFace, edge, lw)
|
|
518
|
+
oid = self._hatchd.get(dictkey)
|
|
519
|
+
if oid is None:
|
|
520
|
+
oid = self._make_id('h', dictkey)
|
|
521
|
+
self._hatchd[dictkey] = ((gc.get_hatch_path(), rgbFace, edge, lw), oid)
|
|
522
|
+
else:
|
|
523
|
+
_, oid = oid
|
|
524
|
+
return oid
|
|
525
|
+
|
|
526
|
+
def _write_hatches(self):
|
|
527
|
+
if not len(self._hatchd):
|
|
528
|
+
return
|
|
529
|
+
HATCH_SIZE = 72
|
|
530
|
+
writer = self.writer
|
|
531
|
+
writer.start('defs')
|
|
532
|
+
for (path, face, stroke, lw), oid in self._hatchd.values():
|
|
533
|
+
writer.start(
|
|
534
|
+
'pattern',
|
|
535
|
+
id=oid,
|
|
536
|
+
patternUnits="userSpaceOnUse",
|
|
537
|
+
x="0", y="0", width=str(HATCH_SIZE),
|
|
538
|
+
height=str(HATCH_SIZE))
|
|
539
|
+
path_data = self._convert_path(
|
|
540
|
+
path,
|
|
541
|
+
Affine2D()
|
|
542
|
+
.scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, HATCH_SIZE),
|
|
543
|
+
simplify=False)
|
|
544
|
+
if face is None:
|
|
545
|
+
fill = 'none'
|
|
546
|
+
else:
|
|
547
|
+
fill = rgb2hex(face)
|
|
548
|
+
writer.element(
|
|
549
|
+
'rect',
|
|
550
|
+
x="0", y="0", width=str(HATCH_SIZE+1),
|
|
551
|
+
height=str(HATCH_SIZE+1),
|
|
552
|
+
fill=fill)
|
|
553
|
+
hatch_style = {
|
|
554
|
+
'fill': rgb2hex(stroke),
|
|
555
|
+
'stroke': rgb2hex(stroke),
|
|
556
|
+
'stroke-width': str(lw),
|
|
557
|
+
'stroke-linecap': 'butt',
|
|
558
|
+
'stroke-linejoin': 'miter'
|
|
559
|
+
}
|
|
560
|
+
if stroke[3] < 1:
|
|
561
|
+
hatch_style['stroke-opacity'] = str(stroke[3])
|
|
562
|
+
writer.element(
|
|
563
|
+
'path',
|
|
564
|
+
d=path_data,
|
|
565
|
+
style=_generate_css(hatch_style)
|
|
566
|
+
)
|
|
567
|
+
writer.end('pattern')
|
|
568
|
+
writer.end('defs')
|
|
569
|
+
|
|
570
|
+
def _get_style_dict(self, gc, rgbFace):
|
|
571
|
+
"""Generate a style string from the GraphicsContext and rgbFace."""
|
|
572
|
+
attrib = {}
|
|
573
|
+
|
|
574
|
+
forced_alpha = gc.get_forced_alpha()
|
|
575
|
+
|
|
576
|
+
if gc.get_hatch() is not None:
|
|
577
|
+
attrib['fill'] = f"url(#{self._get_hatch(gc, rgbFace)})"
|
|
578
|
+
if (rgbFace is not None and len(rgbFace) == 4 and rgbFace[3] != 1.0
|
|
579
|
+
and not forced_alpha):
|
|
580
|
+
attrib['fill-opacity'] = _short_float_fmt(rgbFace[3])
|
|
581
|
+
else:
|
|
582
|
+
if rgbFace is None:
|
|
583
|
+
attrib['fill'] = 'none'
|
|
584
|
+
else:
|
|
585
|
+
if tuple(rgbFace[:3]) != (0, 0, 0):
|
|
586
|
+
attrib['fill'] = rgb2hex(rgbFace)
|
|
587
|
+
if (len(rgbFace) == 4 and rgbFace[3] != 1.0
|
|
588
|
+
and not forced_alpha):
|
|
589
|
+
attrib['fill-opacity'] = _short_float_fmt(rgbFace[3])
|
|
590
|
+
|
|
591
|
+
if forced_alpha and gc.get_alpha() != 1.0:
|
|
592
|
+
attrib['opacity'] = _short_float_fmt(gc.get_alpha())
|
|
593
|
+
|
|
594
|
+
offset, seq = gc.get_dashes()
|
|
595
|
+
if seq is not None:
|
|
596
|
+
attrib['stroke-dasharray'] = ','.join(
|
|
597
|
+
_short_float_fmt(val) for val in seq)
|
|
598
|
+
attrib['stroke-dashoffset'] = _short_float_fmt(float(offset))
|
|
599
|
+
|
|
600
|
+
linewidth = gc.get_linewidth()
|
|
601
|
+
if linewidth:
|
|
602
|
+
rgb = gc.get_rgb()
|
|
603
|
+
attrib['stroke'] = rgb2hex(rgb)
|
|
604
|
+
if not forced_alpha and rgb[3] != 1.0:
|
|
605
|
+
attrib['stroke-opacity'] = _short_float_fmt(rgb[3])
|
|
606
|
+
if linewidth != 1.0:
|
|
607
|
+
attrib['stroke-width'] = _short_float_fmt(linewidth)
|
|
608
|
+
if gc.get_joinstyle() != 'round':
|
|
609
|
+
attrib['stroke-linejoin'] = gc.get_joinstyle()
|
|
610
|
+
if gc.get_capstyle() != 'butt':
|
|
611
|
+
attrib['stroke-linecap'] = _capstyle_d[gc.get_capstyle()]
|
|
612
|
+
|
|
613
|
+
return attrib
|
|
614
|
+
|
|
615
|
+
def _get_style(self, gc, rgbFace):
|
|
616
|
+
return _generate_css(self._get_style_dict(gc, rgbFace))
|
|
617
|
+
|
|
618
|
+
def _get_clip_attrs(self, gc):
|
|
619
|
+
cliprect = gc.get_clip_rectangle()
|
|
620
|
+
clippath, clippath_trans = gc.get_clip_path()
|
|
621
|
+
if clippath is not None:
|
|
622
|
+
clippath_trans = self._make_flip_transform(clippath_trans)
|
|
623
|
+
dictkey = (self._get_clippath_id(clippath), str(clippath_trans))
|
|
624
|
+
elif cliprect is not None:
|
|
625
|
+
x, y, w, h = cliprect.bounds
|
|
626
|
+
y = self.height-(y+h)
|
|
627
|
+
dictkey = (x, y, w, h)
|
|
628
|
+
else:
|
|
629
|
+
return {}
|
|
630
|
+
clip = self._clipd.get(dictkey)
|
|
631
|
+
if clip is None:
|
|
632
|
+
oid = self._make_id('p', dictkey)
|
|
633
|
+
if clippath is not None:
|
|
634
|
+
self._clipd[dictkey] = ((clippath, clippath_trans), oid)
|
|
635
|
+
else:
|
|
636
|
+
self._clipd[dictkey] = (dictkey, oid)
|
|
637
|
+
else:
|
|
638
|
+
_, oid = clip
|
|
639
|
+
return {'clip-path': f'url(#{oid})'}
|
|
640
|
+
|
|
641
|
+
def _write_clips(self):
|
|
642
|
+
if not len(self._clipd):
|
|
643
|
+
return
|
|
644
|
+
writer = self.writer
|
|
645
|
+
writer.start('defs')
|
|
646
|
+
for clip, oid in self._clipd.values():
|
|
647
|
+
writer.start('clipPath', id=oid)
|
|
648
|
+
if len(clip) == 2:
|
|
649
|
+
clippath, clippath_trans = clip
|
|
650
|
+
path_data = self._convert_path(
|
|
651
|
+
clippath, clippath_trans, simplify=False)
|
|
652
|
+
writer.element('path', d=path_data)
|
|
653
|
+
else:
|
|
654
|
+
x, y, w, h = clip
|
|
655
|
+
writer.element(
|
|
656
|
+
'rect',
|
|
657
|
+
x=_short_float_fmt(x),
|
|
658
|
+
y=_short_float_fmt(y),
|
|
659
|
+
width=_short_float_fmt(w),
|
|
660
|
+
height=_short_float_fmt(h))
|
|
661
|
+
writer.end('clipPath')
|
|
662
|
+
writer.end('defs')
|
|
663
|
+
|
|
664
|
+
def open_group(self, s, gid=None):
|
|
665
|
+
# docstring inherited
|
|
666
|
+
if gid:
|
|
667
|
+
self.writer.start('g', id=gid)
|
|
668
|
+
else:
|
|
669
|
+
self._groupd[s] = self._groupd.get(s, 0) + 1
|
|
670
|
+
self.writer.start('g', id=f"{s}_{self._groupd[s]:d}")
|
|
671
|
+
|
|
672
|
+
def close_group(self, s):
|
|
673
|
+
# docstring inherited
|
|
674
|
+
self.writer.end('g')
|
|
675
|
+
|
|
676
|
+
def option_image_nocomposite(self):
|
|
677
|
+
# docstring inherited
|
|
678
|
+
return not mpl.rcParams['image.composite_image']
|
|
679
|
+
|
|
680
|
+
def _convert_path(self, path, transform=None, clip=None, simplify=None,
|
|
681
|
+
sketch=None):
|
|
682
|
+
if clip:
|
|
683
|
+
clip = (0.0, 0.0, self.width, self.height)
|
|
684
|
+
else:
|
|
685
|
+
clip = None
|
|
686
|
+
return _path.convert_to_string(
|
|
687
|
+
path, transform, clip, simplify, sketch, 6,
|
|
688
|
+
[b'M', b'L', b'Q', b'C', b'z'], False).decode('ascii')
|
|
689
|
+
|
|
690
|
+
def draw_path(self, gc, path, transform, rgbFace=None):
|
|
691
|
+
# docstring inherited
|
|
692
|
+
trans_and_flip = self._make_flip_transform(transform)
|
|
693
|
+
clip = (rgbFace is None and gc.get_hatch_path() is None)
|
|
694
|
+
simplify = path.should_simplify and clip
|
|
695
|
+
path_data = self._convert_path(
|
|
696
|
+
path, trans_and_flip, clip=clip, simplify=simplify,
|
|
697
|
+
sketch=gc.get_sketch_params())
|
|
698
|
+
|
|
699
|
+
if gc.get_url() is not None:
|
|
700
|
+
self.writer.start('a', {'xlink:href': gc.get_url(), 'target': '_blank'})
|
|
701
|
+
self.writer.element('path', d=path_data, **self._get_clip_attrs(gc),
|
|
702
|
+
style=self._get_style(gc, rgbFace))
|
|
703
|
+
if gc.get_url() is not None:
|
|
704
|
+
self.writer.end('a')
|
|
705
|
+
|
|
706
|
+
def draw_markers(
|
|
707
|
+
self, gc, marker_path, marker_trans, path, trans, rgbFace=None):
|
|
708
|
+
# docstring inherited
|
|
709
|
+
|
|
710
|
+
if not len(path.vertices):
|
|
711
|
+
return
|
|
712
|
+
|
|
713
|
+
writer = self.writer
|
|
714
|
+
path_data = self._convert_path(
|
|
715
|
+
marker_path,
|
|
716
|
+
marker_trans + Affine2D().scale(1.0, -1.0),
|
|
717
|
+
simplify=False)
|
|
718
|
+
style = self._get_style_dict(gc, rgbFace)
|
|
719
|
+
dictkey = (path_data, _generate_css(style))
|
|
720
|
+
oid = self._markers.get(dictkey)
|
|
721
|
+
style = _generate_css({k: v for k, v in style.items()
|
|
722
|
+
if k.startswith('stroke')})
|
|
723
|
+
|
|
724
|
+
if oid is None:
|
|
725
|
+
oid = self._make_id('m', dictkey)
|
|
726
|
+
writer.start('defs')
|
|
727
|
+
writer.element('path', id=oid, d=path_data, style=style)
|
|
728
|
+
writer.end('defs')
|
|
729
|
+
self._markers[dictkey] = oid
|
|
730
|
+
|
|
731
|
+
writer.start('g', **self._get_clip_attrs(gc))
|
|
732
|
+
if gc.get_url() is not None:
|
|
733
|
+
self.writer.start('a', {'xlink:href': gc.get_url(), 'target': '_blank'})
|
|
734
|
+
trans_and_flip = self._make_flip_transform(trans)
|
|
735
|
+
attrib = {'xlink:href': f'#{oid}'}
|
|
736
|
+
clip = (0, 0, self.width*72, self.height*72)
|
|
737
|
+
for vertices, code in path.iter_segments(
|
|
738
|
+
trans_and_flip, clip=clip, simplify=False):
|
|
739
|
+
if len(vertices):
|
|
740
|
+
x, y = vertices[-2:]
|
|
741
|
+
attrib['x'] = _short_float_fmt(x)
|
|
742
|
+
attrib['y'] = _short_float_fmt(y)
|
|
743
|
+
attrib['style'] = self._get_style(gc, rgbFace)
|
|
744
|
+
writer.element('use', attrib=attrib)
|
|
745
|
+
if gc.get_url() is not None:
|
|
746
|
+
self.writer.end('a')
|
|
747
|
+
writer.end('g')
|
|
748
|
+
|
|
749
|
+
def draw_path_collection(self, gc, master_transform, paths, all_transforms,
|
|
750
|
+
offsets, offset_trans, facecolors, edgecolors,
|
|
751
|
+
linewidths, linestyles, antialiaseds, urls,
|
|
752
|
+
offset_position, *, hatchcolors=None):
|
|
753
|
+
if hatchcolors is None:
|
|
754
|
+
hatchcolors = []
|
|
755
|
+
# Is the optimization worth it? Rough calculation:
|
|
756
|
+
# cost of emitting a path in-line is
|
|
757
|
+
# (len_path + 5) * uses_per_path
|
|
758
|
+
# cost of definition+use is
|
|
759
|
+
# (len_path + 3) + 9 * uses_per_path
|
|
760
|
+
len_path = len(paths[0].vertices) if len(paths) > 0 else 0
|
|
761
|
+
uses_per_path = self._iter_collection_uses_per_path(
|
|
762
|
+
paths, all_transforms, offsets, facecolors, edgecolors)
|
|
763
|
+
should_do_optimization = \
|
|
764
|
+
len_path + 9 * uses_per_path + 3 < (len_path + 5) * uses_per_path
|
|
765
|
+
if not should_do_optimization:
|
|
766
|
+
return super().draw_path_collection(
|
|
767
|
+
gc, master_transform, paths, all_transforms,
|
|
768
|
+
offsets, offset_trans, facecolors, edgecolors,
|
|
769
|
+
linewidths, linestyles, antialiaseds, urls,
|
|
770
|
+
offset_position, hatchcolors=hatchcolors)
|
|
771
|
+
|
|
772
|
+
writer = self.writer
|
|
773
|
+
path_codes = []
|
|
774
|
+
writer.start('defs')
|
|
775
|
+
for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
|
|
776
|
+
master_transform, paths, all_transforms)):
|
|
777
|
+
transform = Affine2D(transform.get_matrix()).scale(1.0, -1.0)
|
|
778
|
+
d = self._convert_path(path, transform, simplify=False)
|
|
779
|
+
oid = 'C{:x}_{:x}_{}'.format(
|
|
780
|
+
self._path_collection_id, i, self._make_id('', d))
|
|
781
|
+
writer.element('path', id=oid, d=d)
|
|
782
|
+
path_codes.append(oid)
|
|
783
|
+
writer.end('defs')
|
|
784
|
+
|
|
785
|
+
for xo, yo, path_id, gc0, rgbFace in self._iter_collection(
|
|
786
|
+
gc, path_codes, offsets, offset_trans,
|
|
787
|
+
facecolors, edgecolors, linewidths, linestyles,
|
|
788
|
+
antialiaseds, urls, offset_position, hatchcolors=hatchcolors):
|
|
789
|
+
url = gc0.get_url()
|
|
790
|
+
if url is not None:
|
|
791
|
+
writer.start('a', attrib={'xlink:href': url, 'target': '_blank'})
|
|
792
|
+
clip_attrs = self._get_clip_attrs(gc0)
|
|
793
|
+
if clip_attrs:
|
|
794
|
+
writer.start('g', **clip_attrs)
|
|
795
|
+
attrib = {
|
|
796
|
+
'xlink:href': f'#{path_id}',
|
|
797
|
+
'x': _short_float_fmt(xo),
|
|
798
|
+
'y': _short_float_fmt(self.height - yo),
|
|
799
|
+
'style': self._get_style(gc0, rgbFace)
|
|
800
|
+
}
|
|
801
|
+
writer.element('use', attrib=attrib)
|
|
802
|
+
if clip_attrs:
|
|
803
|
+
writer.end('g')
|
|
804
|
+
if url is not None:
|
|
805
|
+
writer.end('a')
|
|
806
|
+
|
|
807
|
+
self._path_collection_id += 1
|
|
808
|
+
|
|
809
|
+
def _draw_gouraud_triangle(self, transformed_points, colors):
|
|
810
|
+
# This uses a method described here:
|
|
811
|
+
#
|
|
812
|
+
# http://www.svgopen.org/2005/papers/Converting3DFaceToSVG/index.html
|
|
813
|
+
#
|
|
814
|
+
# that uses three overlapping linear gradients to simulate a
|
|
815
|
+
# Gouraud triangle. Each gradient goes from fully opaque in
|
|
816
|
+
# one corner to fully transparent along the opposite edge.
|
|
817
|
+
# The line between the stop points is perpendicular to the
|
|
818
|
+
# opposite edge. Underlying these three gradients is a solid
|
|
819
|
+
# triangle whose color is the average of all three points.
|
|
820
|
+
|
|
821
|
+
avg_color = np.average(colors, axis=0)
|
|
822
|
+
if avg_color[-1] == 0:
|
|
823
|
+
# Skip fully-transparent triangles
|
|
824
|
+
return
|
|
825
|
+
|
|
826
|
+
writer = self.writer
|
|
827
|
+
writer.start('defs')
|
|
828
|
+
for i in range(3):
|
|
829
|
+
x1, y1 = transformed_points[i]
|
|
830
|
+
x2, y2 = transformed_points[(i + 1) % 3]
|
|
831
|
+
x3, y3 = transformed_points[(i + 2) % 3]
|
|
832
|
+
rgba_color = colors[i]
|
|
833
|
+
|
|
834
|
+
if x2 == x3:
|
|
835
|
+
xb = x2
|
|
836
|
+
yb = y1
|
|
837
|
+
elif y2 == y3:
|
|
838
|
+
xb = x1
|
|
839
|
+
yb = y2
|
|
840
|
+
else:
|
|
841
|
+
m1 = (y2 - y3) / (x2 - x3)
|
|
842
|
+
b1 = y2 - (m1 * x2)
|
|
843
|
+
m2 = -(1.0 / m1)
|
|
844
|
+
b2 = y1 - (m2 * x1)
|
|
845
|
+
xb = (-b1 + b2) / (m1 - m2)
|
|
846
|
+
yb = m2 * xb + b2
|
|
847
|
+
|
|
848
|
+
writer.start(
|
|
849
|
+
'linearGradient',
|
|
850
|
+
id=f"GR{self._n_gradients:x}_{i:d}",
|
|
851
|
+
gradientUnits="userSpaceOnUse",
|
|
852
|
+
x1=_short_float_fmt(x1), y1=_short_float_fmt(y1),
|
|
853
|
+
x2=_short_float_fmt(xb), y2=_short_float_fmt(yb))
|
|
854
|
+
writer.element(
|
|
855
|
+
'stop',
|
|
856
|
+
offset='1',
|
|
857
|
+
style=_generate_css({
|
|
858
|
+
'stop-color': rgb2hex(avg_color),
|
|
859
|
+
'stop-opacity': _short_float_fmt(rgba_color[-1])}))
|
|
860
|
+
writer.element(
|
|
861
|
+
'stop',
|
|
862
|
+
offset='0',
|
|
863
|
+
style=_generate_css({'stop-color': rgb2hex(rgba_color),
|
|
864
|
+
'stop-opacity': "0"}))
|
|
865
|
+
|
|
866
|
+
writer.end('linearGradient')
|
|
867
|
+
|
|
868
|
+
writer.end('defs')
|
|
869
|
+
|
|
870
|
+
# triangle formation using "path"
|
|
871
|
+
dpath = (f"M {_short_float_fmt(x1)},{_short_float_fmt(y1)}"
|
|
872
|
+
f" L {_short_float_fmt(x2)},{_short_float_fmt(y2)}"
|
|
873
|
+
f" {_short_float_fmt(x3)},{_short_float_fmt(y3)} Z")
|
|
874
|
+
|
|
875
|
+
writer.element(
|
|
876
|
+
'path',
|
|
877
|
+
attrib={'d': dpath,
|
|
878
|
+
'fill': rgb2hex(avg_color),
|
|
879
|
+
'fill-opacity': '1',
|
|
880
|
+
'shape-rendering': "crispEdges"})
|
|
881
|
+
|
|
882
|
+
writer.start(
|
|
883
|
+
'g',
|
|
884
|
+
attrib={'stroke': "none",
|
|
885
|
+
'stroke-width': "0",
|
|
886
|
+
'shape-rendering': "crispEdges",
|
|
887
|
+
'filter': "url(#colorMat)"})
|
|
888
|
+
|
|
889
|
+
writer.element(
|
|
890
|
+
'path',
|
|
891
|
+
attrib={'d': dpath,
|
|
892
|
+
'fill': f'url(#GR{self._n_gradients:x}_0)',
|
|
893
|
+
'shape-rendering': "crispEdges"})
|
|
894
|
+
|
|
895
|
+
writer.element(
|
|
896
|
+
'path',
|
|
897
|
+
attrib={'d': dpath,
|
|
898
|
+
'fill': f'url(#GR{self._n_gradients:x}_1)',
|
|
899
|
+
'filter': 'url(#colorAdd)',
|
|
900
|
+
'shape-rendering': "crispEdges"})
|
|
901
|
+
|
|
902
|
+
writer.element(
|
|
903
|
+
'path',
|
|
904
|
+
attrib={'d': dpath,
|
|
905
|
+
'fill': f'url(#GR{self._n_gradients:x}_2)',
|
|
906
|
+
'filter': 'url(#colorAdd)',
|
|
907
|
+
'shape-rendering': "crispEdges"})
|
|
908
|
+
|
|
909
|
+
writer.end('g')
|
|
910
|
+
|
|
911
|
+
self._n_gradients += 1
|
|
912
|
+
|
|
913
|
+
def draw_gouraud_triangles(self, gc, triangles_array, colors_array,
|
|
914
|
+
transform):
|
|
915
|
+
writer = self.writer
|
|
916
|
+
writer.start('g', **self._get_clip_attrs(gc))
|
|
917
|
+
transform = transform.frozen()
|
|
918
|
+
trans_and_flip = self._make_flip_transform(transform)
|
|
919
|
+
|
|
920
|
+
if not self._has_gouraud:
|
|
921
|
+
self._has_gouraud = True
|
|
922
|
+
writer.start(
|
|
923
|
+
'filter',
|
|
924
|
+
id='colorAdd')
|
|
925
|
+
writer.element(
|
|
926
|
+
'feComposite',
|
|
927
|
+
attrib={'in': 'SourceGraphic'},
|
|
928
|
+
in2='BackgroundImage',
|
|
929
|
+
operator='arithmetic',
|
|
930
|
+
k2="1", k3="1")
|
|
931
|
+
writer.end('filter')
|
|
932
|
+
# feColorMatrix filter to correct opacity
|
|
933
|
+
writer.start(
|
|
934
|
+
'filter',
|
|
935
|
+
id='colorMat')
|
|
936
|
+
writer.element(
|
|
937
|
+
'feColorMatrix',
|
|
938
|
+
type='matrix',
|
|
939
|
+
values='1 0 0 0 0 \n0 1 0 0 0 \n0 0 1 0 0 \n1 1 1 1 0 \n0 0 0 0 1 ')
|
|
940
|
+
writer.end('filter')
|
|
941
|
+
|
|
942
|
+
for points, colors in zip(triangles_array, colors_array):
|
|
943
|
+
self._draw_gouraud_triangle(trans_and_flip.transform(points), colors)
|
|
944
|
+
writer.end('g')
|
|
945
|
+
|
|
946
|
+
def option_scale_image(self):
|
|
947
|
+
# docstring inherited
|
|
948
|
+
return True
|
|
949
|
+
|
|
950
|
+
def get_image_magnification(self):
|
|
951
|
+
return self.image_dpi / 72.0
|
|
952
|
+
|
|
953
|
+
def draw_image(self, gc, x, y, im, transform=None):
|
|
954
|
+
# docstring inherited
|
|
955
|
+
|
|
956
|
+
h, w = im.shape[:2]
|
|
957
|
+
|
|
958
|
+
if w == 0 or h == 0:
|
|
959
|
+
return
|
|
960
|
+
|
|
961
|
+
clip_attrs = self._get_clip_attrs(gc)
|
|
962
|
+
if clip_attrs:
|
|
963
|
+
# Can't apply clip-path directly to the image because the image has
|
|
964
|
+
# a transformation, which would also be applied to the clip-path.
|
|
965
|
+
self.writer.start('g', **clip_attrs)
|
|
966
|
+
|
|
967
|
+
url = gc.get_url()
|
|
968
|
+
if url is not None:
|
|
969
|
+
self.writer.start('a', attrib={'xlink:href': url, 'target': '_blank'})
|
|
970
|
+
|
|
971
|
+
attrib = {}
|
|
972
|
+
oid = gc.get_gid()
|
|
973
|
+
if mpl.rcParams['svg.image_inline']:
|
|
974
|
+
buf = BytesIO()
|
|
975
|
+
buf.write(_png.encode(im))
|
|
976
|
+
oid = oid or self._make_id('image', buf.getvalue())
|
|
977
|
+
attrib['xlink:href'] = (
|
|
978
|
+
"data:image/png;base64,\n" +
|
|
979
|
+
base64.b64encode(buf.getvalue()).decode('ascii'))
|
|
980
|
+
else:
|
|
981
|
+
if self.basename is None:
|
|
982
|
+
raise ValueError("Cannot save image data to filesystem when "
|
|
983
|
+
"writing SVG to an in-memory buffer")
|
|
984
|
+
filename = f'{self.basename}.image{next(self._image_counter)}.png'
|
|
985
|
+
_log.info('Writing image file for inclusion: %s', filename)
|
|
986
|
+
_png.write(filename, im)
|
|
987
|
+
oid = oid or 'Im_' + self._make_id('image', filename)
|
|
988
|
+
attrib['xlink:href'] = filename
|
|
989
|
+
attrib['id'] = oid
|
|
990
|
+
|
|
991
|
+
if transform is None:
|
|
992
|
+
w = 72.0 * w / self.image_dpi
|
|
993
|
+
h = 72.0 * h / self.image_dpi
|
|
994
|
+
self.writer.element(
|
|
995
|
+
'image',
|
|
996
|
+
transform=_generate_transform([
|
|
997
|
+
('scale', (1, -1)), ('translate', (0, -h))]),
|
|
998
|
+
x=_short_float_fmt(x),
|
|
999
|
+
y=_short_float_fmt(-(self.height - y - h)),
|
|
1000
|
+
width=_short_float_fmt(w), height=_short_float_fmt(h),
|
|
1001
|
+
attrib=attrib,
|
|
1002
|
+
)
|
|
1003
|
+
else:
|
|
1004
|
+
alpha = gc.get_alpha()
|
|
1005
|
+
if alpha != 1.0:
|
|
1006
|
+
attrib['opacity'] = _short_float_fmt(alpha)
|
|
1007
|
+
flipped = (
|
|
1008
|
+
Affine2D().scale(1 / w, 1 / h)
|
|
1009
|
+
+ transform
|
|
1010
|
+
+ Affine2D().translate(x, y).scale(1, -1).translate(0, self.height))
|
|
1011
|
+
self.writer.element(
|
|
1012
|
+
'image',
|
|
1013
|
+
width=_short_float_fmt(w), height=_short_float_fmt(h),
|
|
1014
|
+
attrib=attrib,
|
|
1015
|
+
transform=_generate_transform([('matrix', flipped.frozen())]),
|
|
1016
|
+
style='image-rendering:crisp-edges;image-rendering:pixelated',
|
|
1017
|
+
)
|
|
1018
|
+
|
|
1019
|
+
if url is not None:
|
|
1020
|
+
self.writer.end('a')
|
|
1021
|
+
if clip_attrs:
|
|
1022
|
+
self.writer.end('g')
|
|
1023
|
+
|
|
1024
|
+
def _update_glyph_map_defs(self, glyph_map_new):
|
|
1025
|
+
"""
|
|
1026
|
+
Emit definitions for not-yet-defined glyphs, and record them as having
|
|
1027
|
+
been defined.
|
|
1028
|
+
"""
|
|
1029
|
+
writer = self.writer
|
|
1030
|
+
if glyph_map_new:
|
|
1031
|
+
writer.start('defs')
|
|
1032
|
+
for glyph_repr, (vertices, codes) in glyph_map_new.items():
|
|
1033
|
+
glyph_repr = self._adjust_glyph_repr(glyph_repr)
|
|
1034
|
+
# x64 to go back to FreeType's internal (integral) units.
|
|
1035
|
+
path_data = self._convert_path(
|
|
1036
|
+
Path(vertices * 64, codes), simplify=False)
|
|
1037
|
+
writer.element(
|
|
1038
|
+
'path', id=glyph_repr, d=path_data,
|
|
1039
|
+
transform=_generate_transform([('scale', (1 / 64,))]))
|
|
1040
|
+
writer.end('defs')
|
|
1041
|
+
self._glyph_map.update(glyph_map_new)
|
|
1042
|
+
|
|
1043
|
+
def _adjust_glyph_repr(self, glyph_repr):
|
|
1044
|
+
return glyph_repr.replace("%20", "_")
|
|
1045
|
+
|
|
1046
|
+
def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath, mtext=None):
|
|
1047
|
+
# docstring inherited
|
|
1048
|
+
writer = self.writer
|
|
1049
|
+
|
|
1050
|
+
writer.comment(s)
|
|
1051
|
+
|
|
1052
|
+
glyph_map = self._glyph_map
|
|
1053
|
+
|
|
1054
|
+
text2path = self._text2path
|
|
1055
|
+
color = rgb2hex(gc.get_rgb())
|
|
1056
|
+
fontsize = prop.get_size_in_points()
|
|
1057
|
+
if mtext is not None:
|
|
1058
|
+
features = mtext.get_fontfeatures()
|
|
1059
|
+
language = mtext.get_language()
|
|
1060
|
+
else:
|
|
1061
|
+
features = language = None
|
|
1062
|
+
|
|
1063
|
+
style = {}
|
|
1064
|
+
if color != '#000000':
|
|
1065
|
+
style['fill'] = color
|
|
1066
|
+
alpha = gc.get_alpha() if gc.get_forced_alpha() else gc.get_rgb()[3]
|
|
1067
|
+
if alpha != 1:
|
|
1068
|
+
style['opacity'] = _short_float_fmt(alpha)
|
|
1069
|
+
font_scale = fontsize / text2path.FONT_SCALE
|
|
1070
|
+
writer.start(
|
|
1071
|
+
'g',
|
|
1072
|
+
style=_generate_css(style),
|
|
1073
|
+
transform=_generate_transform([
|
|
1074
|
+
('translate', (x, y)),
|
|
1075
|
+
('rotate', (-angle,)),
|
|
1076
|
+
('scale', (font_scale, -font_scale)),
|
|
1077
|
+
]),
|
|
1078
|
+
)
|
|
1079
|
+
|
|
1080
|
+
if not ismath:
|
|
1081
|
+
font = text2path._get_font(prop)
|
|
1082
|
+
glyph_info, glyph_map_new, rects = text2path.get_glyphs_with_font(
|
|
1083
|
+
font, s, features=features, language=language,
|
|
1084
|
+
glyph_map=glyph_map, return_new_glyphs_only=True)
|
|
1085
|
+
self._update_glyph_map_defs(glyph_map_new)
|
|
1086
|
+
|
|
1087
|
+
for glyph_repr, xposition, yposition, scale in glyph_info:
|
|
1088
|
+
writer.element(
|
|
1089
|
+
'use',
|
|
1090
|
+
transform=_generate_transform([
|
|
1091
|
+
('translate', (xposition, yposition)),
|
|
1092
|
+
('scale', (scale,)),
|
|
1093
|
+
]),
|
|
1094
|
+
attrib={'xlink:href': f'#{glyph_repr}'})
|
|
1095
|
+
|
|
1096
|
+
else:
|
|
1097
|
+
if ismath == "TeX":
|
|
1098
|
+
_glyphs = text2path.get_glyphs_tex(
|
|
1099
|
+
prop, s, glyph_map=glyph_map, return_new_glyphs_only=True)
|
|
1100
|
+
else:
|
|
1101
|
+
_glyphs = text2path.get_glyphs_mathtext(
|
|
1102
|
+
prop, s, glyph_map=glyph_map, return_new_glyphs_only=True)
|
|
1103
|
+
glyph_info, glyph_map_new, rects = _glyphs
|
|
1104
|
+
self._update_glyph_map_defs(glyph_map_new)
|
|
1105
|
+
|
|
1106
|
+
for glyph_repr, xposition, yposition, scale in glyph_info:
|
|
1107
|
+
glyph_repr = self._adjust_glyph_repr(glyph_repr)
|
|
1108
|
+
writer.element(
|
|
1109
|
+
'use',
|
|
1110
|
+
transform=_generate_transform([
|
|
1111
|
+
('translate', (xposition, yposition)),
|
|
1112
|
+
('scale', (scale,)),
|
|
1113
|
+
]),
|
|
1114
|
+
attrib={'xlink:href': f'#{glyph_repr}'})
|
|
1115
|
+
|
|
1116
|
+
for verts, codes in rects:
|
|
1117
|
+
path = Path(verts, codes)
|
|
1118
|
+
path_data = self._convert_path(path, simplify=False)
|
|
1119
|
+
writer.element('path', d=path_data)
|
|
1120
|
+
|
|
1121
|
+
writer.end('g')
|
|
1122
|
+
|
|
1123
|
+
def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
|
|
1124
|
+
# NOTE: If you change the font styling CSS, then be sure the check for
|
|
1125
|
+
# svg.fonttype = none in `lib/matplotlib/testing/compare.py::convert` remains in
|
|
1126
|
+
# sync. Also be sure to re-generate any SVG using this mode, or else such tests
|
|
1127
|
+
# will fail to use the right converter for the expected images, and they will
|
|
1128
|
+
# fail strangely.
|
|
1129
|
+
writer = self.writer
|
|
1130
|
+
|
|
1131
|
+
color = rgb2hex(gc.get_rgb())
|
|
1132
|
+
font_style = {}
|
|
1133
|
+
color_style = {}
|
|
1134
|
+
if color != '#000000':
|
|
1135
|
+
color_style['fill'] = color
|
|
1136
|
+
|
|
1137
|
+
alpha = gc.get_alpha() if gc.get_forced_alpha() else gc.get_rgb()[3]
|
|
1138
|
+
if alpha != 1:
|
|
1139
|
+
color_style['opacity'] = _short_float_fmt(alpha)
|
|
1140
|
+
|
|
1141
|
+
if not ismath:
|
|
1142
|
+
attrib = {}
|
|
1143
|
+
|
|
1144
|
+
# Separate font style in their separate attributes
|
|
1145
|
+
if prop.get_style() != 'normal':
|
|
1146
|
+
font_style['font-style'] = prop.get_style()
|
|
1147
|
+
if prop.get_variant() != 'normal':
|
|
1148
|
+
font_style['font-variant'] = prop.get_variant()
|
|
1149
|
+
weight = prop.get_weight()
|
|
1150
|
+
weight = fm.weight_dict.get(weight, weight) # convert to int
|
|
1151
|
+
if weight != 400:
|
|
1152
|
+
font_style['font-weight'] = f'{weight}'
|
|
1153
|
+
|
|
1154
|
+
def _normalize_sans(name):
|
|
1155
|
+
return 'sans-serif' if name in ['sans', 'sans serif'] else name
|
|
1156
|
+
|
|
1157
|
+
def _expand_family_entry(fn):
|
|
1158
|
+
fn = _normalize_sans(fn)
|
|
1159
|
+
# prepend generic font families with all configured font names
|
|
1160
|
+
if fn in fm.font_family_aliases:
|
|
1161
|
+
# get all of the font names and fix spelling of sans-serif
|
|
1162
|
+
# (we accept 3 ways CSS only supports 1)
|
|
1163
|
+
for name in fm.FontManager._expand_aliases(fn):
|
|
1164
|
+
yield _normalize_sans(name)
|
|
1165
|
+
# whether a generic name or a family name, it must appear at
|
|
1166
|
+
# least once
|
|
1167
|
+
yield fn
|
|
1168
|
+
|
|
1169
|
+
def _get_all_quoted_names(prop):
|
|
1170
|
+
# only quote specific names, not generic names
|
|
1171
|
+
return [name if name in fm.font_family_aliases else repr(name)
|
|
1172
|
+
for entry in prop.get_family()
|
|
1173
|
+
for name in _expand_family_entry(entry)]
|
|
1174
|
+
|
|
1175
|
+
font_style['font-size'] = f'{_short_float_fmt(prop.get_size())}px'
|
|
1176
|
+
# ensure expansion, quoting, and dedupe of font names
|
|
1177
|
+
font_style['font-family'] = ", ".join(
|
|
1178
|
+
dict.fromkeys(_get_all_quoted_names(prop))
|
|
1179
|
+
)
|
|
1180
|
+
|
|
1181
|
+
if prop.get_stretch() != 'normal':
|
|
1182
|
+
font_style['font-stretch'] = prop.get_stretch()
|
|
1183
|
+
attrib['style'] = _generate_css({**font_style, **color_style})
|
|
1184
|
+
|
|
1185
|
+
if mtext and (angle == 0 or mtext.get_rotation_mode() == "anchor"):
|
|
1186
|
+
# If text anchoring can be supported, get the original
|
|
1187
|
+
# coordinates and add alignment information.
|
|
1188
|
+
|
|
1189
|
+
# Get anchor coordinates.
|
|
1190
|
+
transform = mtext.get_transform()
|
|
1191
|
+
ax, ay = transform.transform(mtext.get_unitless_position())
|
|
1192
|
+
ay = self.height - ay
|
|
1193
|
+
|
|
1194
|
+
# Don't do vertical anchor alignment. Most applications do not
|
|
1195
|
+
# support 'alignment-baseline' yet. Apply the vertical layout
|
|
1196
|
+
# to the anchor point manually for now.
|
|
1197
|
+
angle_rad = np.deg2rad(angle)
|
|
1198
|
+
dir_vert = np.array([np.sin(angle_rad), np.cos(angle_rad)])
|
|
1199
|
+
v_offset = np.dot(dir_vert, [(x - ax), (y - ay)])
|
|
1200
|
+
ax = ax + v_offset * dir_vert[0]
|
|
1201
|
+
ay = ay + v_offset * dir_vert[1]
|
|
1202
|
+
|
|
1203
|
+
ha_mpl_to_svg = {'left': 'start', 'right': 'end',
|
|
1204
|
+
'center': 'middle'}
|
|
1205
|
+
font_style['text-anchor'] = ha_mpl_to_svg[mtext.get_ha()]
|
|
1206
|
+
|
|
1207
|
+
attrib['x'] = _short_float_fmt(ax)
|
|
1208
|
+
attrib['y'] = _short_float_fmt(ay)
|
|
1209
|
+
attrib['style'] = _generate_css({**font_style, **color_style})
|
|
1210
|
+
attrib['transform'] = _generate_transform([
|
|
1211
|
+
("rotate", (-angle, ax, ay))])
|
|
1212
|
+
|
|
1213
|
+
else:
|
|
1214
|
+
attrib['transform'] = _generate_transform([
|
|
1215
|
+
('translate', (x, y)),
|
|
1216
|
+
('rotate', (-angle,))])
|
|
1217
|
+
|
|
1218
|
+
writer.element('text', s, attrib=attrib)
|
|
1219
|
+
|
|
1220
|
+
else:
|
|
1221
|
+
writer.comment(s)
|
|
1222
|
+
|
|
1223
|
+
width, height, descent, glyphs, rects = \
|
|
1224
|
+
self._text2path.mathtext_parser.parse(s, 72, prop)
|
|
1225
|
+
|
|
1226
|
+
# Apply attributes to 'g', not 'text', because we likely have some
|
|
1227
|
+
# rectangles as well with the same style and transformation.
|
|
1228
|
+
writer.start('g',
|
|
1229
|
+
style=_generate_css({**font_style, **color_style}),
|
|
1230
|
+
transform=_generate_transform([
|
|
1231
|
+
('translate', (x, y)),
|
|
1232
|
+
('rotate', (-angle,))]),
|
|
1233
|
+
)
|
|
1234
|
+
|
|
1235
|
+
writer.start('text')
|
|
1236
|
+
|
|
1237
|
+
# Sort the characters by font, and output one tspan for each.
|
|
1238
|
+
spans = {}
|
|
1239
|
+
for font, fontsize, ccode, glyph_index, new_x, new_y in glyphs:
|
|
1240
|
+
entry = fm.ttfFontProperty(font)
|
|
1241
|
+
font_style = {}
|
|
1242
|
+
# Separate font style in its separate attributes
|
|
1243
|
+
if entry.style != 'normal':
|
|
1244
|
+
font_style['font-style'] = entry.style
|
|
1245
|
+
if entry.variant != 'normal':
|
|
1246
|
+
font_style['font-variant'] = entry.variant
|
|
1247
|
+
if entry.weight != 400:
|
|
1248
|
+
font_style['font-weight'] = f'{entry.weight}'
|
|
1249
|
+
font_style['font-size'] = f'{_short_float_fmt(fontsize)}px'
|
|
1250
|
+
font_style['font-family'] = f'{entry.name!r}' # ensure quoting
|
|
1251
|
+
if entry.stretch != 'normal':
|
|
1252
|
+
font_style['font-stretch'] = entry.stretch
|
|
1253
|
+
style = _generate_css({**font_style, **color_style})
|
|
1254
|
+
if ccode == 32:
|
|
1255
|
+
ccode = 0xa0 # non-breaking space
|
|
1256
|
+
spans.setdefault(style, []).append((new_x, -new_y, ccode))
|
|
1257
|
+
|
|
1258
|
+
for style, chars in spans.items():
|
|
1259
|
+
chars.sort() # Sort by increasing x position
|
|
1260
|
+
for x, y, t in chars: # Output one tspan for each character
|
|
1261
|
+
writer.element(
|
|
1262
|
+
'tspan',
|
|
1263
|
+
chr(t),
|
|
1264
|
+
x=_short_float_fmt(x),
|
|
1265
|
+
y=_short_float_fmt(y),
|
|
1266
|
+
style=style)
|
|
1267
|
+
|
|
1268
|
+
writer.end('text')
|
|
1269
|
+
|
|
1270
|
+
for x, y, width, height in rects:
|
|
1271
|
+
writer.element(
|
|
1272
|
+
'rect',
|
|
1273
|
+
x=_short_float_fmt(x),
|
|
1274
|
+
y=_short_float_fmt(-y-1),
|
|
1275
|
+
width=_short_float_fmt(width),
|
|
1276
|
+
height=_short_float_fmt(height)
|
|
1277
|
+
)
|
|
1278
|
+
|
|
1279
|
+
writer.end('g')
|
|
1280
|
+
|
|
1281
|
+
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
|
|
1282
|
+
# docstring inherited
|
|
1283
|
+
|
|
1284
|
+
clip_attrs = self._get_clip_attrs(gc)
|
|
1285
|
+
if clip_attrs:
|
|
1286
|
+
# Cannot apply clip-path directly to the text, because
|
|
1287
|
+
# it has a transformation
|
|
1288
|
+
self.writer.start('g', **clip_attrs)
|
|
1289
|
+
|
|
1290
|
+
if gc.get_url() is not None:
|
|
1291
|
+
self.writer.start('a', {'xlink:href': gc.get_url(), 'target': '_blank'})
|
|
1292
|
+
|
|
1293
|
+
if mpl.rcParams['svg.fonttype'] == 'path':
|
|
1294
|
+
self._draw_text_as_path(gc, x, y, s, prop, angle, ismath, mtext)
|
|
1295
|
+
else:
|
|
1296
|
+
self._draw_text_as_text(gc, x, y, s, prop, angle, ismath, mtext)
|
|
1297
|
+
|
|
1298
|
+
if gc.get_url() is not None:
|
|
1299
|
+
self.writer.end('a')
|
|
1300
|
+
|
|
1301
|
+
if clip_attrs:
|
|
1302
|
+
self.writer.end('g')
|
|
1303
|
+
|
|
1304
|
+
def flipy(self):
|
|
1305
|
+
# docstring inherited
|
|
1306
|
+
return True
|
|
1307
|
+
|
|
1308
|
+
def get_canvas_width_height(self):
|
|
1309
|
+
# docstring inherited
|
|
1310
|
+
return self.width, self.height
|
|
1311
|
+
|
|
1312
|
+
def get_text_width_height_descent(self, s, prop, ismath):
|
|
1313
|
+
# docstring inherited
|
|
1314
|
+
return self._text2path.get_text_width_height_descent(s, prop, ismath)
|
|
1315
|
+
|
|
1316
|
+
|
|
1317
|
+
class FigureCanvasSVG(FigureCanvasBase):
|
|
1318
|
+
filetypes = {'svg': 'Scalable Vector Graphics',
|
|
1319
|
+
'svgz': 'Scalable Vector Graphics'}
|
|
1320
|
+
|
|
1321
|
+
fixed_dpi = 72
|
|
1322
|
+
|
|
1323
|
+
def print_svg(self, filename, *, bbox_inches_restore=None, metadata=None):
|
|
1324
|
+
"""
|
|
1325
|
+
Parameters
|
|
1326
|
+
----------
|
|
1327
|
+
filename : str or path-like or file-like
|
|
1328
|
+
Output target; if a string, a file will be opened for writing.
|
|
1329
|
+
|
|
1330
|
+
metadata : dict[str, Any], optional
|
|
1331
|
+
Metadata in the SVG file defined as key-value pairs of strings,
|
|
1332
|
+
datetimes, or lists of strings, e.g., ``{'Creator': 'My software',
|
|
1333
|
+
'Contributor': ['Me', 'My Friend'], 'Title': 'Awesome'}``.
|
|
1334
|
+
|
|
1335
|
+
The standard keys and their value types are:
|
|
1336
|
+
|
|
1337
|
+
* *str*: ``'Coverage'``, ``'Description'``, ``'Format'``,
|
|
1338
|
+
``'Identifier'``, ``'Language'``, ``'Relation'``, ``'Source'``,
|
|
1339
|
+
``'Title'``, and ``'Type'``.
|
|
1340
|
+
* *str* or *list of str*: ``'Contributor'``, ``'Creator'``,
|
|
1341
|
+
``'Keywords'``, ``'Publisher'``, and ``'Rights'``.
|
|
1342
|
+
* *str*, *date*, *datetime*, or *tuple* of same: ``'Date'``. If a
|
|
1343
|
+
non-*str*, then it will be formatted as ISO 8601.
|
|
1344
|
+
|
|
1345
|
+
Values have been predefined for ``'Creator'``, ``'Date'``,
|
|
1346
|
+
``'Format'``, and ``'Type'``. They can be removed by setting them
|
|
1347
|
+
to `None`.
|
|
1348
|
+
|
|
1349
|
+
Information is encoded as `Dublin Core Metadata`__.
|
|
1350
|
+
|
|
1351
|
+
.. _DC: https://www.dublincore.org/specifications/dublin-core/
|
|
1352
|
+
|
|
1353
|
+
__ DC_
|
|
1354
|
+
"""
|
|
1355
|
+
with cbook.open_file_cm(filename, "w", encoding="utf-8") as fh:
|
|
1356
|
+
if not cbook.file_requires_unicode(fh):
|
|
1357
|
+
fh = codecs.getwriter('utf-8')(fh)
|
|
1358
|
+
dpi = self.figure.dpi
|
|
1359
|
+
self.figure.dpi = 72
|
|
1360
|
+
width, height = self.figure.get_size_inches()
|
|
1361
|
+
w, h = width * 72, height * 72
|
|
1362
|
+
renderer = MixedModeRenderer(
|
|
1363
|
+
self.figure, width, height, dpi,
|
|
1364
|
+
RendererSVG(w, h, fh, image_dpi=dpi, metadata=metadata),
|
|
1365
|
+
bbox_inches_restore=bbox_inches_restore)
|
|
1366
|
+
self.figure.draw(renderer)
|
|
1367
|
+
renderer.finalize()
|
|
1368
|
+
|
|
1369
|
+
def print_svgz(self, filename, **kwargs):
|
|
1370
|
+
with (cbook.open_file_cm(filename, "wb") as fh,
|
|
1371
|
+
gzip.GzipFile(mode='w', fileobj=fh) as gzipwriter):
|
|
1372
|
+
return self.print_svg(gzipwriter, **kwargs)
|
|
1373
|
+
|
|
1374
|
+
def get_default_filetype(self):
|
|
1375
|
+
return 'svg'
|
|
1376
|
+
|
|
1377
|
+
def draw(self):
|
|
1378
|
+
self.figure.draw_without_rendering()
|
|
1379
|
+
return super().draw()
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
FigureManagerSVG = FigureManagerBase
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
svgProlog = """\
|
|
1386
|
+
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
|
1387
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
|
1388
|
+
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
1389
|
+
"""
|
|
1390
|
+
|
|
1391
|
+
|
|
1392
|
+
@_Backend.export
|
|
1393
|
+
class _BackendSVG(_Backend):
|
|
1394
|
+
backend_version = mpl.__version__
|
|
1395
|
+
FigureCanvas = FigureCanvasSVG
|