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.
Files changed (352) hide show
  1. docs/releases/0.0.1.md +268 -0
  2. docs/releases/0.0.2.md +69 -0
  3. docs/releases/0.0.3.md +80 -0
  4. docs/releases/0.0.4.md +73 -0
  5. docs/releases/0.0.5.md +24 -0
  6. docs/releases/0.0.6.md +24 -0
  7. docs/releases/0.0.7.md +24 -0
  8. docs/releases/0.0.8.md +16 -0
  9. licenses/LICENSE_CONTOURPY +29 -0
  10. licenses/LICENSE_CYCLER +27 -0
  11. licenses/LICENSE_DATEUTIL +54 -0
  12. licenses/LICENSE_KIWISOLVER +71 -0
  13. licenses/LICENSE_LIBWEBP +56 -0
  14. licenses/LICENSE_MATPLOTLIB +1253 -0
  15. licenses/LICENSE_PYPARSING +20 -0
  16. licenses/LICENSE_QHULL +39 -0
  17. licenses/LICENSE_SIX +18 -0
  18. matplotlib_rs/__init__.py +1683 -0
  19. matplotlib_rs/__main__.py +27 -0
  20. matplotlib_rs/_afm.py +500 -0
  21. matplotlib_rs/_animation_data.py +263 -0
  22. matplotlib_rs/_api/__init__.py +495 -0
  23. matplotlib_rs/_api/deprecation.py +534 -0
  24. matplotlib_rs/_axis_py.py +2991 -0
  25. matplotlib_rs/_blocking_input.py +31 -0
  26. matplotlib_rs/_cm.py +1500 -0
  27. matplotlib_rs/_cm_bivar.py +1289 -0
  28. matplotlib_rs/_cm_listed.py +2848 -0
  29. matplotlib_rs/_cm_multivar.py +167 -0
  30. matplotlib_rs/_color_data.py +1142 -0
  31. matplotlib_rs/_colormap.py +132 -0
  32. matplotlib_rs/_constrained_layout.py +825 -0
  33. matplotlib_rs/_contour.py +108 -0
  34. matplotlib_rs/_doc_cache.py +12214 -0
  35. matplotlib_rs/_docstring.py +142 -0
  36. matplotlib_rs/_enums.py +178 -0
  37. matplotlib_rs/_figure_rs.py +294 -0
  38. matplotlib_rs/_fontconfig_pattern.py +129 -0
  39. matplotlib_rs/_foreign.py +220 -0
  40. matplotlib_rs/_hook.py +94 -0
  41. matplotlib_rs/_image.py +160 -0
  42. matplotlib_rs/_imageio.py +229 -0
  43. matplotlib_rs/_internal_utils.py +65 -0
  44. matplotlib_rs/_kiwi.py +484 -0
  45. matplotlib_rs/_layoutgrid.py +549 -0
  46. matplotlib_rs/_live.py +192 -0
  47. matplotlib_rs/_mathtext.py +3103 -0
  48. matplotlib_rs/_mathtext_data.py +1811 -0
  49. matplotlib_rs/_mplrs.cp315-win_amd64.pyd +0 -0
  50. matplotlib_rs/_path.py +25 -0
  51. matplotlib_rs/_png.py +162 -0
  52. matplotlib_rs/_pylab_helpers.py +137 -0
  53. matplotlib_rs/_qhull.py +66 -0
  54. matplotlib_rs/_rcpush.py +84 -0
  55. matplotlib_rs/_spines_rs.py +108 -0
  56. matplotlib_rs/_style_helpers.py +52 -0
  57. matplotlib_rs/_text_helpers.py +51 -0
  58. matplotlib_rs/_tight_bbox.py +85 -0
  59. matplotlib_rs/_tight_layout.py +302 -0
  60. matplotlib_rs/_tri.py +140 -0
  61. matplotlib_rs/_type1font.py +1228 -0
  62. matplotlib_rs/_vendor/__init__.py +8 -0
  63. matplotlib_rs/_vendor/cycler.py +574 -0
  64. matplotlib_rs/_vendor/dateutil/__init__.py +27 -0
  65. matplotlib_rs/_vendor/dateutil/_common.py +44 -0
  66. matplotlib_rs/_vendor/dateutil/_tzdata_impl.py +148 -0
  67. matplotlib_rs/_vendor/dateutil/_version.py +5 -0
  68. matplotlib_rs/_vendor/dateutil/easter.py +90 -0
  69. matplotlib_rs/_vendor/dateutil/parser/__init__.py +62 -0
  70. matplotlib_rs/_vendor/dateutil/parser/_parser.py +1614 -0
  71. matplotlib_rs/_vendor/dateutil/parser/isoparser.py +417 -0
  72. matplotlib_rs/_vendor/dateutil/relativedelta.py +597 -0
  73. matplotlib_rs/_vendor/dateutil/rrule.py +1765 -0
  74. matplotlib_rs/_vendor/dateutil/tz/__init__.py +61 -0
  75. matplotlib_rs/_vendor/dateutil/tz/_common.py +420 -0
  76. matplotlib_rs/_vendor/dateutil/tz/_factories.py +81 -0
  77. matplotlib_rs/_vendor/dateutil/tz/_tzfile.py +1429 -0
  78. matplotlib_rs/_vendor/dateutil/tz/_tzpath.py +105 -0
  79. matplotlib_rs/_vendor/dateutil/tz/tz.py +1473 -0
  80. matplotlib_rs/_vendor/dateutil/tz/win.py +371 -0
  81. matplotlib_rs/_vendor/dateutil/tzwin.py +3 -0
  82. matplotlib_rs/_vendor/dateutil/utils.py +72 -0
  83. matplotlib_rs/_vendor/dateutil/zoneinfo/__init__.py +234 -0
  84. matplotlib_rs/_vendor/pyparsing/__init__.py +414 -0
  85. matplotlib_rs/_vendor/pyparsing/actions.py +265 -0
  86. matplotlib_rs/_vendor/pyparsing/common.py +571 -0
  87. matplotlib_rs/_vendor/pyparsing/core.py +6973 -0
  88. matplotlib_rs/_vendor/pyparsing/exceptions.py +354 -0
  89. matplotlib_rs/_vendor/pyparsing/helpers.py +1770 -0
  90. matplotlib_rs/_vendor/pyparsing/results.py +929 -0
  91. matplotlib_rs/_vendor/pyparsing/testing.py +399 -0
  92. matplotlib_rs/_vendor/pyparsing/unicode.py +357 -0
  93. matplotlib_rs/_vendor/pyparsing/util.py +515 -0
  94. matplotlib_rs/_vendor/pyparsing/warnings.py +11 -0
  95. matplotlib_rs/_vendor/six.py +1004 -0
  96. matplotlib_rs/animation.py +1843 -0
  97. matplotlib_rs/artist.py +2302 -0
  98. matplotlib_rs/axes/__init__.py +19 -0
  99. matplotlib_rs/axes/_axes.py +9402 -0
  100. matplotlib_rs/axes/_bar.py +185 -0
  101. matplotlib_rs/axes/_base.py +5236 -0
  102. matplotlib_rs/axes/_base_rs.py +727 -0
  103. matplotlib_rs/axes/_boxplot.py +391 -0
  104. matplotlib_rs/axes/_hist.py +99 -0
  105. matplotlib_rs/axes/_secondary_axes.py +357 -0
  106. matplotlib_rs/axis.py +1963 -0
  107. matplotlib_rs/backend_bases.py +3760 -0
  108. matplotlib_rs/backend_managers.py +388 -0
  109. matplotlib_rs/backend_tools.py +1002 -0
  110. matplotlib_rs/backends/__init__.py +6 -0
  111. matplotlib_rs/backends/_backend_pdf_ps.py +451 -0
  112. matplotlib_rs/backends/backend_agg.py +552 -0
  113. matplotlib_rs/backends/backend_mixed.py +123 -0
  114. matplotlib_rs/backends/backend_pdf.py +2711 -0
  115. matplotlib_rs/backends/backend_pgf.py +1031 -0
  116. matplotlib_rs/backends/backend_ps.py +1491 -0
  117. matplotlib_rs/backends/backend_svg.py +1395 -0
  118. matplotlib_rs/backends/backend_template.py +214 -0
  119. matplotlib_rs/backends/registry.py +423 -0
  120. matplotlib_rs/bezier.py +691 -0
  121. matplotlib_rs/category.py +236 -0
  122. matplotlib_rs/cbook.py +2762 -0
  123. matplotlib_rs/cm.py +251 -0
  124. matplotlib_rs/collections.py +2711 -0
  125. matplotlib_rs/colorbar.py +1586 -0
  126. matplotlib_rs/colorizer.py +909 -0
  127. matplotlib_rs/colors.py +4278 -0
  128. matplotlib_rs/container.py +256 -0
  129. matplotlib_rs/contour.py +1756 -0
  130. matplotlib_rs/dates.py +1847 -0
  131. matplotlib_rs/dviread.py +1386 -0
  132. matplotlib_rs/figure.py +3815 -0
  133. matplotlib_rs/font_manager.py +1855 -0
  134. matplotlib_rs/ft2font.py +515 -0
  135. matplotlib_rs/gridspec.py +808 -0
  136. matplotlib_rs/hatch.py +244 -0
  137. matplotlib_rs/image.py +1863 -0
  138. matplotlib_rs/inset.py +291 -0
  139. matplotlib_rs/layout_engine.py +310 -0
  140. matplotlib_rs/legend.py +1480 -0
  141. matplotlib_rs/legend_handler.py +812 -0
  142. matplotlib_rs/lines.py +1886 -0
  143. matplotlib_rs/markers.py +908 -0
  144. matplotlib_rs/mathtext.py +141 -0
  145. matplotlib_rs/mlab.py +959 -0
  146. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-Bold.ttf +0 -0
  147. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-BoldOblique.ttf +0 -0
  148. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans-Oblique.ttf +0 -0
  149. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSans.ttf +0 -0
  150. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansDisplay.ttf +0 -0
  151. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-Bold.ttf +0 -0
  152. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-BoldOblique.ttf +0 -0
  153. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono-Oblique.ttf +0 -0
  154. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSansMono.ttf +0 -0
  155. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-Bold.ttf +0 -0
  156. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-BoldItalic.ttf +0 -0
  157. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif-Italic.ttf +0 -0
  158. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerif.ttf +0 -0
  159. matplotlib_rs/mpl-data/fonts/ttf/DejaVuSerifDisplay.ttf +0 -0
  160. matplotlib_rs/mpl-data/fonts/ttf/LICENSE_DEJAVU +99 -0
  161. matplotlib_rs/mpl-data/fonts/ttf/LICENSE_STIX +124 -0
  162. matplotlib_rs/mpl-data/fonts/ttf/LastResortHE-Regular.ttf +0 -0
  163. matplotlib_rs/mpl-data/fonts/ttf/STIXGeneral.ttf +0 -0
  164. matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralBol.ttf +0 -0
  165. matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralBolIta.ttf +0 -0
  166. matplotlib_rs/mpl-data/fonts/ttf/STIXGeneralItalic.ttf +0 -0
  167. matplotlib_rs/mpl-data/fonts/ttf/STIXNonUni.ttf +0 -0
  168. matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniBol.ttf +0 -0
  169. matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniBolIta.ttf +0 -0
  170. matplotlib_rs/mpl-data/fonts/ttf/STIXNonUniIta.ttf +0 -0
  171. matplotlib_rs/mpl-data/fonts/ttf/STIXSizFiveSymReg.ttf +0 -0
  172. matplotlib_rs/mpl-data/fonts/ttf/STIXSizFourSymBol.ttf +0 -0
  173. matplotlib_rs/mpl-data/fonts/ttf/STIXSizFourSymReg.ttf +0 -0
  174. matplotlib_rs/mpl-data/fonts/ttf/STIXSizOneSymBol.ttf +0 -0
  175. matplotlib_rs/mpl-data/fonts/ttf/STIXSizOneSymReg.ttf +0 -0
  176. matplotlib_rs/mpl-data/fonts/ttf/STIXSizThreeSymBol.ttf +0 -0
  177. matplotlib_rs/mpl-data/fonts/ttf/STIXSizThreeSymReg.ttf +0 -0
  178. matplotlib_rs/mpl-data/fonts/ttf/STIXSizTwoSymBol.ttf +0 -0
  179. matplotlib_rs/mpl-data/fonts/ttf/STIXSizTwoSymReg.ttf +0 -0
  180. matplotlib_rs/mpl-data/fonts/ttf/cmb10.ttf +0 -0
  181. matplotlib_rs/mpl-data/fonts/ttf/cmex10.ttf +0 -0
  182. matplotlib_rs/mpl-data/fonts/ttf/cmmi10.ttf +0 -0
  183. matplotlib_rs/mpl-data/fonts/ttf/cmr10.ttf +0 -0
  184. matplotlib_rs/mpl-data/fonts/ttf/cmss10.ttf +0 -0
  185. matplotlib_rs/mpl-data/fonts/ttf/cmsy10.ttf +0 -0
  186. matplotlib_rs/mpl-data/fonts/ttf/cmti10.ttf +0 -0
  187. matplotlib_rs/mpl-data/fonts/ttf/cmtt10.ttf +0 -0
  188. matplotlib_rs/mpl-data/images/back-symbolic.svg +46 -0
  189. matplotlib_rs/mpl-data/images/back.pdf +0 -0
  190. matplotlib_rs/mpl-data/images/back.png +0 -0
  191. matplotlib_rs/mpl-data/images/back.svg +46 -0
  192. matplotlib_rs/mpl-data/images/back_large.png +0 -0
  193. matplotlib_rs/mpl-data/images/filesave-symbolic.svg +68 -0
  194. matplotlib_rs/mpl-data/images/filesave.pdf +72 -0
  195. matplotlib_rs/mpl-data/images/filesave.png +0 -0
  196. matplotlib_rs/mpl-data/images/filesave.svg +68 -0
  197. matplotlib_rs/mpl-data/images/filesave_large.png +0 -0
  198. matplotlib_rs/mpl-data/images/forward-symbolic.svg +46 -0
  199. matplotlib_rs/mpl-data/images/forward.pdf +0 -0
  200. matplotlib_rs/mpl-data/images/forward.png +0 -0
  201. matplotlib_rs/mpl-data/images/forward.svg +46 -0
  202. matplotlib_rs/mpl-data/images/forward_large.png +0 -0
  203. matplotlib_rs/mpl-data/images/hand.pdf +0 -0
  204. matplotlib_rs/mpl-data/images/hand.png +0 -0
  205. matplotlib_rs/mpl-data/images/hand.svg +130 -0
  206. matplotlib_rs/mpl-data/images/help-symbolic.svg +52 -0
  207. matplotlib_rs/mpl-data/images/help.pdf +71 -0
  208. matplotlib_rs/mpl-data/images/help.png +0 -0
  209. matplotlib_rs/mpl-data/images/help.svg +52 -0
  210. matplotlib_rs/mpl-data/images/help_large.png +0 -0
  211. matplotlib_rs/mpl-data/images/home-symbolic.svg +59 -0
  212. matplotlib_rs/mpl-data/images/home.pdf +0 -0
  213. matplotlib_rs/mpl-data/images/home.png +0 -0
  214. matplotlib_rs/mpl-data/images/home.svg +59 -0
  215. matplotlib_rs/mpl-data/images/home_large.png +0 -0
  216. matplotlib_rs/mpl-data/images/matplotlib.pdf +0 -0
  217. matplotlib_rs/mpl-data/images/matplotlib.png +0 -0
  218. matplotlib_rs/mpl-data/images/matplotlib.svg +3171 -0
  219. matplotlib_rs/mpl-data/images/matplotlib_large.png +0 -0
  220. matplotlib_rs/mpl-data/images/move-symbolic.svg +73 -0
  221. matplotlib_rs/mpl-data/images/move.pdf +0 -0
  222. matplotlib_rs/mpl-data/images/move.png +0 -0
  223. matplotlib_rs/mpl-data/images/move.svg +73 -0
  224. matplotlib_rs/mpl-data/images/move_large.png +0 -0
  225. matplotlib_rs/mpl-data/images/qt4_editor_options.pdf +0 -0
  226. matplotlib_rs/mpl-data/images/qt4_editor_options.png +0 -0
  227. matplotlib_rs/mpl-data/images/qt4_editor_options.svg +48 -0
  228. matplotlib_rs/mpl-data/images/qt4_editor_options_large.png +0 -0
  229. matplotlib_rs/mpl-data/images/subplots-symbolic.svg +81 -0
  230. matplotlib_rs/mpl-data/images/subplots.pdf +0 -0
  231. matplotlib_rs/mpl-data/images/subplots.png +0 -0
  232. matplotlib_rs/mpl-data/images/subplots.svg +81 -0
  233. matplotlib_rs/mpl-data/images/subplots_large.png +0 -0
  234. matplotlib_rs/mpl-data/images/zoom_to_rect-symbolic.svg +40 -0
  235. matplotlib_rs/mpl-data/images/zoom_to_rect.pdf +69 -0
  236. matplotlib_rs/mpl-data/images/zoom_to_rect.png +0 -0
  237. matplotlib_rs/mpl-data/images/zoom_to_rect.svg +40 -0
  238. matplotlib_rs/mpl-data/images/zoom_to_rect_large.png +0 -0
  239. matplotlib_rs/mpl-data/kpsewhich.lua +4 -0
  240. matplotlib_rs/mpl-data/matplotlibrc +849 -0
  241. matplotlib_rs/mpl-data/plot_directive/plot_directive.css +16 -0
  242. matplotlib_rs/mpl-data/sample_data/Minduka_Present_Blue_Pack.png +0 -0
  243. matplotlib_rs/mpl-data/sample_data/README.txt +2 -0
  244. matplotlib_rs/mpl-data/sample_data/Stocks.csv +526 -0
  245. matplotlib_rs/mpl-data/sample_data/axes_grid/bivariate_normal.npy +0 -0
  246. matplotlib_rs/mpl-data/sample_data/data_x_x2_x3.csv +11 -0
  247. matplotlib_rs/mpl-data/sample_data/eeg.dat +0 -0
  248. matplotlib_rs/mpl-data/sample_data/embedding_in_wx3.xrc +65 -0
  249. matplotlib_rs/mpl-data/sample_data/goog.npz +0 -0
  250. matplotlib_rs/mpl-data/sample_data/grace_hopper.jpg +0 -0
  251. matplotlib_rs/mpl-data/sample_data/jacksboro_fault_dem.npz +0 -0
  252. matplotlib_rs/mpl-data/sample_data/logo2.png +0 -0
  253. matplotlib_rs/mpl-data/sample_data/membrane.dat +0 -0
  254. matplotlib_rs/mpl-data/sample_data/msft.csv +66 -0
  255. matplotlib_rs/mpl-data/sample_data/s1045.ima.gz +0 -0
  256. matplotlib_rs/mpl-data/sample_data/topobathy.npz +0 -0
  257. matplotlib_rs/mpl-data/stylelib/Solarize_Light2.mplstyle +53 -0
  258. matplotlib_rs/mpl-data/stylelib/_classic_test_patch.mplstyle +8 -0
  259. matplotlib_rs/mpl-data/stylelib/_mpl-gallery-nogrid.mplstyle +19 -0
  260. matplotlib_rs/mpl-data/stylelib/_mpl-gallery.mplstyle +19 -0
  261. matplotlib_rs/mpl-data/stylelib/bmh.mplstyle +27 -0
  262. matplotlib_rs/mpl-data/stylelib/classic.mplstyle +491 -0
  263. matplotlib_rs/mpl-data/stylelib/dark_background.mplstyle +26 -0
  264. matplotlib_rs/mpl-data/stylelib/fast.mplstyle +11 -0
  265. matplotlib_rs/mpl-data/stylelib/fivethirtyeight.mplstyle +37 -0
  266. matplotlib_rs/mpl-data/stylelib/ggplot.mplstyle +39 -0
  267. matplotlib_rs/mpl-data/stylelib/grayscale.mplstyle +29 -0
  268. matplotlib_rs/mpl-data/stylelib/petroff10.mplstyle +5 -0
  269. matplotlib_rs/mpl-data/stylelib/petroff6.mplstyle +5 -0
  270. matplotlib_rs/mpl-data/stylelib/petroff8.mplstyle +5 -0
  271. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-bright.mplstyle +3 -0
  272. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-colorblind.mplstyle +3 -0
  273. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-dark-palette.mplstyle +3 -0
  274. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-dark.mplstyle +30 -0
  275. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-darkgrid.mplstyle +30 -0
  276. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-deep.mplstyle +3 -0
  277. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-muted.mplstyle +3 -0
  278. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-notebook.mplstyle +21 -0
  279. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-paper.mplstyle +21 -0
  280. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-pastel.mplstyle +3 -0
  281. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-poster.mplstyle +21 -0
  282. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-talk.mplstyle +21 -0
  283. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-ticks.mplstyle +30 -0
  284. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-white.mplstyle +30 -0
  285. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8-whitegrid.mplstyle +30 -0
  286. matplotlib_rs/mpl-data/stylelib/seaborn-v0_8.mplstyle +57 -0
  287. matplotlib_rs/mpl-data/stylelib/tableau-colorblind10.mplstyle +3 -0
  288. matplotlib_rs/mpl_toolkits/__init__.py +3 -0
  289. matplotlib_rs/mpl_toolkits/axes_grid1/__init__.py +11 -0
  290. matplotlib_rs/mpl_toolkits/axes_grid1/anchored_artists.py +415 -0
  291. matplotlib_rs/mpl_toolkits/axes_grid1/axes_divider.py +619 -0
  292. matplotlib_rs/mpl_toolkits/axes_grid1/axes_grid.py +565 -0
  293. matplotlib_rs/mpl_toolkits/axes_grid1/axes_rgb.py +158 -0
  294. matplotlib_rs/mpl_toolkits/axes_grid1/axes_size.py +272 -0
  295. matplotlib_rs/mpl_toolkits/axes_grid1/inset_locator.py +525 -0
  296. matplotlib_rs/mpl_toolkits/axes_grid1/mpl_axes.py +129 -0
  297. matplotlib_rs/mpl_toolkits/axes_grid1/parasite_axes.py +261 -0
  298. matplotlib_rs/mpl_toolkits/axisartist/__init__.py +15 -0
  299. matplotlib_rs/mpl_toolkits/axisartist/angle_helper.py +396 -0
  300. matplotlib_rs/mpl_toolkits/axisartist/axes_divider.py +3 -0
  301. matplotlib_rs/mpl_toolkits/axisartist/axis_artist.py +1148 -0
  302. matplotlib_rs/mpl_toolkits/axisartist/axisline_style.py +193 -0
  303. matplotlib_rs/mpl_toolkits/axisartist/axislines.py +475 -0
  304. matplotlib_rs/mpl_toolkits/axisartist/floating_axes.py +265 -0
  305. matplotlib_rs/mpl_toolkits/axisartist/grid_finder.py +329 -0
  306. matplotlib_rs/mpl_toolkits/axisartist/grid_helper_curvelinear.py +353 -0
  307. matplotlib_rs/mpl_toolkits/axisartist/parasite_axes.py +8 -0
  308. matplotlib_rs/mpl_toolkits/mplot3d/__init__.py +4 -0
  309. matplotlib_rs/mpl_toolkits/mplot3d/art3d.py +1758 -0
  310. matplotlib_rs/mpl_toolkits/mplot3d/axes3d.py +4462 -0
  311. matplotlib_rs/mpl_toolkits/mplot3d/axis3d.py +807 -0
  312. matplotlib_rs/mpl_toolkits/mplot3d/proj3d.py +270 -0
  313. matplotlib_rs/offsetbox.py +1726 -0
  314. matplotlib_rs/patches.py +5049 -0
  315. matplotlib_rs/path.py +1147 -0
  316. matplotlib_rs/patheffects.py +512 -0
  317. matplotlib_rs/projections/__init__.py +126 -0
  318. matplotlib_rs/projections/geo.py +512 -0
  319. matplotlib_rs/projections/polar.py +1518 -0
  320. matplotlib_rs/pylab.py +68 -0
  321. matplotlib_rs/pyplot.py +4834 -0
  322. matplotlib_rs/quiver.py +1236 -0
  323. matplotlib_rs/rcsetup.py +3435 -0
  324. matplotlib_rs/sankey.py +815 -0
  325. matplotlib_rs/scale.py +1002 -0
  326. matplotlib_rs/spines.py +618 -0
  327. matplotlib_rs/stackplot.py +144 -0
  328. matplotlib_rs/streamplot.py +768 -0
  329. matplotlib_rs/style/__init__.py +269 -0
  330. matplotlib_rs/style/core.py +28 -0
  331. matplotlib_rs/table.py +860 -0
  332. matplotlib_rs/texmanager.py +375 -0
  333. matplotlib_rs/text.py +2412 -0
  334. matplotlib_rs/textpath.py +377 -0
  335. matplotlib_rs/ticker.py +3111 -0
  336. matplotlib_rs/transforms.py +3069 -0
  337. matplotlib_rs/tri/__init__.py +24 -0
  338. matplotlib_rs/tri/_triangulation.py +248 -0
  339. matplotlib_rs/tri/_tricontour.py +271 -0
  340. matplotlib_rs/tri/_trifinder.py +97 -0
  341. matplotlib_rs/tri/_triinterpolate.py +1575 -0
  342. matplotlib_rs/tri/_tripcolor.py +170 -0
  343. matplotlib_rs/tri/_triplot.py +87 -0
  344. matplotlib_rs/tri/_trirefine.py +308 -0
  345. matplotlib_rs/tri/_tritools.py +264 -0
  346. matplotlib_rs/typing.py +597 -0
  347. matplotlib_rs/units.py +196 -0
  348. matplotlib_rs/widgets.py +4455 -0
  349. matplotlib_rs-0.0.8.dist-info/METADATA +392 -0
  350. matplotlib_rs-0.0.8.dist-info/RECORD +352 -0
  351. matplotlib_rs-0.0.8.dist-info/WHEEL +4 -0
  352. matplotlib_rs-0.0.8.dist-info/sboms/matplotlib-rs.cyclonedx.json +4390 -0
@@ -0,0 +1,1031 @@
1
+ # Vendored from matplotlib 3.11 (see licenses/LICENSE_MATPLOTLIB), adapted for matplotlib_rs.
2
+ import codecs
3
+ import datetime
4
+ import functools
5
+ from io import BytesIO
6
+ import logging
7
+ import math
8
+ import os
9
+ import pathlib
10
+ import shutil
11
+ import subprocess
12
+ from tempfile import TemporaryDirectory
13
+ import weakref
14
+
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
+ )
21
+ from matplotlib_rs.backends.backend_mixed import MixedModeRenderer
22
+ from matplotlib_rs.backends.backend_pdf import (
23
+ _create_pdf_info_dict, _datetime_to_pdf)
24
+ from matplotlib_rs.path import Path
25
+ from matplotlib_rs.figure import Figure
26
+ from matplotlib_rs.font_manager import FontProperties
27
+ from matplotlib_rs._pylab_helpers import Gcf
28
+
29
+ _log = logging.getLogger(__name__)
30
+
31
+
32
+ _DOCUMENTCLASS = r"\documentclass{article}"
33
+
34
+
35
+ # Note: When formatting floating point values, it is important to use the
36
+ # %f/{:f} format rather than %s/{} to avoid triggering scientific notation,
37
+ # which is not recognized by TeX.
38
+
39
+ def _get_preamble():
40
+ """Prepare a LaTeX preamble based on the rcParams configuration."""
41
+ def _to_fontspec():
42
+ for command, family in [("setmainfont", "serif"),
43
+ ("setsansfont", "sans\\-serif"),
44
+ ("setmonofont", "monospace")]:
45
+ font_path = fm.findfont(family)
46
+ path = pathlib.Path(font_path)
47
+ yield r" \%s{%s}[Path=\detokenize{%s/}%s]" % (
48
+ command, path.name, path.parent.as_posix(),
49
+ f',FontIndex={font_path.face_index:d}' if path.suffix == '.ttc' else '')
50
+
51
+ font_size_pt = FontProperties(size=mpl.rcParams["font.size"]).get_size_in_points()
52
+ return "\n".join([
53
+ # Remove Matplotlib's custom command \mathdefault. (Not using
54
+ # \mathnormal instead since this looks odd with Computer Modern.)
55
+ r"\def\mathdefault#1{#1}",
56
+ # Use displaystyle for all math.
57
+ r"\everymath=\expandafter{\the\everymath\displaystyle}",
58
+ # Set up font sizes to match font.size setting.
59
+ # If present, use the KOMA package scrextend to adjust the standard
60
+ # LaTeX font commands (\tiny, ..., \normalsize, ..., \Huge) accordingly.
61
+ # Otherwise, only set \normalsize, manually.
62
+ r"\IfFileExists{scrextend.sty}{",
63
+ r" \usepackage[fontsize=%fpt]{scrextend}" % font_size_pt,
64
+ r"}{",
65
+ r" \renewcommand{\normalsize}{\fontsize{%f}{%f}\selectfont}"
66
+ % (font_size_pt, 1.2 * font_size_pt),
67
+ r" \normalsize",
68
+ r"}",
69
+ # Allow pgf.preamble to override the above definitions.
70
+ mpl.rcParams["pgf.preamble"],
71
+ *([
72
+ r"\ifdefined\pdftexversion\else % non-pdftex case.",
73
+ r" \usepackage{fontspec}",
74
+ *_to_fontspec(),
75
+ r"\fi"] if mpl.rcParams["pgf.rcfonts"] else []),
76
+ # Documented as "must come last".
77
+ mpl.texmanager._usepackage_if_not_loaded("underscore", option="strings"),
78
+ ])
79
+
80
+
81
+ # It's better to use only one unit for all coordinates, since the
82
+ # arithmetic in latex seems to produce inaccurate conversions.
83
+ latex_pt_to_in = 1. / 72.27
84
+ latex_in_to_pt = 1. / latex_pt_to_in
85
+ mpl_pt_to_in = 1. / 72.
86
+ mpl_in_to_pt = 1. / mpl_pt_to_in
87
+
88
+
89
+ def _tex_escape(text):
90
+ r"""
91
+ Do some necessary and/or useful substitutions for texts to be included in
92
+ LaTeX documents.
93
+ """
94
+ return text.replace("\N{MINUS SIGN}", r"\ensuremath{-}")
95
+
96
+
97
+ def _writeln(fh, line):
98
+ # Ending lines with a % prevents TeX from inserting spurious spaces
99
+ # (https://tex.stackexchange.com/questions/7453).
100
+ fh.write(line)
101
+ fh.write("%\n")
102
+
103
+
104
+ def _escape_and_apply_props(s, prop):
105
+ """
106
+ Generate a TeX string that renders string *s* with font properties *prop*,
107
+ also applying any required escapes to *s*.
108
+ """
109
+ commands = []
110
+
111
+ families = {"serif": r"\rmfamily", "sans": r"\sffamily",
112
+ "sans-serif": r"\sffamily", "monospace": r"\ttfamily"}
113
+ family = prop.get_family()[0]
114
+ if family in families:
115
+ commands.append(families[family])
116
+ elif not mpl.rcParams["pgf.rcfonts"]:
117
+ commands.append(r"\fontfamily{\familydefault}")
118
+ elif any(font.name == family for font in fm.fontManager.ttflist):
119
+ commands.append(
120
+ r"\ifdefined\pdftexversion\else\setmainfont{%s}\rmfamily\fi" % family)
121
+ else:
122
+ _log.warning("Ignoring unknown font: %s", family)
123
+
124
+ size = prop.get_size_in_points()
125
+ commands.append(r"\fontsize{%f}{%f}" % (size, size * 1.2))
126
+
127
+ styles = {"normal": r"", "italic": r"\itshape", "oblique": r"\slshape"}
128
+ commands.append(styles[prop.get_style()])
129
+
130
+ boldstyles = ["semibold", "demibold", "demi", "bold", "heavy",
131
+ "extra bold", "black"]
132
+ if prop.get_weight() in boldstyles:
133
+ commands.append(r"\bfseries")
134
+
135
+ commands.append(r"\selectfont")
136
+ return (
137
+ "{"
138
+ + "".join(commands)
139
+ + r"\catcode`\^=\active\def^{\ifmmode\sp\else\^{}\fi}"
140
+ # It should normally be enough to set the catcode of % to 12 ("normal
141
+ # character"); this works on TeXLive 2021 but not on 2018, so we just
142
+ # make it active too.
143
+ + r"\catcode`\%=\active\def%{\%}"
144
+ + _tex_escape(s)
145
+ + "}"
146
+ )
147
+
148
+
149
+ def _metadata_to_str(key, value):
150
+ """Convert metadata key/value to a form that hyperref accepts."""
151
+ if isinstance(value, datetime.datetime):
152
+ value = _datetime_to_pdf(value)
153
+ elif key == 'Trapped':
154
+ value = value.name.decode('ascii')
155
+ else:
156
+ value = str(value)
157
+
158
+ # ensure that metadata does not contain special TeX chars because we
159
+ # insert the metadata as raw text into the TeX source
160
+ invalid_chars = r"\{}[]()"
161
+ if any(c in value + key for c in invalid_chars):
162
+ raise ValueError(
163
+ f"Invalid metadata value for {key!r}: {value!r}. "
164
+ f"The value must not contain the chars {invalid_chars}.")
165
+
166
+ return f'{key}={{{value}}}'
167
+
168
+
169
+ def make_pdf_to_png_converter():
170
+ """Return a function that converts a pdf file to a png file."""
171
+ try:
172
+ mpl._get_executable_info("pdftocairo")
173
+ except mpl.ExecutableNotFoundError:
174
+ pass
175
+ else:
176
+ return lambda pdffile, pngfile, dpi: subprocess.check_output(
177
+ ["pdftocairo", "-singlefile", "-transp", "-png", "-r", "%d" % dpi,
178
+ pdffile, os.path.splitext(pngfile)[0]],
179
+ stderr=subprocess.STDOUT)
180
+ try:
181
+ gs_info = mpl._get_executable_info("gs")
182
+ except mpl.ExecutableNotFoundError:
183
+ pass
184
+ else:
185
+ return lambda pdffile, pngfile, dpi: subprocess.check_output(
186
+ [gs_info.executable,
187
+ '-dQUIET', '-dSAFER', '-dBATCH', '-dNOPAUSE', '-dNOPROMPT',
188
+ '-dUseCIEColor', '-dTextAlphaBits=4',
189
+ '-dGraphicsAlphaBits=4', '-dDOINTERPOLATE',
190
+ '-sDEVICE=pngalpha', '-sOutputFile=%s' % pngfile,
191
+ '-r%d' % dpi, pdffile],
192
+ stderr=subprocess.STDOUT)
193
+ raise RuntimeError("No suitable pdf to png renderer found.")
194
+
195
+
196
+ class LatexError(Exception):
197
+ def __init__(self, message, latex_output=""):
198
+ super().__init__(message)
199
+ self.latex_output = latex_output
200
+
201
+ def __str__(self):
202
+ s, = self.args
203
+ if self.latex_output:
204
+ s += "\n" + self.latex_output
205
+ return s
206
+
207
+
208
+ class LatexManager:
209
+ """
210
+ The LatexManager opens an instance of the LaTeX application for
211
+ determining the metrics of text elements. The LaTeX environment can be
212
+ modified by setting fonts and/or a custom preamble in `.rcParams`.
213
+ """
214
+
215
+ @staticmethod
216
+ def _build_latex_header():
217
+ latex_header = [
218
+ _DOCUMENTCLASS,
219
+ # Include TeX program name as a comment for cache invalidation.
220
+ # TeX does not allow this to be the first line.
221
+ rf"% !TeX program = {mpl.rcParams['pgf.texsystem']}",
222
+ # Test whether \includegraphics supports interpolate option.
223
+ r"\usepackage{graphicx}",
224
+ _get_preamble(),
225
+ r"\begin{document}",
226
+ r"\typeout{pgf_backend_query_start}",
227
+ ]
228
+ return "\n".join(latex_header)
229
+
230
+ @classmethod
231
+ def _get_cached_or_new(cls):
232
+ """
233
+ Return the previous LatexManager if the header and tex system did not
234
+ change, or a new instance otherwise.
235
+ """
236
+ return cls._get_cached_or_new_impl(cls._build_latex_header())
237
+
238
+ @classmethod
239
+ @functools.lru_cache(1)
240
+ def _get_cached_or_new_impl(cls, header): # Helper for _get_cached_or_new.
241
+ return cls()
242
+
243
+ def _stdin_writeln(self, s):
244
+ if self.latex is None:
245
+ self._setup_latex_process()
246
+ self.latex.stdin.write(s)
247
+ self.latex.stdin.write("\n")
248
+ self.latex.stdin.flush()
249
+
250
+ def _expect(self, s):
251
+ s = list(s)
252
+ chars = []
253
+ while True:
254
+ c = self.latex.stdout.read(1)
255
+ chars.append(c)
256
+ if chars[-len(s):] == s:
257
+ break
258
+ if not c:
259
+ self.latex.kill()
260
+ self.latex = None
261
+ raise LatexError("LaTeX process halted", "".join(chars))
262
+ return "".join(chars)
263
+
264
+ def _expect_prompt(self):
265
+ return self._expect("\n*")
266
+
267
+ def __init__(self):
268
+ # create a tmp directory for running latex, register it for deletion
269
+ self._tmpdir = TemporaryDirectory()
270
+ self.tmpdir = self._tmpdir.name
271
+ self._finalize_tmpdir = weakref.finalize(self, self._tmpdir.cleanup)
272
+
273
+ # test the LaTeX setup to ensure a clean startup of the subprocess
274
+ self._setup_latex_process(expect_reply=False)
275
+ stdout, stderr = self.latex.communicate("\n\\makeatletter\\@@end\n")
276
+ if self.latex.returncode != 0:
277
+ raise LatexError(
278
+ f"LaTeX errored (probably missing font or error in preamble) "
279
+ f"while processing the following input:\n"
280
+ f"{self._build_latex_header()}",
281
+ stdout)
282
+ self.latex = None # Will be set up on first use.
283
+ # Per-instance cache.
284
+ self._get_box_metrics = functools.lru_cache(self._get_box_metrics)
285
+
286
+ def _setup_latex_process(self, *, expect_reply=True):
287
+ # Open LaTeX process for real work; register it for deletion. On
288
+ # Windows, we must ensure that the subprocess has quit before being
289
+ # able to delete the tmpdir in which it runs; in order to do so, we
290
+ # must first `kill()` it, and then `communicate()` with or `wait()` on
291
+ # it.
292
+ try:
293
+ self.latex = subprocess.Popen(
294
+ [mpl.rcParams["pgf.texsystem"], "-halt-on-error", "-no-shell-escape"],
295
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,
296
+ encoding="utf-8", cwd=self.tmpdir)
297
+ except FileNotFoundError as err:
298
+ raise RuntimeError(
299
+ f"{mpl.rcParams['pgf.texsystem']!r} not found; install it or change "
300
+ f"rcParams['pgf.texsystem'] to an available TeX implementation"
301
+ ) from err
302
+ except OSError as err:
303
+ raise RuntimeError(
304
+ f"Error starting {mpl.rcParams['pgf.texsystem']!r}") from err
305
+
306
+ def finalize_latex(latex):
307
+ latex.kill()
308
+ try:
309
+ latex.communicate()
310
+ except RuntimeError:
311
+ latex.wait()
312
+
313
+ self._finalize_latex = weakref.finalize(
314
+ self, finalize_latex, self.latex)
315
+ # write header with 'pgf_backend_query_start' token
316
+ self._stdin_writeln(self._build_latex_header())
317
+ if expect_reply: # read until 'pgf_backend_query_start' token appears
318
+ self._expect("*pgf_backend_query_start")
319
+ self._expect_prompt()
320
+
321
+ def get_width_height_descent(self, text, prop):
322
+ """
323
+ Get the width, total height, and descent (in TeX points) for a text
324
+ typeset by the current LaTeX environment.
325
+ """
326
+ return self._get_box_metrics(_escape_and_apply_props(text, prop))
327
+
328
+ def _get_box_metrics(self, tex):
329
+ """
330
+ Get the width, total height and descent (in TeX points) for a TeX
331
+ command's output in the current LaTeX environment.
332
+ """
333
+ # This method gets wrapped in __init__ for per-instance caching.
334
+ self._stdin_writeln( # Send textbox to TeX & request metrics typeout.
335
+ # \sbox doesn't handle catcode assignments inside its argument,
336
+ # so repeat the assignment of the catcode of "^" and "%" outside.
337
+ r"{\catcode`\^=\active\catcode`\%%=\active\sbox0{%s}"
338
+ r"\typeout{\the\wd0,\the\ht0,\the\dp0}}"
339
+ % tex)
340
+ try:
341
+ answer = self._expect_prompt()
342
+ except LatexError as err:
343
+ # Here and below, use '{}' instead of {!r} to avoid doubling all
344
+ # backslashes.
345
+ raise ValueError("Error measuring {}\nLaTeX Output:\n{}"
346
+ .format(tex, err.latex_output)) from err
347
+ try:
348
+ # Parse metrics from the answer string. Last line is prompt, and
349
+ # next-to-last-line is blank line from \typeout.
350
+ width, height, offset = answer.splitlines()[-3].split(",")
351
+ except Exception as err:
352
+ raise ValueError("Error measuring {}\nLaTeX Output:\n{}"
353
+ .format(tex, answer)) from err
354
+ w, h, o = float(width[:-2]), float(height[:-2]), float(offset[:-2])
355
+ # The height returned from LaTeX goes from base to top;
356
+ # the height Matplotlib expects goes from bottom to top.
357
+ return w, h + o, o
358
+
359
+
360
+ @functools.lru_cache(1)
361
+ def _get_image_inclusion_command():
362
+ man = LatexManager._get_cached_or_new()
363
+ man._stdin_writeln(
364
+ r"\includegraphics[interpolate=true]{%s}"
365
+ # Don't mess with backslashes on Windows.
366
+ % cbook._get_data_path("images/matplotlib.png").as_posix())
367
+ try:
368
+ man._expect_prompt()
369
+ return r"\includegraphics"
370
+ except LatexError:
371
+ # Discard the broken manager.
372
+ LatexManager._get_cached_or_new_impl.cache_clear()
373
+ return r"\pgfimage"
374
+
375
+
376
+ class RendererPgf(RendererBase):
377
+
378
+ def __init__(self, figure, fh):
379
+ """
380
+ Create a new PGF renderer that translates any drawing instruction
381
+ into text commands to be interpreted in a latex pgfpicture environment.
382
+
383
+ Attributes
384
+ ----------
385
+ figure : `~matplotlib.figure.Figure`
386
+ Matplotlib figure to initialize height, width and dpi from.
387
+ fh : file-like
388
+ File handle for the output of the drawing commands.
389
+ """
390
+
391
+ super().__init__()
392
+ self.dpi = figure.dpi
393
+ self.fh = fh
394
+ self.figure = figure
395
+ self.image_counter = 0
396
+
397
+ def draw_markers(self, gc, marker_path, marker_trans, path, trans,
398
+ rgbFace=None):
399
+ # docstring inherited
400
+
401
+ _writeln(self.fh, r"\begin{pgfscope}")
402
+
403
+ # convert from display units to in
404
+ f = 1. / self.dpi
405
+
406
+ # set style and clip
407
+ self._print_pgf_clip(gc)
408
+ self._print_pgf_path_styles(gc, rgbFace)
409
+
410
+ # build marker definition
411
+ bl, tr = marker_path.get_extents(marker_trans).get_points()
412
+ coords = bl[0] * f, bl[1] * f, tr[0] * f, tr[1] * f
413
+ _writeln(self.fh,
414
+ r"\pgfsys@defobject{currentmarker}"
415
+ r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{" % coords)
416
+ self._print_pgf_path(None, marker_path, marker_trans)
417
+ self._pgf_path_draw(stroke=gc.get_linewidth() != 0.0,
418
+ fill=rgbFace is not None)
419
+ _writeln(self.fh, r"}")
420
+
421
+ maxcoord = 16383 / 72.27 * self.dpi # Max dimensions in LaTeX.
422
+ clip = (-maxcoord, -maxcoord, maxcoord, maxcoord)
423
+
424
+ # draw marker for each vertex
425
+ for point, code in path.iter_segments(trans, simplify=False,
426
+ clip=clip):
427
+ x, y = point[0] * f, point[1] * f
428
+ _writeln(self.fh, r"\begin{pgfscope}")
429
+ _writeln(self.fh, r"\pgfsys@transformshift{%fin}{%fin}" % (x, y))
430
+ _writeln(self.fh, r"\pgfsys@useobject{currentmarker}{}")
431
+ _writeln(self.fh, r"\end{pgfscope}")
432
+
433
+ _writeln(self.fh, r"\end{pgfscope}")
434
+
435
+ def draw_path(self, gc, path, transform, rgbFace=None):
436
+ # docstring inherited
437
+ _writeln(self.fh, r"\begin{pgfscope}")
438
+ # draw the path
439
+ self._print_pgf_clip(gc)
440
+ self._print_pgf_path_styles(gc, rgbFace)
441
+ self._print_pgf_path(gc, path, transform, rgbFace)
442
+ self._pgf_path_draw(stroke=gc.get_linewidth() != 0.0,
443
+ fill=rgbFace is not None)
444
+ _writeln(self.fh, r"\end{pgfscope}")
445
+
446
+ # if present, draw pattern on top
447
+ if gc.get_hatch():
448
+ _writeln(self.fh, r"\begin{pgfscope}")
449
+ self._print_pgf_path_styles(gc, rgbFace)
450
+
451
+ # combine clip and path for clipping
452
+ self._print_pgf_clip(gc)
453
+ self._print_pgf_path(gc, path, transform, rgbFace)
454
+ _writeln(self.fh, r"\pgfusepath{clip}")
455
+
456
+ # build pattern definition
457
+ _writeln(self.fh,
458
+ r"\pgfsys@defobject{currentpattern}"
459
+ r"{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}{")
460
+ _writeln(self.fh, r"\begin{pgfscope}")
461
+
462
+ # hatch linewidth and color
463
+ lw = gc.get_hatch_linewidth() * mpl_pt_to_in * latex_in_to_pt
464
+ hatch_rgba = gc.get_hatch_color()
465
+ _writeln(self.fh, r"\pgfsetlinewidth{%fpt}" % lw)
466
+ _writeln(self.fh,
467
+ r"\definecolor{currenthatch}{rgb}{%f,%f,%f}"
468
+ % hatch_rgba[:3])
469
+ _writeln(self.fh, r"\pgfsetstrokecolor{currenthatch}")
470
+ _writeln(self.fh, r"\pgfsetstrokeopacity{%f}" % hatch_rgba[3])
471
+
472
+ _writeln(self.fh,
473
+ r"\pgfpathrectangle"
474
+ r"{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}")
475
+ _writeln(self.fh, r"\pgfusepath{clip}")
476
+ scale = mpl.transforms.Affine2D().scale(self.dpi)
477
+ self._print_pgf_path(None, gc.get_hatch_path(), scale)
478
+ self._pgf_path_draw(stroke=True)
479
+ _writeln(self.fh, r"\end{pgfscope}")
480
+ _writeln(self.fh, r"}")
481
+ # repeat pattern, filling the bounding rect of the path
482
+ f = 1. / self.dpi
483
+ (xmin, ymin), (xmax, ymax) = \
484
+ path.get_extents(transform).get_points()
485
+ xmin, xmax = f * xmin, f * xmax
486
+ ymin, ymax = f * ymin, f * ymax
487
+ repx, repy = math.ceil(xmax - xmin), math.ceil(ymax - ymin)
488
+ _writeln(self.fh,
489
+ r"\pgfsys@transformshift{%fin}{%fin}" % (xmin, ymin))
490
+ for iy in range(repy):
491
+ for ix in range(repx):
492
+ _writeln(self.fh, r"\pgfsys@useobject{currentpattern}{}")
493
+ _writeln(self.fh, r"\pgfsys@transformshift{1in}{0in}")
494
+ _writeln(self.fh, r"\pgfsys@transformshift{-%din}{0in}" % repx)
495
+ _writeln(self.fh, r"\pgfsys@transformshift{0in}{1in}")
496
+
497
+ _writeln(self.fh, r"\end{pgfscope}")
498
+
499
+ def _print_pgf_clip(self, gc):
500
+ f = 1. / self.dpi
501
+ # check for clip box
502
+ bbox = gc.get_clip_rectangle()
503
+ if bbox:
504
+ p1, p2 = bbox.get_points()
505
+ w, h = p2 - p1
506
+ coords = p1[0] * f, p1[1] * f, w * f, h * f
507
+ _writeln(self.fh,
508
+ r"\pgfpathrectangle"
509
+ r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}"
510
+ % coords)
511
+ _writeln(self.fh, r"\pgfusepath{clip}")
512
+
513
+ # check for clip path
514
+ clippath, clippath_trans = gc.get_clip_path()
515
+ if clippath is not None:
516
+ self._print_pgf_path(gc, clippath, clippath_trans)
517
+ _writeln(self.fh, r"\pgfusepath{clip}")
518
+
519
+ def _print_pgf_path_styles(self, gc, rgbFace):
520
+ # cap style
521
+ capstyles = {"butt": r"\pgfsetbuttcap",
522
+ "round": r"\pgfsetroundcap",
523
+ "projecting": r"\pgfsetrectcap"}
524
+ _writeln(self.fh, capstyles[gc.get_capstyle()])
525
+
526
+ # join style
527
+ joinstyles = {"miter": r"\pgfsetmiterjoin",
528
+ "round": r"\pgfsetroundjoin",
529
+ "bevel": r"\pgfsetbeveljoin"}
530
+ _writeln(self.fh, joinstyles[gc.get_joinstyle()])
531
+
532
+ # filling
533
+ has_fill = rgbFace is not None
534
+
535
+ if gc.get_forced_alpha():
536
+ fillopacity = strokeopacity = gc.get_alpha()
537
+ else:
538
+ strokeopacity = gc.get_rgb()[3]
539
+ fillopacity = rgbFace[3] if has_fill and len(rgbFace) > 3 else 1.0
540
+
541
+ if has_fill:
542
+ _writeln(self.fh,
543
+ r"\definecolor{currentfill}{rgb}{%f,%f,%f}"
544
+ % tuple(rgbFace[:3]))
545
+ _writeln(self.fh, r"\pgfsetfillcolor{currentfill}")
546
+ if has_fill and fillopacity != 1.0:
547
+ _writeln(self.fh, r"\pgfsetfillopacity{%f}" % fillopacity)
548
+
549
+ # linewidth and color
550
+ lw = gc.get_linewidth() * mpl_pt_to_in * latex_in_to_pt
551
+ stroke_rgba = gc.get_rgb()
552
+ _writeln(self.fh, r"\pgfsetlinewidth{%fpt}" % lw)
553
+ _writeln(self.fh,
554
+ r"\definecolor{currentstroke}{rgb}{%f,%f,%f}"
555
+ % stroke_rgba[:3])
556
+ _writeln(self.fh, r"\pgfsetstrokecolor{currentstroke}")
557
+ if strokeopacity != 1.0:
558
+ _writeln(self.fh, r"\pgfsetstrokeopacity{%f}" % strokeopacity)
559
+
560
+ # line style
561
+ dash_offset, dash_list = gc.get_dashes()
562
+ if dash_list is None:
563
+ _writeln(self.fh, r"\pgfsetdash{}{0pt}")
564
+ else:
565
+ _writeln(self.fh,
566
+ r"\pgfsetdash{%s}{%fpt}"
567
+ % ("".join(r"{%fpt}" % dash for dash in dash_list),
568
+ dash_offset))
569
+
570
+ def _print_pgf_path(self, gc, path, transform, rgbFace=None):
571
+ f = 1. / self.dpi
572
+ # check for clip box / ignore clip for filled paths
573
+ bbox = gc.get_clip_rectangle() if gc else None
574
+ maxcoord = 16383 / 72.27 * self.dpi # Max dimensions in LaTeX.
575
+ if bbox and (rgbFace is None):
576
+ p1, p2 = bbox.get_points()
577
+ clip = (max(p1[0], -maxcoord), max(p1[1], -maxcoord),
578
+ min(p2[0], maxcoord), min(p2[1], maxcoord))
579
+ else:
580
+ clip = (-maxcoord, -maxcoord, maxcoord, maxcoord)
581
+ # build path
582
+ for points, code in path.iter_segments(transform, clip=clip):
583
+ if code == Path.MOVETO:
584
+ x, y = tuple(points)
585
+ _writeln(self.fh,
586
+ r"\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}" %
587
+ (f * x, f * y))
588
+ elif code == Path.CLOSEPOLY:
589
+ _writeln(self.fh, r"\pgfpathclose")
590
+ elif code == Path.LINETO:
591
+ x, y = tuple(points)
592
+ _writeln(self.fh,
593
+ r"\pgfpathlineto{\pgfqpoint{%fin}{%fin}}" %
594
+ (f * x, f * y))
595
+ elif code == Path.CURVE3:
596
+ cx, cy, px, py = tuple(points)
597
+ coords = cx * f, cy * f, px * f, py * f
598
+ _writeln(self.fh,
599
+ r"\pgfpathquadraticcurveto"
600
+ r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}"
601
+ % coords)
602
+ elif code == Path.CURVE4:
603
+ c1x, c1y, c2x, c2y, px, py = tuple(points)
604
+ coords = c1x * f, c1y * f, c2x * f, c2y * f, px * f, py * f
605
+ _writeln(self.fh,
606
+ r"\pgfpathcurveto"
607
+ r"{\pgfqpoint{%fin}{%fin}}"
608
+ r"{\pgfqpoint{%fin}{%fin}}"
609
+ r"{\pgfqpoint{%fin}{%fin}}"
610
+ % coords)
611
+
612
+ # apply pgf decorators
613
+ sketch_params = gc.get_sketch_params() if gc else None
614
+ if sketch_params is not None:
615
+ # Only "length" directly maps to "segment length" in PGF's API.
616
+ # PGF uses "amplitude" to pass the combined deviation in both x-
617
+ # and y-direction, while matplotlib only varies the length of the
618
+ # wiggle along the line ("randomness" and "length" parameters)
619
+ # and has a separate "scale" argument for the amplitude.
620
+ # -> Use "randomness" as PRNG seed to allow the user to force the
621
+ # same shape on multiple sketched lines
622
+ scale, length, randomness = sketch_params
623
+ if scale is not None:
624
+ # make matplotlib and PGF rendering visually similar
625
+ length *= 0.5
626
+ scale *= 2
627
+ # PGF guarantees that repeated loading is a no-op
628
+ _writeln(self.fh, r"\usepgfmodule{decorations}")
629
+ _writeln(self.fh, r"\usepgflibrary{decorations.pathmorphing}")
630
+ _writeln(self.fh, r"\pgfkeys{/pgf/decoration/.cd, "
631
+ f"segment length = {(length * f):f}in, "
632
+ f"amplitude = {(scale * f):f}in}}")
633
+ _writeln(self.fh, f"\\pgfmathsetseed{{{int(randomness)}}}")
634
+ _writeln(self.fh, r"\pgfdecoratecurrentpath{random steps}")
635
+
636
+ def _pgf_path_draw(self, stroke=True, fill=False):
637
+ actions = []
638
+ if stroke:
639
+ actions.append("stroke")
640
+ if fill:
641
+ actions.append("fill")
642
+ _writeln(self.fh, r"\pgfusepath{%s}" % ",".join(actions))
643
+
644
+ def option_scale_image(self):
645
+ # docstring inherited
646
+ return True
647
+
648
+ def option_image_nocomposite(self):
649
+ # docstring inherited
650
+ return not mpl.rcParams['image.composite_image']
651
+
652
+ def draw_image(self, gc, x, y, im, transform=None):
653
+ # docstring inherited
654
+
655
+ h, w = im.shape[:2]
656
+ if w == 0 or h == 0:
657
+ return
658
+
659
+ if not os.path.exists(getattr(self.fh, "name", "")):
660
+ raise ValueError(
661
+ "streamed pgf-code does not support raster graphics, consider "
662
+ "using the pgf-to-pdf option")
663
+
664
+ # save the images to png files
665
+ path = pathlib.Path(self.fh.name)
666
+ fname_img = "%s-img%d.png" % (path.stem, self.image_counter)
667
+ _png.write(path.parent / fname_img, im[::-1])
668
+ self.image_counter += 1
669
+
670
+ # reference the image in the pgf picture
671
+ _writeln(self.fh, r"\begin{pgfscope}")
672
+ self._print_pgf_clip(gc)
673
+ f = 1. / self.dpi # from display coords to inch
674
+ if transform is None:
675
+ _writeln(self.fh,
676
+ r"\pgfsys@transformshift{%fin}{%fin}" % (x * f, y * f))
677
+ w, h = w * f, h * f
678
+ else:
679
+ tr1, tr2, tr3, tr4, tr5, tr6 = transform.frozen().to_values()
680
+ _writeln(self.fh,
681
+ r"\pgfsys@transformcm{%f}{%f}{%f}{%f}{%fin}{%fin}" %
682
+ (tr1 * f, tr2 * f, tr3 * f, tr4 * f,
683
+ (tr5 + x) * f, (tr6 + y) * f))
684
+ w = h = 1 # scale is already included in the transform
685
+ interp = str(transform is None).lower() # interpolation in PDF reader
686
+ _writeln(self.fh,
687
+ r"\pgftext[left,bottom]"
688
+ r"{%s[interpolate=%s,width=%fin,height=%fin]{%s}}" %
689
+ (_get_image_inclusion_command(),
690
+ interp, w, h, fname_img))
691
+ _writeln(self.fh, r"\end{pgfscope}")
692
+
693
+ def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None):
694
+ # docstring inherited
695
+ self.draw_text(gc, x, y, s, prop, angle, ismath="TeX", mtext=mtext)
696
+
697
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
698
+ # docstring inherited
699
+
700
+ # prepare string for tex
701
+ s = _escape_and_apply_props(s, prop)
702
+
703
+ _writeln(self.fh, r"\begin{pgfscope}")
704
+ self._print_pgf_clip(gc)
705
+
706
+ alpha = gc.get_alpha()
707
+ if alpha != 1.0:
708
+ _writeln(self.fh, r"\pgfsetfillopacity{%f}" % alpha)
709
+ _writeln(self.fh, r"\pgfsetstrokeopacity{%f}" % alpha)
710
+ rgb = tuple(gc.get_rgb())[:3]
711
+ _writeln(self.fh, r"\definecolor{textcolor}{rgb}{%f,%f,%f}" % rgb)
712
+ _writeln(self.fh, r"\pgfsetstrokecolor{textcolor}")
713
+ _writeln(self.fh, r"\pgfsetfillcolor{textcolor}")
714
+ s = r"\color{textcolor}" + s
715
+
716
+ dpi = self.figure.dpi
717
+ text_args = []
718
+ if mtext and (
719
+ (angle == 0 or
720
+ mtext.get_rotation_mode() == "anchor") and
721
+ mtext.get_verticalalignment() != "center_baseline"):
722
+ # if text anchoring can be supported, get the original coordinates
723
+ # and add alignment information
724
+ pos = mtext.get_unitless_position()
725
+ x, y = mtext.get_transform().transform(pos)
726
+ halign = {"left": "left", "right": "right", "center": ""}
727
+ valign = {"top": "top", "bottom": "bottom",
728
+ "baseline": "base", "center": ""}
729
+ text_args.extend([
730
+ f"x={x/dpi:f}in",
731
+ f"y={y/dpi:f}in",
732
+ halign[mtext.get_horizontalalignment()],
733
+ valign[mtext.get_verticalalignment()],
734
+ ])
735
+ else:
736
+ # if not, use the text layout provided by Matplotlib.
737
+ text_args.append(f"x={x/dpi:f}in, y={y/dpi:f}in, left, base")
738
+
739
+ if angle != 0:
740
+ text_args.append("rotate=%f" % angle)
741
+
742
+ _writeln(self.fh, r"\pgftext[%s]{%s}" % (",".join(text_args), s))
743
+ _writeln(self.fh, r"\end{pgfscope}")
744
+
745
+ def get_text_width_height_descent(self, s, prop, ismath):
746
+ # docstring inherited
747
+ # get text metrics in units of latex pt, convert to display units
748
+ w, h, d = (LatexManager._get_cached_or_new()
749
+ .get_width_height_descent(s, prop))
750
+ # TODO: this should be latex_pt_to_in instead of mpl_pt_to_in
751
+ # but having a little bit more space around the text looks better,
752
+ # plus the bounding box reported by LaTeX is VERY narrow
753
+ f = mpl_pt_to_in * self.dpi
754
+ return w * f, h * f, d * f
755
+
756
+ def flipy(self):
757
+ # docstring inherited
758
+ return False
759
+
760
+ def get_canvas_width_height(self):
761
+ # docstring inherited
762
+ return (self.figure.get_figwidth() * self.dpi,
763
+ self.figure.get_figheight() * self.dpi)
764
+
765
+ def points_to_pixels(self, points):
766
+ # docstring inherited
767
+ return points * mpl_pt_to_in * self.dpi
768
+
769
+
770
+ class FigureCanvasPgf(FigureCanvasBase):
771
+ filetypes = {"pgf": "LaTeX PGF picture",
772
+ "pdf": "LaTeX compiled PGF picture",
773
+ "png": "Portable Network Graphics", }
774
+
775
+ def get_default_filetype(self):
776
+ return 'pdf'
777
+
778
+ def _print_pgf_to_fh(self, fh, *, bbox_inches_restore=None):
779
+
780
+ header_text = """%% Creator: Matplotlib, PGF backend
781
+ %%
782
+ %% To include the figure in your LaTeX document, write
783
+ %% \\input{<filename>.pgf}
784
+ %%
785
+ %% Make sure the required packages are loaded in your preamble
786
+ %% \\usepackage{pgf}
787
+ %%
788
+ %% Also ensure that all the required font packages are loaded; for instance,
789
+ %% the lmodern package is sometimes necessary when using math font.
790
+ %% \\usepackage{lmodern}
791
+ %%
792
+ %% Figures using additional raster images can only be included by \\input if
793
+ %% they are in the same directory as the main LaTeX file. For loading figures
794
+ %% from other directories you can use the `import` package
795
+ %% \\usepackage{import}
796
+ %%
797
+ %% and then include the figures with
798
+ %% \\import{<path to file>}{<filename>.pgf}
799
+ %%
800
+ """
801
+
802
+ # append the preamble used by the backend as a comment for debugging
803
+ header_info_preamble = ["%% Matplotlib used the following preamble"]
804
+ for line in _get_preamble().splitlines():
805
+ header_info_preamble.append("%% " + line)
806
+ header_info_preamble.append("%%")
807
+ header_info_preamble = "\n".join(header_info_preamble)
808
+
809
+ # get figure size in inch
810
+ w, h = self.figure.get_figwidth(), self.figure.get_figheight()
811
+ dpi = self.figure.dpi
812
+
813
+ # create pgfpicture environment and write the pgf code
814
+ fh.write(header_text)
815
+ fh.write(header_info_preamble)
816
+ fh.write("\n")
817
+ _writeln(fh, r"\begingroup")
818
+ _writeln(fh, r"\makeatletter")
819
+ _writeln(fh, r"\begin{pgfpicture}")
820
+ _writeln(fh,
821
+ r"\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}"
822
+ % (w, h))
823
+ _writeln(fh, r"\pgfusepath{use as bounding box, clip}")
824
+ renderer = MixedModeRenderer(self.figure, w, h, dpi,
825
+ RendererPgf(self.figure, fh),
826
+ bbox_inches_restore=bbox_inches_restore)
827
+ self.figure.draw(renderer)
828
+
829
+ # end the pgfpicture environment
830
+ _writeln(fh, r"\end{pgfpicture}")
831
+ _writeln(fh, r"\makeatother")
832
+ _writeln(fh, r"\endgroup")
833
+
834
+ def print_pgf(self, fname_or_fh, **kwargs):
835
+ """
836
+ Output pgf macros for drawing the figure so it can be included and
837
+ rendered in latex documents.
838
+ """
839
+ with cbook.open_file_cm(fname_or_fh, "w", encoding="utf-8") as file:
840
+ if not cbook.file_requires_unicode(file):
841
+ file = codecs.getwriter("utf-8")(file)
842
+ self._print_pgf_to_fh(file, **kwargs)
843
+
844
+ def print_pdf(self, fname_or_fh, *, metadata=None, **kwargs):
845
+ """Use LaTeX to compile a pgf generated figure to pdf."""
846
+ w, h = self.figure.get_size_inches()
847
+
848
+ info_dict = _create_pdf_info_dict('pgf', metadata or {})
849
+ pdfinfo = ','.join(
850
+ _metadata_to_str(k, v) for k, v in info_dict.items())
851
+
852
+ # print figure to pgf and compile it with latex
853
+ with TemporaryDirectory() as tmpdir:
854
+ tmppath = pathlib.Path(tmpdir)
855
+ self.print_pgf(tmppath / "figure.pgf", **kwargs)
856
+ (tmppath / "figure.tex").write_text(
857
+ "\n".join([
858
+ _DOCUMENTCLASS,
859
+ r"\usepackage[pdfinfo={%s}]{hyperref}" % pdfinfo,
860
+ r"\usepackage[papersize={%fin,%fin}, margin=0in]{geometry}"
861
+ % (w, h),
862
+ r"\usepackage{pgf}",
863
+ _get_preamble(),
864
+ r"\begin{document}",
865
+ r"\centering",
866
+ r"\input{figure.pgf}",
867
+ r"\end{document}",
868
+ ]), encoding="utf-8")
869
+ texcommand = mpl.rcParams["pgf.texsystem"]
870
+ cbook._check_and_log_subprocess(
871
+ [texcommand, "-interaction=nonstopmode", "-halt-on-error",
872
+ "-no-shell-escape", "figure.tex"], _log, cwd=tmpdir)
873
+ with ((tmppath / "figure.pdf").open("rb") as orig,
874
+ cbook.open_file_cm(fname_or_fh, "wb") as dest):
875
+ shutil.copyfileobj(orig, dest) # copy file contents to target
876
+
877
+ def print_png(self, fname_or_fh, **kwargs):
878
+ """Use LaTeX to compile a pgf figure to pdf and convert it to png."""
879
+ converter = make_pdf_to_png_converter()
880
+ with TemporaryDirectory() as tmpdir:
881
+ tmppath = pathlib.Path(tmpdir)
882
+ pdf_path = tmppath / "figure.pdf"
883
+ png_path = tmppath / "figure.png"
884
+ self.print_pdf(pdf_path, **kwargs)
885
+ converter(pdf_path, png_path, dpi=self.figure.dpi)
886
+ with (png_path.open("rb") as orig,
887
+ cbook.open_file_cm(fname_or_fh, "wb") as dest):
888
+ shutil.copyfileobj(orig, dest) # copy file contents to target
889
+
890
+ def get_renderer(self):
891
+ return RendererPgf(self.figure, None)
892
+
893
+ def draw(self):
894
+ self.figure.draw_without_rendering()
895
+ return super().draw()
896
+
897
+
898
+ FigureManagerPgf = FigureManagerBase
899
+
900
+
901
+ @_Backend.export
902
+ class _BackendPgf(_Backend):
903
+ FigureCanvas = FigureCanvasPgf
904
+
905
+
906
+ class PdfPages:
907
+ """
908
+ A multi-page PDF file using the pgf backend
909
+
910
+ Examples
911
+ --------
912
+ >>> import matplotlib.pyplot as plt
913
+ >>> # Initialize:
914
+ >>> with PdfPages('foo.pdf') as pdf:
915
+ ... # As many times as you like, create a figure fig and save it:
916
+ ... fig = plt.figure()
917
+ ... pdf.savefig(fig)
918
+ ... # When no figure is specified the current figure is saved
919
+ ... pdf.savefig()
920
+ """
921
+
922
+ def __init__(self, filename, *, metadata=None):
923
+ """
924
+ Create a new PdfPages object.
925
+
926
+ Parameters
927
+ ----------
928
+ filename : str or path-like
929
+ Plots using `PdfPages.savefig` will be written to a file at this
930
+ location. Any older file with the same name is overwritten.
931
+
932
+ metadata : dict, optional
933
+ Information dictionary object (see PDF reference section 10.2.1
934
+ 'Document Information Dictionary'), e.g.:
935
+ ``{'Creator': 'My software', 'Author': 'Me', 'Title': 'Awesome'}``.
936
+
937
+ The standard keys are 'Title', 'Author', 'Subject', 'Keywords',
938
+ 'Creator', 'Producer', 'CreationDate', 'ModDate', and
939
+ 'Trapped'. Values have been predefined for 'Creator', 'Producer'
940
+ and 'CreationDate'. They can be removed by setting them to `None`.
941
+
942
+ Note that some versions of LaTeX engines may ignore the 'Producer'
943
+ key and set it to themselves.
944
+ """
945
+ self._output_name = filename
946
+ self._n_figures = 0
947
+ self._metadata = (metadata or {}).copy()
948
+ self._info_dict = _create_pdf_info_dict('pgf', self._metadata)
949
+ self._file = BytesIO()
950
+
951
+ def _write_header(self, width_inches, height_inches):
952
+ pdfinfo = ','.join(
953
+ _metadata_to_str(k, v) for k, v in self._info_dict.items())
954
+ latex_header = "\n".join([
955
+ _DOCUMENTCLASS,
956
+ r"\usepackage[pdfinfo={%s}]{hyperref}" % pdfinfo,
957
+ r"\usepackage[papersize={%fin,%fin}, margin=0in]{geometry}"
958
+ % (width_inches, height_inches),
959
+ r"\usepackage{pgf}",
960
+ _get_preamble(),
961
+ r"\setlength{\parindent}{0pt}",
962
+ r"\begin{document}%",
963
+ ])
964
+ self._file.write(latex_header.encode('utf-8'))
965
+
966
+ def __enter__(self):
967
+ return self
968
+
969
+ def __exit__(self, exc_type, exc_val, exc_tb):
970
+ self.close()
971
+
972
+ def close(self):
973
+ """
974
+ Finalize this object, running LaTeX in a temporary directory
975
+ and moving the final pdf file to *filename*.
976
+ """
977
+ self._file.write(rb'\end{document}\n')
978
+ if self._n_figures > 0:
979
+ self._run_latex()
980
+ self._file.close()
981
+
982
+ def _run_latex(self):
983
+ texcommand = mpl.rcParams["pgf.texsystem"]
984
+ with TemporaryDirectory() as tmpdir:
985
+ tex_source = pathlib.Path(tmpdir, "pdf_pages.tex")
986
+ tex_source.write_bytes(self._file.getvalue())
987
+ cbook._check_and_log_subprocess(
988
+ [texcommand, "-interaction=nonstopmode", "-halt-on-error",
989
+ "-no-shell-escape", tex_source],
990
+ _log, cwd=tmpdir)
991
+ shutil.move(tex_source.with_suffix(".pdf"), self._output_name)
992
+
993
+ def savefig(self, figure=None, **kwargs):
994
+ """
995
+ Save a `.Figure` to this file as a new page.
996
+
997
+ Any other keyword arguments are passed to `~.Figure.savefig`.
998
+
999
+ Parameters
1000
+ ----------
1001
+ figure : `.Figure` or int, default: the active figure
1002
+ The figure, or index of the figure, that is saved to the file.
1003
+ """
1004
+ if not isinstance(figure, Figure):
1005
+ if figure is None:
1006
+ manager = Gcf.get_active()
1007
+ else:
1008
+ manager = Gcf.get_fig_manager(figure)
1009
+ if manager is None:
1010
+ raise ValueError(f"No figure {figure}")
1011
+ figure = manager.canvas.figure
1012
+
1013
+ width, height = figure.get_size_inches()
1014
+ if self._n_figures == 0:
1015
+ self._write_header(width, height)
1016
+ else:
1017
+ # \pdfpagewidth and \pdfpageheight exist on pdftex, xetex, and
1018
+ # luatex<0.85; they were renamed to \pagewidth and \pageheight
1019
+ # on luatex>=0.85.
1020
+ self._file.write(
1021
+ rb'\newpage'
1022
+ rb'\ifdefined\pdfpagewidth\pdfpagewidth\else\pagewidth\fi=%fin'
1023
+ rb'\ifdefined\pdfpageheight\pdfpageheight\else\pageheight\fi=%fin'
1024
+ b'%%\n' % (width, height)
1025
+ )
1026
+ figure.savefig(self._file, format="pgf", backend="pgf", **kwargs)
1027
+ self._n_figures += 1
1028
+
1029
+ def get_pagecount(self):
1030
+ """Return the current number of pages in the multipage pdf file."""
1031
+ return self._n_figures