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,2302 @@
1
+ # Vendored from matplotlib 3.11 (see licenses/LICENSE_MATPLOTLIB), adapted for matplotlib_rs.
2
+ from collections import namedtuple
3
+ import contextlib
4
+ from functools import cache, reduce, wraps
5
+ import inspect
6
+ from inspect import Signature, Parameter
7
+ import logging
8
+ from numbers import Number, Real
9
+ import operator
10
+ import os
11
+ import re
12
+ import sys
13
+ import warnings
14
+
15
+ import numpy as np
16
+
17
+ import matplotlib_rs as mpl
18
+ from . import _api, _mplrs, cbook
19
+ from .path import Path
20
+ from .transforms import (BboxBase, Bbox, IdentityTransform, Transform, TransformedBbox,
21
+ TransformedPatchPath, TransformedPath)
22
+
23
+ _log = logging.getLogger(__name__)
24
+
25
+
26
+ def _prevent_rasterization(draw):
27
+ # We assume that by default artists are not allowed to rasterize (unless
28
+ # its draw method is explicitly decorated). If it is being drawn after a
29
+ # rasterized artist and it has reached a raster_depth of 0, we stop
30
+ # rasterization so that it does not affect the behavior of normal artist
31
+ # (e.g., change in dpi).
32
+
33
+ @wraps(draw)
34
+ def draw_wrapper(artist, renderer, *args, **kwargs):
35
+ if renderer._raster_depth == 0 and renderer._rasterizing:
36
+ # Only stop when we are not in a rasterized parent
37
+ # and something has been rasterized since last stop.
38
+ renderer.stop_rasterizing()
39
+ renderer._rasterizing = False
40
+
41
+ return draw(artist, renderer, *args, **kwargs)
42
+
43
+ draw_wrapper._supports_rasterization = False
44
+ return draw_wrapper
45
+
46
+
47
+ def allow_rasterization(draw):
48
+ """
49
+ Decorator for Artist.draw method. Provides routines
50
+ that run before and after the draw call. The before and after functions
51
+ are useful for changing artist-dependent renderer attributes or making
52
+ other setup function calls, such as starting and flushing a mixed-mode
53
+ renderer.
54
+ """
55
+
56
+ @wraps(draw)
57
+ def draw_wrapper(artist, renderer):
58
+ try:
59
+ if artist.get_rasterized():
60
+ if renderer._raster_depth == 0 and not renderer._rasterizing:
61
+ renderer.start_rasterizing()
62
+ renderer._rasterizing = True
63
+ renderer._raster_depth += 1
64
+ else:
65
+ if renderer._raster_depth == 0 and renderer._rasterizing:
66
+ # Only stop when we are not in a rasterized parent
67
+ # and something has be rasterized since last stop
68
+ renderer.stop_rasterizing()
69
+ renderer._rasterizing = False
70
+
71
+ if artist.get_agg_filter() is not None:
72
+ renderer.start_filter()
73
+
74
+ return draw(artist, renderer)
75
+ finally:
76
+ if artist.get_agg_filter() is not None:
77
+ renderer.stop_filter(artist.get_agg_filter())
78
+ if artist.get_rasterized():
79
+ renderer._raster_depth -= 1
80
+ if (renderer._rasterizing and (fig := artist.get_figure(root=True)) and
81
+ fig.suppressComposite):
82
+ # restart rasterizing to prevent merging
83
+ renderer.stop_rasterizing()
84
+ renderer.start_rasterizing()
85
+
86
+ draw_wrapper._supports_rasterization = True
87
+ return draw_wrapper
88
+
89
+
90
+ def _finalize_rasterization(draw):
91
+ """
92
+ Decorator for Artist.draw method. Needed on the outermost artist, i.e.
93
+ Figure, to finish up if the render is still in rasterized mode.
94
+ """
95
+ @wraps(draw)
96
+ def draw_wrapper(artist, renderer, *args, **kwargs):
97
+ result = draw(artist, renderer, *args, **kwargs)
98
+ if renderer._rasterizing:
99
+ renderer.stop_rasterizing()
100
+ renderer._rasterizing = False
101
+ return result
102
+ return draw_wrapper
103
+
104
+
105
+ def _stale_axes_callback(self, val):
106
+ if self.axes:
107
+ self.axes.stale = val
108
+
109
+
110
+ _XYPair = namedtuple("_XYPair", "x y")
111
+
112
+
113
+ import weakref as _weakref
114
+
115
+ #: Rust-backed artists whose Python state changed since the last sync.
116
+ _DIRTY = _weakref.WeakSet()
117
+
118
+
119
+ # >0 while the Rust core draws a figure: its state (synced before the draw)
120
+ # cannot change then, so changes made by Python code running inside the
121
+ # draw are pushed afterwards.
122
+ _DRAWING = [0]
123
+
124
+
125
+ @contextlib.contextmanager
126
+ def _rs_drawing():
127
+ _DRAWING[0] += 1
128
+ try:
129
+ yield
130
+ finally:
131
+ _DRAWING[0] -= 1
132
+
133
+
134
+ def _sync_dirty():
135
+ """Push the state of every changed artist into the Rust model."""
136
+ if _DRAWING[0]:
137
+ return
138
+ while _DIRTY:
139
+ items = list(_DIRTY)
140
+ _DIRTY.clear()
141
+ for a in items:
142
+ # move the artist between native and Python drawing first; the
143
+ # state of artists drawn by Python is not mirrored
144
+ switch = a.__dict__.get("_rs_switch")
145
+ if switch is not None:
146
+ switch(a)
147
+ native = a.__dict__.get("_rs_native_in")
148
+ if native is False:
149
+ continue
150
+ if (native is None and not isinstance(a, _RsOwned)
151
+ and isinstance(a.__dict__.get("_h"), _PLAIN_HANDLES)):
152
+ continue # never handed to the Rust model
153
+ sync = getattr(a, "_rs_sync", None)
154
+ if sync is not None:
155
+ sync()
156
+
157
+
158
+ # Rust twins of plain lines, texts and patches: only those given to the Rust
159
+ # model (flagged by ``_rs_native_in``) need their state mirrored.
160
+ _PLAIN_HANDLES = (_mplrs.Line2D, _mplrs.Text, _mplrs.Patch)
161
+
162
+
163
+ def _rs_clip_path(a):
164
+ """The clip path of *a* as (Path, transform spec), or None; raises
165
+ NotImplementedError if the Rust core cannot evaluate its transform."""
166
+ cp = a._clippath
167
+ if cp is None:
168
+ return None
169
+ from ._live import tspec
170
+ from .transforms import TransformedPatchPath
171
+ # (a TransformedPatchPath follows the path of its patch)
172
+ path = cp._patch.get_path() if isinstance(cp, TransformedPatchPath) else cp._path
173
+ return (path, tspec(cp._transform), cp)
174
+
175
+
176
+ def _rs_base_props(a, d):
177
+ """Common Artist properties for a Rust `set_many` call."""
178
+ from ._live import tspec
179
+ d["visible"] = bool(a._visible)
180
+ d["alpha"] = None if a._alpha is None else float(a._alpha)
181
+ d["zorder"] = float(a.zorder)
182
+ d["label"] = "" if a._label is None else str(a._label)
183
+ d["clip_on"] = bool(a._clipon)
184
+ d["snap"] = a._snap
185
+ d["in_layout"] = bool(a._in_layout)
186
+ d["sketch_params"] = a._sketch
187
+ d["gid"] = None if a._gid is None else str(a._gid)
188
+ d["url"] = None if a._url is None else str(a._url)
189
+ d["animated"] = bool(a._animated)
190
+ try:
191
+ d["clip_path"] = _rs_clip_path(a)
192
+ except NotImplementedError:
193
+ d["clip_path"] = None # (such artists are drawn by Python)
194
+ if a._transformSet or a._transform is not None:
195
+ try:
196
+ d["transform"] = tspec(a.get_transform())
197
+ except NotImplementedError:
198
+ pass
199
+ cb = a.clipbox
200
+ if cb is None:
201
+ d["clip_box"] = None
202
+ else:
203
+ spec = getattr(cb, "_rs_clip_spec", None)
204
+ if spec is None:
205
+ try:
206
+ (x0, y0), (x1, y1) = cb.get_points()
207
+ spec = (float(x0), float(y0), float(x1), float(y1))
208
+ except Exception:
209
+ spec = None
210
+ d["clip_box"] = spec
211
+ return d
212
+
213
+
214
+ _MISSING = object()
215
+
216
+
217
+ def _rs_same(a, b):
218
+ """Whether two `set_many` values are equal (pushing would be a no-op)."""
219
+ if a is b:
220
+ return not hasattr(a, "set_many") # Rust handles may have changed inside
221
+ if isinstance(a, np.ndarray) or isinstance(b, np.ndarray):
222
+ try:
223
+ return np.array_equal(a, b, equal_nan=True)
224
+ except TypeError:
225
+ return np.array_equal(a, b)
226
+ try:
227
+ return bool(a == b)
228
+ except Exception:
229
+ return False
230
+
231
+
232
+ class _RsOwned:
233
+ """
234
+ Mixin for Python views of artists owned by the Rust model (tick labels,
235
+ tick and grid lines, axis labels, titles, ...).
236
+
237
+ The view mirrors the Rust state when it is created (`_rs_refresh`) and
238
+ afterwards only pushes back the properties changed from Python, so Rust
239
+ keeps managing everything else (tick positions, label texts, ...).
240
+ """
241
+ _rs_snap = None
242
+ _rs_owner = None # the Python Axes or Figure whose Rust model holds it
243
+
244
+ @classmethod
245
+ def _from_rs(cls, h, owner=None):
246
+ self = cls._rs_blank()
247
+ self._rs_owner = owner
248
+ self.__dict__["_h"] = h
249
+ self._rs_refresh()
250
+ return self
251
+
252
+ def _rs_refresh(self):
253
+ """Re-read the Rust state (after pushing pending Python changes)."""
254
+ if self in _DIRTY:
255
+ _DIRTY.discard(self)
256
+ self._rs_sync()
257
+ h = self.__dict__.pop("_h")
258
+ try:
259
+ # skip re-reading a Rust object that has not changed
260
+ sig = h.state_hash() if hasattr(h, "state_hash") else None
261
+ if sig is not None and sig == self.__dict__.get("_rs_sig"):
262
+ return
263
+ self._rs_read(h.get)
264
+ finally:
265
+ self.__dict__["_h"] = h
266
+ self._rs_snap = self._rs_props()
267
+ self._rs_sig = sig
268
+
269
+ def _rs_sync(self):
270
+ d = self._rs_props()
271
+ snap = self._rs_snap
272
+ if snap is not None:
273
+ changed = {k: v for k, v in d.items()
274
+ if not _rs_same(snap.get(k, _MISSING), v)}
275
+ else:
276
+ changed = d
277
+ self._rs_snap = d
278
+ if changed:
279
+ self._h.set_many(changed)
280
+
281
+
282
+ def _rs_transform_from_spec(spec, axes, figure):
283
+ """A Python transform equivalent to a Rust transform spec."""
284
+ from . import transforms as mtransforms
285
+ if isinstance(spec, str):
286
+ if spec == "identity":
287
+ return mtransforms.IdentityTransform()
288
+ if spec == "data":
289
+ return axes.transData
290
+ if spec == "axes":
291
+ return axes.transAxes
292
+ if spec == "figure":
293
+ return figure.transFigure
294
+ if spec == "dpi":
295
+ return figure.dpi_scale_trans
296
+ raise ValueError(spec)
297
+ kind = spec[0]
298
+ if kind == "xaxis":
299
+ return axes.get_xaxis_transform(which=spec[1])
300
+ if kind == "yaxis":
301
+ return axes.get_yaxis_transform(which=spec[1])
302
+ if kind == "xtext1":
303
+ return axes.get_xaxis_text1_transform(spec[1])[0]
304
+ if kind == "xtext2":
305
+ return axes.get_xaxis_text2_transform(spec[1])[0]
306
+ if kind == "ytext1":
307
+ return axes.get_yaxis_text1_transform(spec[1])[0]
308
+ if kind == "ytext2":
309
+ return axes.get_yaxis_text2_transform(spec[1])[0]
310
+ if kind == "title":
311
+ return axes.transAxes + mtransforms.ScaledTranslation(
312
+ 0, spec[1] / 72, figure.dpi_scale_trans)
313
+ if kind == "affine":
314
+ m = np.eye(3)
315
+ m[:2] = spec[1]
316
+ return mtransforms.Affine2D(m)
317
+ if kind == "py":
318
+ return spec[1].t
319
+ if kind == "scaled_translation":
320
+ return mtransforms.ScaledTranslation(spec[1], spec[2], figure.dpi_scale_trans)
321
+ if kind == "then":
322
+ return (_rs_transform_from_spec(spec[1], axes, figure)
323
+ + _rs_transform_from_spec(spec[2], axes, figure))
324
+ if kind == "blend":
325
+ return mtransforms.blended_transform_factory(
326
+ _rs_transform_from_spec(spec[1], axes, figure),
327
+ _rs_transform_from_spec(spec[2], axes, figure))
328
+ if kind == "spine":
329
+ return axes.spines[("left", "right", "bottom", "top")[spec[1]]].get_spine_transform()
330
+ raise ValueError(spec)
331
+
332
+
333
+ class _LazyCallbacks:
334
+ """Class attribute standing in for an artist's ``_callbacks`` registry
335
+ until it is used (an artist's own registry, set by `Artist.__init__`,
336
+ takes precedence)."""
337
+
338
+ def __get__(self, obj, objtype=None):
339
+ if obj is None:
340
+ return self
341
+ registry = obj.__dict__["_callbacks"] = cbook.CallbackRegistry(signals=["pchanged"])
342
+ return registry
343
+
344
+
345
+ def _rs_axes_patch_transform(rect):
346
+ """
347
+ ``rect.get_transform()`` for the rectangle of an Axes: the same transform
348
+ object while the rectangle is unchanged.
349
+
350
+ Every artist added to an Axes is clipped to this rectangle
351
+ (``set_clip_path(axes.patch)``), and building the transform anew took
352
+ most of that call. The transform is a snapshot of the rectangle's
353
+ bounds, rotation and base transform, so it is reused only while these
354
+ are the same.
355
+ """
356
+ base = Artist.get_transform(rect)
357
+ key = (*rect._convert_units(), rect.angle, rect.rotation_point,
358
+ rect._aspect_ratio_correction)
359
+ if not all(isinstance(v, (int, float)) for v in key[:4]):
360
+ return rect.get_transform()
361
+ kept = rect.__dict__.get("_rs_clip_transform")
362
+ if kept is not None and kept[1] is base and kept[0] == key:
363
+ return kept[2]
364
+ trf = rect.get_transform()
365
+ rect._rs_clip_transform = (key, base, trf)
366
+ return trf
367
+
368
+
369
+ class Artist:
370
+ """
371
+ Abstract base class for objects that render into a FigureCanvas.
372
+
373
+ Typically, all visible elements in a figure are subclasses of Artist.
374
+ """
375
+
376
+ zorder = 0
377
+
378
+ def __init_subclass__(cls):
379
+
380
+ # Decorate draw() method so that all artists are able to stop
381
+ # rastrization when necessary. If the artist's draw method is already
382
+ # decorated (has a `_supports_rasterization` attribute), it won't be
383
+ # decorated.
384
+
385
+ if not hasattr(cls.draw, "_supports_rasterization"):
386
+ cls.draw = _prevent_rasterization(cls.draw)
387
+
388
+ # Inject custom set() methods into the subclass with signature and
389
+ # docstring based on the subclasses' properties.
390
+
391
+ if not hasattr(cls.set, '_autogenerated_signature'):
392
+ # Don't overwrite cls.set if the subclass or one of its parents
393
+ # has defined a set method set itself.
394
+ # If there was no explicit definition, cls.set is inherited from
395
+ # the hierarchy of auto-generated set methods, which hold the
396
+ # flag _autogenerated_signature.
397
+ return
398
+
399
+ cls.set = lambda self, **kwargs: Artist.set(self, **kwargs)
400
+ cls.set.__name__ = "set"
401
+ cls.set.__qualname__ = f"{cls.__qualname__}.set"
402
+ cls._update_set_signature_and_docstring()
403
+
404
+ _PROPERTIES_EXCLUDED_FROM_SET = [
405
+ 'navigate_mode', # not a user-facing function
406
+ 'figure', # changing the figure is such a profound operation
407
+ # that we don't want this in set()
408
+ '3d_properties', # cannot be used as a keyword due to leading digit
409
+ ]
410
+
411
+ @classmethod
412
+ def _update_set_signature_and_docstring(cls):
413
+ """
414
+ Update the signature of the set function to list all properties
415
+ as keyword arguments.
416
+
417
+ Property aliases are not listed in the signature for brevity, but
418
+ are still accepted as keyword arguments.
419
+ """
420
+ setters = _doc_cache_get(cls, "setters")
421
+ if setters is None:
422
+ setters = ArtistInspector(cls).get_setters()
423
+ cls.set.__signature__ = Signature(
424
+ [Parameter("self", Parameter.POSITIONAL_OR_KEYWORD),
425
+ *[Parameter(prop, Parameter.KEYWORD_ONLY, default=_api.UNSET)
426
+ for prop in setters
427
+ if prop not in Artist._PROPERTIES_EXCLUDED_FROM_SET]])
428
+ cls.set._autogenerated_signature = True
429
+
430
+ cls.set.__doc__ = ("""\
431
+ Set multiple properties at once.
432
+
433
+ ::
434
+
435
+ a.set(a=A, b=B, c=C)
436
+
437
+ is equivalent to ::
438
+
439
+ a.set_a(A)
440
+ a.set_b(B)
441
+ a.set_c(C)
442
+
443
+ In addition to the full property names, aliases are also supported, e.g.
444
+ ``set(lw=2)`` is equivalent to ``set(linewidth=2)``, but it is an error
445
+ to pass both simultaneously.
446
+
447
+ The order of the individual setter calls matches the order of parameters
448
+ in ``set()``. However, most properties do not depend on each other so
449
+ that order is rarely relevant.
450
+
451
+ Supported properties are
452
+
453
+ """ + kwdoc(cls))
454
+
455
+ def __init__(self):
456
+ self._stale = True
457
+ self.stale_callback = None
458
+ self._axes = None
459
+ self._parent_figure = None
460
+
461
+ self._transform = None
462
+ self._transformSet = False
463
+ self._visible = True
464
+ self._animated = False
465
+ self._alpha = None
466
+ self.clipbox = None
467
+ self._clippath = None
468
+ self._clipon = True
469
+ self._label = ''
470
+ self._picker = None
471
+ self._rasterized = False
472
+ self._agg_filter = None
473
+ # Normally, artist classes need to be queried for mouseover info if and
474
+ # only if they override get_cursor_data.
475
+ self._mouseover = type(self).get_cursor_data != Artist.get_cursor_data
476
+ self._callbacks = cbook.CallbackRegistry(signals=["pchanged"])
477
+ try:
478
+ self.axes = None
479
+ except AttributeError:
480
+ # Handle self.axes as a read-only property, as in Figure.
481
+ pass
482
+ self._remove_method = None
483
+ self._url = None
484
+ self._gid = None
485
+ self._snap = None
486
+ self._sketch = mpl.rcParams['path.sketch']
487
+ self._path_effects = mpl.rcParams['path.effects']
488
+ self._sticky_edges = None
489
+ self._in_layout = True
490
+ self._in_autoscale = False
491
+
492
+ # -- matplotlib_rs: mirror properties into the Rust artist -------------
493
+ _h = None # the Rust handle (set by subclasses)
494
+ # Artists cloned without a callback registry (boxplot's, see
495
+ # axes/_boxplot.py) create theirs on first use.
496
+ _callbacks = _LazyCallbacks()
497
+
498
+ def _rs_props(self):
499
+ return _rs_base_props(self, {})
500
+
501
+ def _rs_sync(self):
502
+ """Push this artist's state into its Rust twin."""
503
+ self._h.set_many(self._rs_props())
504
+
505
+ # Called by the Rust core for artists it does not draw itself; *target*
506
+ # is the renderer of the figure being drawn.
507
+ def _rs_draw(self, target):
508
+ if isinstance(target, _mplrs.RendererAgg):
509
+ from .backends.backend_agg import RendererAgg
510
+ target = RendererAgg._for_target(target)
511
+ self.draw(target)
512
+
513
+ def _rs_sticky_edges(self):
514
+ se = self._sticky_edges
515
+ if se is None:
516
+ return ([], [])
517
+ return ([float(v) for v in se.x], [float(v) for v in se.y])
518
+
519
+ def _rs_tightbbox(self, target, for_axes):
520
+ if not self.get_visible() or not self.get_in_layout():
521
+ return None
522
+ if for_axes and self._fully_clipped_to_axes():
523
+ return None
524
+ if isinstance(target, _mplrs.RendererAgg):
525
+ from .backends.backend_agg import RendererAgg
526
+ target = RendererAgg._for_target(target)
527
+ bb = self.get_tightbbox(target)
528
+ if bb is None:
529
+ return None
530
+ return tuple(map(float, bb.extents))
531
+
532
+ def _push(self, name, value):
533
+ h = self.__dict__.get("_h")
534
+ if h is not None:
535
+ h.set(name, value)
536
+
537
+ def __getstate__(self):
538
+ d = self.__dict__.copy()
539
+ d['stale_callback'] = None
540
+ return d
541
+
542
+ def remove(self):
543
+ """
544
+ Remove the artist from the figure if possible.
545
+
546
+ The effect will not be visible until the figure is redrawn, e.g.,
547
+ with `.FigureCanvasBase.draw_idle`. Call `~.axes.Axes.relim` to
548
+ update the Axes limits if desired.
549
+
550
+ Note: there is no support for removing the artist's legend entry.
551
+ """
552
+
553
+ # There is no method to set the callback. Instead, the parent should
554
+ # set the _remove_method attribute directly. This would be a
555
+ # protected attribute if Python supported that sort of thing. The
556
+ # callback has one parameter, which is the child to be removed.
557
+ if self._remove_method is not None:
558
+ self._remove_method(self)
559
+ # clear stale callback
560
+ self.stale_callback = None
561
+ _ax_flag = False
562
+ ax = getattr(self, 'axes', None)
563
+ mouseover_set = getattr(ax, '_mouseover_set', None)
564
+ if mouseover_set is not None:
565
+ # remove from the mouse hit list
566
+ mouseover_set.discard(self)
567
+ ax.stale = True
568
+ self.axes = None # decouple the artist from the Axes
569
+ _ax_flag = True
570
+
571
+ if (fig := self.get_figure(root=False)) is not None:
572
+ if not _ax_flag:
573
+ fig.stale = True
574
+ self._parent_figure = None
575
+
576
+ else:
577
+ raise NotImplementedError('cannot remove artist')
578
+
579
+ def have_units(self):
580
+ """Return whether units are set on any axis."""
581
+ ax = self.axes
582
+ return ax and any(axis.have_units() for axis in ax._axis_map.values())
583
+
584
+ def convert_xunits(self, x):
585
+ """
586
+ Convert *x* using the unit type of the xaxis.
587
+
588
+ If the artist is not contained in an Axes or if the xaxis does not
589
+ have units, *x* itself is returned.
590
+ """
591
+ ax = getattr(self, 'axes', None)
592
+ if ax is None or ax.xaxis is None:
593
+ return x
594
+ return ax.xaxis.convert_units(x)
595
+
596
+ def convert_yunits(self, y):
597
+ """
598
+ Convert *y* using the unit type of the yaxis.
599
+
600
+ If the artist is not contained in an Axes or if the yaxis does not
601
+ have units, *y* itself is returned.
602
+ """
603
+ ax = getattr(self, 'axes', None)
604
+ if ax is None or ax.yaxis is None:
605
+ return y
606
+ return ax.yaxis.convert_units(y)
607
+
608
+ @property
609
+ def axes(self):
610
+ """The `~.axes.Axes` instance the artist resides in, or *None*."""
611
+ return self._axes
612
+
613
+ @axes.setter
614
+ def axes(self, new_axes):
615
+ if (new_axes is not None and self._axes is not None
616
+ and new_axes != self._axes):
617
+ raise ValueError("Can not reset the Axes. You are probably trying to reuse "
618
+ "an artist in more than one Axes which is not supported")
619
+ self._axes = new_axes
620
+ if new_axes is not None and new_axes is not self:
621
+ self.stale_callback = _stale_axes_callback
622
+
623
+ @property
624
+ def stale(self):
625
+ """
626
+ Whether the artist is 'stale' and needs to be re-drawn for the output
627
+ to match the internal state of the artist.
628
+ """
629
+ return self._stale
630
+
631
+ @stale.setter
632
+ def stale(self, val):
633
+ self._stale = val
634
+ if val and self.__dict__.get("_h") is not None:
635
+ _DIRTY.add(self)
636
+
637
+ # if the artist is animated it does not take normal part in the
638
+ # draw stack and is not expected to be drawn as part of the normal
639
+ # draw loop (when not saving) so do not propagate this change
640
+ if self._animated:
641
+ return
642
+
643
+ if val and self.stale_callback is not None:
644
+ self.stale_callback(self, val)
645
+
646
+ def get_window_extent(self, renderer=None):
647
+ """
648
+ Get the artist's bounding box in display space, ignoring clipping.
649
+
650
+ The bounding box's width and height are non-negative.
651
+
652
+ Subclasses should override for inclusion in the bounding box "tight"
653
+ calculation. Default is to return an empty bounding box at 0, 0.
654
+
655
+ .. warning::
656
+
657
+ The extent can change due to any changes in the transform stack, such
658
+ as changing the Axes limits, the figure size, the canvas used (as is
659
+ done when saving a figure), or the DPI.
660
+
661
+ Relying on a once-retrieved window extent can lead to unexpected
662
+ behavior in various cases such as interactive figures being resized or
663
+ moved to a screen with different dpi, or figures that look fine on
664
+ screen render incorrectly when saved to file.
665
+
666
+ To get accurate results you may need to manually call
667
+ `~.Figure.savefig` or `~.Figure.draw_without_rendering` to have
668
+ Matplotlib compute the rendered size.
669
+
670
+ Parameters
671
+ ----------
672
+ renderer : `~matplotlib.backend_bases.RendererBase`, optional
673
+ Renderer used to draw the figure (i.e. ``fig.canvas.get_renderer()``).
674
+
675
+ See Also
676
+ --------
677
+ .Artist.get_tightbbox :
678
+ Get the artist bounding box, taking clipping into account.
679
+ """
680
+ return Bbox([[0, 0], [0, 0]])
681
+
682
+ def get_tightbbox(self, renderer=None):
683
+ """
684
+ Get the artist's bounding box in display space, taking clipping into account.
685
+
686
+ Parameters
687
+ ----------
688
+ renderer : `~matplotlib.backend_bases.RendererBase`, optional
689
+ Renderer used to draw the figure (i.e. ``fig.canvas.get_renderer()``).
690
+
691
+ Returns
692
+ -------
693
+ `.Bbox` or None
694
+ The enclosing bounding box (in figure pixel coordinates), or None
695
+ if clipping results in no intersection.
696
+
697
+ See Also
698
+ --------
699
+ .Artist.get_window_extent :
700
+ Get the artist bounding box, ignoring clipping.
701
+ """
702
+ bbox = self.get_window_extent(renderer)
703
+ if self.get_clip_on():
704
+ clip_box = self.get_clip_box()
705
+ if clip_box is not None:
706
+ bbox = Bbox.intersection(bbox, clip_box)
707
+ clip_path = self.get_clip_path()
708
+ if clip_path is not None and bbox is not None:
709
+ clip_path = clip_path.get_fully_transformed_path()
710
+ bbox = Bbox.intersection(bbox, clip_path.get_extents())
711
+ return bbox
712
+
713
+ def add_callback(self, func):
714
+ """
715
+ Add a callback function that will be called whenever one of the
716
+ `.Artist`'s properties changes.
717
+
718
+ Parameters
719
+ ----------
720
+ func : callable
721
+ The callback function. It must have the signature::
722
+
723
+ def func(artist: Artist) -> Any
724
+
725
+ where *artist* is the calling `.Artist`. Return values may exist
726
+ but are ignored.
727
+
728
+ Returns
729
+ -------
730
+ int
731
+ The observer id associated with the callback. This id can be
732
+ used for removing the callback with `.remove_callback` later.
733
+
734
+ See Also
735
+ --------
736
+ remove_callback
737
+ """
738
+ # Wrapping func in a lambda ensures it can be connected multiple times
739
+ # and never gets weakref-gc'ed.
740
+ return self._callbacks.connect("pchanged", lambda: func(self))
741
+
742
+ def remove_callback(self, oid):
743
+ """
744
+ Remove a callback based on its observer id.
745
+
746
+ See Also
747
+ --------
748
+ add_callback
749
+ """
750
+ self._callbacks.disconnect(oid)
751
+
752
+ def pchanged(self):
753
+ """
754
+ Call all of the registered callbacks.
755
+
756
+ This function is triggered internally when a property is changed.
757
+
758
+ See Also
759
+ --------
760
+ add_callback
761
+ remove_callback
762
+ """
763
+ self._callbacks.process("pchanged")
764
+
765
+ def is_transform_set(self):
766
+ """
767
+ Return whether the Artist has an explicitly set transform.
768
+
769
+ This is *True* after `.set_transform` has been called.
770
+ """
771
+ return self._transformSet
772
+
773
+ def set_transform(self, t):
774
+ """
775
+ Set the artist transform.
776
+
777
+ Parameters
778
+ ----------
779
+ t : `~matplotlib.transforms.Transform`
780
+ """
781
+ self._transform = t
782
+ self._transformSet = True
783
+ self.pchanged()
784
+ self.stale = True
785
+
786
+ def get_transform(self):
787
+ """Return the `.Transform` instance used by this artist."""
788
+ if self._transform is None:
789
+ self._transform = IdentityTransform()
790
+ elif (not isinstance(self._transform, Transform)
791
+ and hasattr(self._transform, '_as_mpl_transform')):
792
+ self._transform = self._transform._as_mpl_transform(self.axes)
793
+ return self._transform
794
+
795
+ def get_children(self):
796
+ r"""Return a list of the child `.Artist`\s of this `.Artist`."""
797
+ return []
798
+
799
+ def _different_canvas(self, event):
800
+ """
801
+ Check whether an *event* occurred on a canvas other that this artist's canvas.
802
+
803
+ If this method returns True, the event definitely occurred on a different
804
+ canvas; if it returns False, either it occurred on the same canvas, or we may
805
+ not have enough information to know.
806
+
807
+ Subclasses should start their definition of `contains` as follows::
808
+
809
+ if self._different_canvas(mouseevent):
810
+ return False, {}
811
+ # subclass-specific implementation follows
812
+ """
813
+ return (getattr(event, "canvas", None) is not None
814
+ and (fig := self.get_figure(root=True)) is not None
815
+ and event.canvas is not fig.canvas)
816
+
817
+ def contains(self, mouseevent):
818
+ """
819
+ Test whether the artist contains the mouse event.
820
+
821
+ Parameters
822
+ ----------
823
+ mouseevent : `~matplotlib.backend_bases.MouseEvent`
824
+
825
+ Returns
826
+ -------
827
+ contains : bool
828
+ Whether any values are within the radius.
829
+ details : dict
830
+ An artist-specific dictionary of details of the event context,
831
+ such as which points are contained in the pick radius. See the
832
+ individual Artist subclasses for details.
833
+ """
834
+ _log.warning("%r needs 'contains' method", self.__class__.__name__)
835
+ return False, {}
836
+
837
+ def pickable(self):
838
+ """
839
+ Return whether the artist is pickable.
840
+
841
+ See Also
842
+ --------
843
+ .Artist.set_picker, .Artist.get_picker, .Artist.pick
844
+ """
845
+ return self.get_figure(root=False) is not None and self._picker is not None
846
+
847
+ def pick(self, mouseevent):
848
+ """
849
+ Process a pick event.
850
+
851
+ Each child artist will fire a pick event if *mouseevent* is over
852
+ the artist and the artist has picker set.
853
+
854
+ See Also
855
+ --------
856
+ .Artist.set_picker, .Artist.get_picker, .Artist.pickable
857
+ """
858
+ from .backend_bases import PickEvent # Circular import.
859
+ # Pick self
860
+ if self.pickable():
861
+ picker = self.get_picker()
862
+ if callable(picker):
863
+ inside, prop = picker(self, mouseevent)
864
+ else:
865
+ inside, prop = self.contains(mouseevent)
866
+ if inside:
867
+ PickEvent("pick_event", self.get_figure(root=True).canvas,
868
+ mouseevent, self, **prop)._process()
869
+
870
+ # Pick children
871
+ for a in self.get_children():
872
+ # make sure the event happened in the same Axes
873
+ ax = getattr(a, 'axes', None)
874
+ if (isinstance(a, mpl.figure.SubFigure)
875
+ or mouseevent.inaxes is None or ax is None
876
+ or mouseevent.inaxes == ax):
877
+ # we need to check if mouseevent.inaxes is None
878
+ # because some objects associated with an Axes (e.g., a
879
+ # tick label) can be outside the bounding box of the
880
+ # Axes and inaxes will be None
881
+ # also check that ax is None so that it traverse objects
882
+ # which do not have an axes property but children might
883
+ a.pick(mouseevent)
884
+
885
+ def set_picker(self, picker):
886
+ """
887
+ Define the picking behavior of the artist.
888
+
889
+ Parameters
890
+ ----------
891
+ picker : None or bool or float or callable
892
+ This can be one of the following:
893
+
894
+ - *None*: Picking is disabled for this artist (default).
895
+
896
+ - A boolean: If *True* then picking will be enabled and the
897
+ artist will fire a pick event if the mouse event is over
898
+ the artist.
899
+
900
+ - A float: If picker is a number it is interpreted as an
901
+ epsilon tolerance in points and the artist will fire
902
+ off an event if its data is within epsilon of the mouse
903
+ event. For some artists like lines and patch collections,
904
+ the artist may provide additional data to the pick event
905
+ that is generated, e.g., the indices of the data within
906
+ epsilon of the pick event
907
+
908
+ - A function: If picker is callable, it is a user supplied
909
+ function which determines whether the artist is hit by the
910
+ mouse event::
911
+
912
+ hit, props = picker(artist, mouseevent)
913
+
914
+ to determine the hit test. if the mouse event is over the
915
+ artist, return *hit=True* and props is a dictionary of
916
+ properties you want added to the PickEvent attributes.
917
+ """
918
+ self._picker = picker
919
+
920
+ def get_picker(self):
921
+ """
922
+ Return the picking behavior of the artist.
923
+
924
+ The possible values are described in `.Artist.set_picker`.
925
+
926
+ See Also
927
+ --------
928
+ .Artist.set_picker, .Artist.pickable, .Artist.pick
929
+ """
930
+ return self._picker
931
+
932
+ def get_url(self):
933
+ """Return the url."""
934
+ return self._url
935
+
936
+ def set_url(self, url):
937
+ """
938
+ Set the url for the artist.
939
+
940
+ Parameters
941
+ ----------
942
+ url : str
943
+ """
944
+ self._url = url
945
+ if self.__dict__.get("_h") is not None:
946
+ _DIRTY.add(self) # (matplotlib does not mark the artist stale)
947
+
948
+ def get_gid(self):
949
+ """Return the group id."""
950
+ return self._gid
951
+
952
+ def set_gid(self, gid):
953
+ """
954
+ Set the (group) id for the artist.
955
+
956
+ Parameters
957
+ ----------
958
+ gid : str
959
+ """
960
+ self._gid = gid
961
+ if self.__dict__.get("_h") is not None:
962
+ _DIRTY.add(self) # (matplotlib does not mark the artist stale)
963
+
964
+ def get_snap(self):
965
+ """
966
+ Return the snap setting.
967
+
968
+ See `.set_snap` for details.
969
+ """
970
+ if mpl.rcParams['path.snap']:
971
+ return self._snap
972
+ else:
973
+ return False
974
+
975
+ def set_snap(self, snap):
976
+ """
977
+ Set the snapping behavior.
978
+
979
+ Snapping aligns positions with the pixel grid, which results in
980
+ clearer images. For example, if a black line of 1px width was
981
+ defined at a position in between two pixels, the resulting image
982
+ would contain the interpolated value of that line in the pixel grid,
983
+ which would be a grey value on both adjacent pixel positions. In
984
+ contrast, snapping will move the line to the nearest integer pixel
985
+ value, so that the resulting image will really contain a 1px wide
986
+ black line.
987
+
988
+ Snapping is currently only supported by the Agg and MacOSX backends.
989
+
990
+ Parameters
991
+ ----------
992
+ snap : bool or None
993
+ Possible values:
994
+
995
+ - *True*: Snap vertices to the nearest pixel center.
996
+ - *False*: Do not modify vertex positions.
997
+ - *None*: (auto) If the path contains only rectilinear line
998
+ segments, round to the nearest pixel center.
999
+ """
1000
+ self._snap = snap
1001
+ self.stale = True
1002
+
1003
+ def get_sketch_params(self):
1004
+ """
1005
+ Return the sketch parameters for the artist.
1006
+
1007
+ Returns
1008
+ -------
1009
+ tuple or None
1010
+
1011
+ A 3-tuple with the following elements:
1012
+
1013
+ - *scale*: The amplitude of the wiggle perpendicular to the
1014
+ source line.
1015
+ - *length*: The length of the wiggle along the line.
1016
+ - *randomness*: The scale factor by which the length is
1017
+ shrunken or expanded.
1018
+
1019
+ Returns *None* if no sketch parameters were set.
1020
+ """
1021
+ return self._sketch
1022
+
1023
+ def set_sketch_params(self, scale=None, length=None, randomness=None):
1024
+ """
1025
+ Set the sketch parameters.
1026
+
1027
+ Parameters
1028
+ ----------
1029
+ scale : float, optional
1030
+ The amplitude of the wiggle perpendicular to the source
1031
+ line, in pixels. If scale is `None`, or not provided, no
1032
+ sketch filter will be provided.
1033
+ length : float, optional
1034
+ The length of the wiggle along the line, in pixels
1035
+ (default 128.0)
1036
+ randomness : float, optional
1037
+ The scale factor by which the length is shrunken or
1038
+ expanded (default 16.0)
1039
+
1040
+ The PGF backend uses this argument as an RNG seed and not as
1041
+ described above. Using the same seed yields the same random shape.
1042
+
1043
+ .. ACCEPTS: (scale: float, length: float, randomness: float)
1044
+ """
1045
+ if scale is None:
1046
+ self._sketch = None
1047
+ else:
1048
+ self._sketch = (scale, length or 128.0, randomness or 16.0)
1049
+ self.stale = True
1050
+
1051
+ def set_path_effects(self, path_effects):
1052
+ """
1053
+ Set the path effects.
1054
+
1055
+ Parameters
1056
+ ----------
1057
+ path_effects : list of `.AbstractPathEffect`
1058
+ """
1059
+ self._path_effects = path_effects
1060
+ self.stale = True
1061
+
1062
+ def get_path_effects(self):
1063
+ return self._path_effects
1064
+
1065
+ def get_figure(self, root=False):
1066
+ """
1067
+ Return the `.Figure` or `.SubFigure` instance the artist belongs to.
1068
+
1069
+ Parameters
1070
+ ----------
1071
+ root : bool, default=False
1072
+ If False, return the (Sub)Figure this artist is on. If True,
1073
+ return the root Figure for a nested tree of SubFigures.
1074
+ """
1075
+ if root and self._parent_figure is not None:
1076
+ return self._parent_figure.get_figure(root=True)
1077
+
1078
+ return self._parent_figure
1079
+
1080
+ def set_figure(self, fig):
1081
+ """
1082
+ Set the `.Figure` or `.SubFigure` instance the artist belongs to.
1083
+
1084
+ .. warning::
1085
+
1086
+ This function should typically not be called by users.
1087
+
1088
+ This is a low-level API and only modifies the internal state of the
1089
+ Artist. Only modifying this is not enough and will typically lead
1090
+ to an inconsistent state, because the state of the figure has to
1091
+ be changed as well.
1092
+
1093
+ Users should typically instead call one of the high-level APIs, i.e.
1094
+ `.Figure.add_artist` or one of the Axes methods
1095
+ :ref:`axes-api-adding-artists`.
1096
+
1097
+ Parameters
1098
+ ----------
1099
+ fig : `~matplotlib.figure.Figure` or `~matplotlib.figure.SubFigure`
1100
+ """
1101
+ # if this is a no-op just return
1102
+ if self._parent_figure is fig:
1103
+ return
1104
+ # if we currently have a figure (the case of both `self.figure`
1105
+ # and *fig* being none is taken care of above) we then user is
1106
+ # trying to change the figure an artist is associated with which
1107
+ # is not allowed for the same reason as adding the same instance
1108
+ # to more than one Axes
1109
+ if self._parent_figure is not None:
1110
+ raise RuntimeError("Can not put single artist in "
1111
+ "more than one figure")
1112
+ self._parent_figure = fig
1113
+ if self._parent_figure and self._parent_figure is not self:
1114
+ self.pchanged()
1115
+ self.stale = True
1116
+
1117
+ figure = property(get_figure, set_figure,
1118
+ doc=("The (Sub)Figure that the artist is on. For more "
1119
+ "control, use the `get_figure` method."))
1120
+
1121
+ def set_clip_box(self, clipbox):
1122
+ """
1123
+ Set the artist's clip `.Bbox`.
1124
+
1125
+ Parameters
1126
+ ----------
1127
+ clipbox : `~matplotlib.transforms.BboxBase` or None
1128
+ Will typically be created from a `.TransformedBbox`. For instance,
1129
+ ``TransformedBbox(Bbox([[0, 0], [1, 1]]), ax.transAxes)`` is the default
1130
+ clipping for an artist added to an Axes.
1131
+
1132
+ """
1133
+ _api.check_isinstance((BboxBase, None), clipbox=clipbox)
1134
+ if clipbox != self.clipbox:
1135
+ self.clipbox = clipbox
1136
+ self.pchanged()
1137
+ self.stale = True
1138
+
1139
+ def set_clip_path(self, path, transform=None):
1140
+ """
1141
+ Set the artist's clip path.
1142
+
1143
+ Parameters
1144
+ ----------
1145
+ path : `~matplotlib.patches.Patch` or `.Path` or `.TransformedPath` or None
1146
+ The clip path. If given a `.Path`, *transform* must be provided as
1147
+ well. If *None*, a previously set clip path is removed.
1148
+ transform : `~matplotlib.transforms.Transform`, optional
1149
+ Only used if *path* is a `.Path`, in which case the given `.Path`
1150
+ is converted to a `.TransformedPath` using *transform*.
1151
+
1152
+ Notes
1153
+ -----
1154
+ For efficiency, if *path* is a `.Rectangle` this method will set the
1155
+ clipping box to the corresponding rectangle and set the clipping path
1156
+ to ``None``.
1157
+
1158
+ For technical reasons (support of `~.Artist.set`), a tuple
1159
+ (*path*, *transform*) is also accepted as a single positional
1160
+ parameter.
1161
+
1162
+ .. ACCEPTS: Patch or (Path, Transform) or None
1163
+ """
1164
+ from .patches import Patch, Rectangle
1165
+
1166
+ success = False
1167
+ if transform is None:
1168
+ if isinstance(path, Rectangle):
1169
+ if getattr(path, "_rs_axes_patch", False):
1170
+ self.clipbox = TransformedBbox(
1171
+ Bbox.unit(), _rs_axes_patch_transform(path))
1172
+ self.clipbox._rs_clip_spec = "axes"
1173
+ else:
1174
+ self.clipbox = TransformedBbox(Bbox.unit(),
1175
+ path.get_transform())
1176
+ self._clippath = None
1177
+ success = True
1178
+ elif isinstance(path, Patch):
1179
+ self._clippath = TransformedPatchPath(path)
1180
+ success = True
1181
+ elif isinstance(path, tuple):
1182
+ path, transform = path
1183
+
1184
+ if path is None:
1185
+ self._clippath = None
1186
+ success = True
1187
+ elif isinstance(path, Path):
1188
+ self._clippath = TransformedPath(path, transform)
1189
+ success = True
1190
+ elif isinstance(path, TransformedPatchPath):
1191
+ self._clippath = path
1192
+ success = True
1193
+ elif isinstance(path, TransformedPath):
1194
+ self._clippath = path
1195
+ success = True
1196
+
1197
+ if not success:
1198
+ raise TypeError(
1199
+ "Invalid arguments to set_clip_path, of type "
1200
+ f"{type(path).__name__} and {type(transform).__name__}")
1201
+ # This may result in the callbacks being hit twice, but guarantees they
1202
+ # will be hit at least once.
1203
+ self.pchanged()
1204
+ self.stale = True
1205
+
1206
+ def get_alpha(self):
1207
+ """
1208
+ Return the alpha value used for blending - not supported on all
1209
+ backends.
1210
+ """
1211
+ return self._alpha
1212
+
1213
+ def get_visible(self):
1214
+ """Return the visibility."""
1215
+ return self._visible
1216
+
1217
+ def get_animated(self):
1218
+ """Return whether the artist is animated."""
1219
+ return self._animated
1220
+
1221
+ def get_in_layout(self):
1222
+ """
1223
+ Return boolean flag, ``True`` if artist is included in layout
1224
+ calculations.
1225
+
1226
+ E.g. :ref:`constrainedlayout_guide`,
1227
+ `.Figure.tight_layout()`, and
1228
+ ``fig.savefig(fname, bbox_inches='tight')``.
1229
+ """
1230
+ return self._in_layout
1231
+
1232
+ def _get_in_autoscale(self):
1233
+ """
1234
+ Return whether the artist is included in autoscaling calculations.
1235
+
1236
+ E.g. `.axes.Axes.autoscale_view()`.
1237
+ """
1238
+ return self._in_autoscale
1239
+
1240
+ def _fully_clipped_to_axes(self):
1241
+ """
1242
+ Return a boolean flag, ``True`` if the artist is clipped to the Axes
1243
+ and can thus be skipped in layout calculations. Requires `get_clip_on`
1244
+ is True, one of `clip_box` or `clip_path` is set, ``clip_box.extents``
1245
+ is equivalent to ``ax.bbox.extents`` (if set), and ``clip_path._patch``
1246
+ is equivalent to ``ax.patch`` (if set).
1247
+ """
1248
+ # Note that ``clip_path.get_fully_transformed_path().get_extents()``
1249
+ # cannot be directly compared to ``axes.bbox.extents`` because the
1250
+ # extents may be undefined (i.e. equivalent to ``Bbox.null()``)
1251
+ # before the associated artist is drawn, and this method is meant
1252
+ # to determine whether ``axes.get_tightbbox()`` may bypass drawing
1253
+ clip_box = self.get_clip_box()
1254
+ clip_path = self.get_clip_path()
1255
+ return (self.axes is not None
1256
+ and self.get_clip_on()
1257
+ and (clip_box is not None or clip_path is not None)
1258
+ and (clip_box is None
1259
+ or np.all(clip_box.extents == self.axes.bbox.extents))
1260
+ and (clip_path is None
1261
+ or isinstance(clip_path, TransformedPatchPath)
1262
+ and clip_path._patch is self.axes.patch))
1263
+
1264
+ def get_clip_on(self):
1265
+ """Return whether the artist uses clipping."""
1266
+ return self._clipon
1267
+
1268
+ def get_clip_box(self):
1269
+ """Return the clipbox."""
1270
+ return self.clipbox
1271
+
1272
+ def get_clip_path(self):
1273
+ """Return the clip path."""
1274
+ return self._clippath
1275
+
1276
+ def get_transformed_clip_path_and_affine(self):
1277
+ """
1278
+ Return the clip path with the non-affine part of its
1279
+ transformation applied, and the remaining affine part of its
1280
+ transformation.
1281
+ """
1282
+ if self._clippath is not None:
1283
+ return self._clippath.get_transformed_path_and_affine()
1284
+ return None, None
1285
+
1286
+ def set_clip_on(self, b):
1287
+ """
1288
+ Set whether the artist uses clipping.
1289
+
1290
+ When False, artists will be visible outside the Axes which
1291
+ can lead to unexpected results.
1292
+
1293
+ Parameters
1294
+ ----------
1295
+ b : bool
1296
+ """
1297
+ self._clipon = b
1298
+ # This may result in the callbacks being hit twice, but ensures they
1299
+ # are hit at least once
1300
+ self.pchanged()
1301
+ self.stale = True
1302
+
1303
+ def _set_gc_clip(self, gc):
1304
+ """Set the clip properly for the gc."""
1305
+ if self._clipon:
1306
+ if self.clipbox is not None:
1307
+ gc.set_clip_rectangle(self.clipbox)
1308
+ gc.set_clip_path(self._clippath)
1309
+ else:
1310
+ gc.set_clip_rectangle(None)
1311
+ gc.set_clip_path(None)
1312
+
1313
+ def get_rasterized(self):
1314
+ """Return whether the artist is to be rasterized."""
1315
+ return self._rasterized
1316
+
1317
+ def set_rasterized(self, rasterized):
1318
+ """
1319
+ Force rasterized (bitmap) drawing for vector graphics output.
1320
+
1321
+ Rasterized drawing is not supported by all artists. If you try to
1322
+ enable this on an artist that does not support it, the command has no
1323
+ effect and a warning will be issued.
1324
+
1325
+ This setting is ignored for pixel-based output.
1326
+
1327
+ See also :doc:`/gallery/misc/rasterization_demo`.
1328
+
1329
+ Parameters
1330
+ ----------
1331
+ rasterized : bool
1332
+ """
1333
+ supports_rasterization = getattr(self.draw,
1334
+ "_supports_rasterization", False)
1335
+ if rasterized and not supports_rasterization:
1336
+ _api.warn_external(f"Rasterization of '{self}' will be ignored")
1337
+
1338
+ self._rasterized = rasterized
1339
+
1340
+ def get_agg_filter(self):
1341
+ """Return filter function to be used for agg filter."""
1342
+ return self._agg_filter
1343
+
1344
+ def set_agg_filter(self, filter_func):
1345
+ """
1346
+ Set the agg filter.
1347
+
1348
+ Parameters
1349
+ ----------
1350
+ filter_func : callable
1351
+ A filter function, which takes a (m, n, depth) float array
1352
+ and a dpi value, and returns a (m, n, depth) array and two
1353
+ offsets from the bottom left corner of the image
1354
+
1355
+ .. ACCEPTS: a filter function, which takes a (m, n, 3) float array
1356
+ and a dpi value, and returns a (m, n, 3) array and two offsets
1357
+ from the bottom left corner of the image
1358
+ """
1359
+ self._agg_filter = filter_func
1360
+ self.stale = True
1361
+
1362
+ def draw(self, renderer):
1363
+ """
1364
+ Draw the Artist (and its children) using the given renderer.
1365
+
1366
+ This has no effect if the artist is not visible (`.Artist.get_visible`
1367
+ returns False).
1368
+
1369
+ Parameters
1370
+ ----------
1371
+ renderer : `~matplotlib.backend_bases.RendererBase` subclass.
1372
+
1373
+ Notes
1374
+ -----
1375
+ This method is overridden in the Artist subclasses.
1376
+ """
1377
+ if not self.get_visible():
1378
+ return
1379
+ self.stale = False
1380
+
1381
+ def set_alpha(self, alpha):
1382
+ """
1383
+ Set the alpha value used for blending - not supported on all backends.
1384
+
1385
+ Parameters
1386
+ ----------
1387
+ alpha : float or None
1388
+ *alpha* must be within the 0-1 range, inclusive.
1389
+ """
1390
+ if alpha is not None and not isinstance(alpha, Real):
1391
+ raise TypeError(
1392
+ f'alpha must be numeric or None, not {type(alpha)}')
1393
+ if alpha is not None and not (0 <= alpha <= 1):
1394
+ raise ValueError(f'alpha ({alpha}) is outside 0-1 range')
1395
+ if alpha != self._alpha:
1396
+ self._alpha = alpha
1397
+ self.pchanged()
1398
+ self.stale = True
1399
+
1400
+ def _set_alpha_for_array(self, alpha):
1401
+ """
1402
+ Set the alpha value used for blending - not supported on all backends.
1403
+
1404
+ Parameters
1405
+ ----------
1406
+ alpha : array-like or float or None
1407
+ All values must be within the 0-1 range, inclusive.
1408
+ Masked values and nans are not supported.
1409
+ """
1410
+ if isinstance(alpha, str):
1411
+ raise TypeError("alpha must be numeric or None, not a string")
1412
+ if not np.iterable(alpha):
1413
+ Artist.set_alpha(self, alpha)
1414
+ return
1415
+ alpha = np.asarray(alpha)
1416
+ if not (0 <= alpha.min() and alpha.max() <= 1):
1417
+ raise ValueError('alpha must be between 0 and 1, inclusive, '
1418
+ f'but min is {alpha.min()}, max is {alpha.max()}')
1419
+ self._alpha = alpha
1420
+ self.pchanged()
1421
+ self.stale = True
1422
+
1423
+ def set_visible(self, b):
1424
+ """
1425
+ Set the artist's visibility.
1426
+
1427
+ Parameters
1428
+ ----------
1429
+ b : bool
1430
+ """
1431
+ if b != self._visible:
1432
+ self._visible = b
1433
+ self.pchanged()
1434
+ self.stale = True
1435
+
1436
+ def set_animated(self, b):
1437
+ """
1438
+ Set whether the artist is intended to be used in an animation.
1439
+
1440
+ If True, the artist is excluded from regular drawing of the figure.
1441
+ You have to call `.Figure.draw_artist` / `.Axes.draw_artist`
1442
+ explicitly on the artist. This approach is used to speed up animations
1443
+ using blitting.
1444
+
1445
+ See also `matplotlib.animation` and
1446
+ :ref:`blitting`.
1447
+
1448
+ Parameters
1449
+ ----------
1450
+ b : bool
1451
+ """
1452
+ if self._animated != b:
1453
+ self._animated = b
1454
+ self.pchanged()
1455
+ if self.__dict__.get("_h") is not None:
1456
+ _DIRTY.add(self)
1457
+
1458
+ def set_in_layout(self, in_layout):
1459
+ """
1460
+ Set if artist is to be included in layout calculations,
1461
+ E.g. :ref:`constrainedlayout_guide`,
1462
+ `.Figure.tight_layout()`, and
1463
+ ``fig.savefig(fname, bbox_inches='tight')``.
1464
+
1465
+ Parameters
1466
+ ----------
1467
+ in_layout : bool
1468
+ """
1469
+ self._in_layout = in_layout
1470
+
1471
+ def _set_in_autoscale(self, b):
1472
+ """
1473
+ Set if artist is to be included in autoscaling calculations,
1474
+ E.g. `.axes.Axes.autoscale_view()`.
1475
+
1476
+ Parameters
1477
+ ----------
1478
+ b : bool
1479
+ """
1480
+ self._in_autoscale = b
1481
+
1482
+ def get_label(self):
1483
+ """Return the label used for this artist in the legend."""
1484
+ return self._label
1485
+
1486
+ def set_label(self, s):
1487
+ """
1488
+ Set a label that will be displayed in the legend.
1489
+
1490
+ Parameters
1491
+ ----------
1492
+ s : object
1493
+ *s* will be converted to a string by calling `str`.
1494
+ """
1495
+ label = str(s) if s is not None else None
1496
+ if label != self._label:
1497
+ self._label = label
1498
+ self.pchanged()
1499
+ self.stale = True
1500
+
1501
+ def get_zorder(self):
1502
+ """Return the artist's zorder."""
1503
+ return self.zorder
1504
+
1505
+ def set_zorder(self, level):
1506
+ """
1507
+ Set the zorder for the artist. Artists with lower zorder
1508
+ values are drawn first.
1509
+
1510
+ Parameters
1511
+ ----------
1512
+ level : float
1513
+ """
1514
+ if level is None:
1515
+ level = self.__class__.zorder
1516
+ if level != self.zorder:
1517
+ self.zorder = level
1518
+ self.pchanged()
1519
+ self.stale = True
1520
+
1521
+ @property
1522
+ def sticky_edges(self):
1523
+ """
1524
+ ``x`` and ``y`` sticky edge lists for autoscaling.
1525
+
1526
+ When performing autoscaling, if a data limit coincides with a value in
1527
+ the corresponding sticky_edges list, then no margin will be added--the
1528
+ view limit "sticks" to the edge. A typical use case is histograms,
1529
+ where one usually expects no margin on the bottom edge (0) of the
1530
+ histogram.
1531
+
1532
+ Moreover, margin expansion "bumps" against sticky edges and cannot
1533
+ cross them. For example, if the upper data limit is 1.0, the upper
1534
+ view limit computed by simple margin application is 1.2, but there is a
1535
+ sticky edge at 1.1, then the actual upper view limit will be 1.1.
1536
+
1537
+ This attribute cannot be assigned to; however, the ``x`` and ``y``
1538
+ lists can be modified in place as needed.
1539
+
1540
+ Examples
1541
+ --------
1542
+ >>> artist.sticky_edges.x[:] = (xmin, xmax)
1543
+ >>> artist.sticky_edges.y[:] = (ymin, ymax)
1544
+
1545
+ """
1546
+ if self._sticky_edges is None:
1547
+ self._sticky_edges = _XYPair([], [])
1548
+ return self._sticky_edges
1549
+
1550
+ def update_from(self, other):
1551
+ """Copy properties from *other* to *self*."""
1552
+ self._transform = other._transform
1553
+ self._transformSet = other._transformSet
1554
+ self._visible = other._visible
1555
+ self._alpha = other._alpha
1556
+ self.clipbox = other.clipbox
1557
+ self._clipon = other._clipon
1558
+ self._clippath = other._clippath
1559
+ self._label = other._label
1560
+ self._sketch = other._sketch
1561
+ self._path_effects = other._path_effects
1562
+ if other._sticky_edges is not None:
1563
+ self.sticky_edges.x[:] = other._sticky_edges.x.copy()
1564
+ self.sticky_edges.y[:] = other._sticky_edges.y.copy()
1565
+ else:
1566
+ self._sticky_edges = None
1567
+ self.pchanged()
1568
+ self.stale = True
1569
+
1570
+ def properties(self):
1571
+ """Return a dictionary of all the properties of the artist."""
1572
+ return ArtistInspector(self).properties()
1573
+
1574
+ def _update_props(self, props, errfmt):
1575
+ """
1576
+ Helper for `.Artist.set` and `.Artist.update`.
1577
+
1578
+ *errfmt* is used to generate error messages for invalid property
1579
+ names; it gets formatted with ``type(self)`` for "{cls}" and the
1580
+ property name for "{prop_name}".
1581
+ """
1582
+ ret = []
1583
+ for k, v in props.items():
1584
+ # Allow attributes we want to be able to update through
1585
+ # art.update, art.set, setp.
1586
+ if k == "axes":
1587
+ ret.append(setattr(self, k, v))
1588
+ else:
1589
+ func = getattr(self, f"set_{k}", None)
1590
+ if not callable(func):
1591
+ raise AttributeError(
1592
+ errfmt.format(cls=type(self), prop_name=k),
1593
+ name=k)
1594
+ ret.append(func(v))
1595
+ if ret:
1596
+ self.pchanged()
1597
+ self.stale = True
1598
+ return ret
1599
+
1600
+ def update(self, props):
1601
+ """
1602
+ [*Discouraged*] Update this artist's properties from the dictionary *props*.
1603
+
1604
+ .. admonition:: Discouraged
1605
+
1606
+ This method exists for historic reasons. Please use `.Artist.set` instead.
1607
+ ``artist.update(props)`` is nowadays almost identical to
1608
+ ``artist.set(**props)`` with the only difference that ``set`` will
1609
+ additionally check that a property is not specified multiple times
1610
+ through aliases.
1611
+
1612
+ Parameters
1613
+ ----------
1614
+ props : dict
1615
+ Dictionary of properties (keys) and their new values.
1616
+
1617
+ Returns
1618
+ -------
1619
+ list
1620
+ A list of return values from the configured setters.
1621
+
1622
+ """
1623
+ return self._update_props(
1624
+ props, "{cls.__name__!r} object has no property {prop_name!r}")
1625
+
1626
+ def _internal_update(self, kwargs):
1627
+ """
1628
+ Update artist properties without prenormalizing them, but generating
1629
+ errors as if calling `set`.
1630
+
1631
+ The lack of prenormalization is to maintain backcompatibility.
1632
+ """
1633
+ return self._update_props(
1634
+ kwargs, "{cls.__name__}.set() got an unexpected keyword argument "
1635
+ "{prop_name!r}")
1636
+
1637
+ def set(self, **kwargs):
1638
+ # docstring and signature are auto-generated via
1639
+ # Artist._update_set_signature_and_docstring() at the end of the
1640
+ # module.
1641
+ return self._internal_update(cbook.normalize_kwargs(kwargs, self))
1642
+
1643
+ @contextlib.contextmanager
1644
+ def _cm_set(self, **kwargs):
1645
+ """
1646
+ A context manager to temporarily set artist properties.
1647
+
1648
+ In contrast to `.Artist.set` and for performance, this skips the
1649
+ `normalize_kwargs` check.
1650
+ """
1651
+ orig_vals = {k: getattr(self, f"get_{k}")() for k in kwargs}
1652
+ try:
1653
+ self._internal_update({k: kwargs[k] for k in orig_vals})
1654
+ yield
1655
+ finally:
1656
+ self._internal_update(orig_vals)
1657
+
1658
+ def findobj(self, match=None, include_self=True):
1659
+ """
1660
+ Find artist objects.
1661
+
1662
+ Recursively find all `.Artist` instances contained in the artist.
1663
+
1664
+ Parameters
1665
+ ----------
1666
+ match
1667
+ A filter criterion for the matches. This can be
1668
+
1669
+ - *None*: Return all objects contained in artist.
1670
+ - A function with signature ``def match(artist: Artist) -> bool``.
1671
+ The result will only contain artists for which the function
1672
+ returns *True*.
1673
+ - A class instance: e.g., `.Line2D`. The result will only contain
1674
+ artists of this class or its subclasses (``isinstance`` check).
1675
+
1676
+ include_self : bool
1677
+ Include *self* in the list to be checked for a match.
1678
+
1679
+ Returns
1680
+ -------
1681
+ list of `.Artist`
1682
+
1683
+ """
1684
+ if match is None: # always return True
1685
+ def matchfunc(x):
1686
+ return True
1687
+ elif isinstance(match, type) and issubclass(match, Artist):
1688
+ def matchfunc(x):
1689
+ return isinstance(x, match)
1690
+ elif callable(match):
1691
+ matchfunc = match
1692
+ else:
1693
+ raise ValueError('match must be None, a matplotlib.artist.Artist '
1694
+ 'subclass, or a callable')
1695
+
1696
+ artists = reduce(operator.iadd,
1697
+ [c.findobj(matchfunc) for c in self.get_children()], [])
1698
+ if include_self and matchfunc(self):
1699
+ artists.append(self)
1700
+ return artists
1701
+
1702
+ def get_cursor_data(self, event):
1703
+ """
1704
+ Return the cursor data for a given event.
1705
+
1706
+ .. note::
1707
+ This method is intended to be overridden by artist subclasses.
1708
+ As an end-user of Matplotlib you will most likely not call this
1709
+ method yourself.
1710
+
1711
+ Cursor data can be used by Artists to provide additional context
1712
+ information for a given event. The default implementation just returns
1713
+ *None*.
1714
+
1715
+ Subclasses can override the method and return arbitrary data. However,
1716
+ when doing so, they must ensure that `.format_cursor_data` can convert
1717
+ the data to a string representation.
1718
+
1719
+ The only current use case is displaying the z-value of an `.AxesImage`
1720
+ in the status bar of a plot window, while moving the mouse.
1721
+
1722
+ Parameters
1723
+ ----------
1724
+ event : `~matplotlib.backend_bases.MouseEvent`
1725
+
1726
+ See Also
1727
+ --------
1728
+ format_cursor_data
1729
+
1730
+ """
1731
+ return None
1732
+
1733
+ def format_cursor_data(self, data):
1734
+ """
1735
+ Return a string representation of *data*.
1736
+
1737
+ .. note::
1738
+ This method is intended to be overridden by artist subclasses.
1739
+ As an end-user of Matplotlib you will most likely not call this
1740
+ method yourself.
1741
+
1742
+ The default implementation converts ints and floats and arrays of ints
1743
+ and floats into a comma-separated string enclosed in square brackets,
1744
+ unless the artist has an associated colorbar, in which case scalar
1745
+ values are formatted using the colorbar's formatter.
1746
+
1747
+ See Also
1748
+ --------
1749
+ get_cursor_data
1750
+ """
1751
+ if np.ndim(data) == 0 and hasattr(self, "_format_cursor_data_override"):
1752
+ # workaround for ScalarMappable to be able to define its own
1753
+ # format_cursor_data(). See ScalarMappable._format_cursor_data_override
1754
+ # for details.
1755
+ return self._format_cursor_data_override(data)
1756
+ else:
1757
+ try:
1758
+ data[0]
1759
+ except (TypeError, IndexError):
1760
+ data = [data]
1761
+ data_str = ', '.join(f'{item:0.3g}' for item in data
1762
+ if isinstance(item, Number))
1763
+ return "[" + data_str + "]"
1764
+
1765
+ def get_mouseover(self):
1766
+ """
1767
+ Return whether this artist is queried for custom context information
1768
+ when the mouse cursor moves over it.
1769
+ """
1770
+ return self._mouseover
1771
+
1772
+ def set_mouseover(self, mouseover):
1773
+ """
1774
+ Set whether this artist is queried for custom context information when
1775
+ the mouse cursor moves over it.
1776
+
1777
+ Parameters
1778
+ ----------
1779
+ mouseover : bool
1780
+
1781
+ See Also
1782
+ --------
1783
+ get_cursor_data
1784
+ .ToolCursorPosition
1785
+ .NavigationToolbar2
1786
+ """
1787
+ self._mouseover = bool(mouseover)
1788
+ ax = self.axes
1789
+ if ax:
1790
+ if self._mouseover:
1791
+ ax._mouseover_set.add(self)
1792
+ else:
1793
+ ax._mouseover_set.discard(self)
1794
+
1795
+ mouseover = property(get_mouseover, set_mouseover) # backcompat.
1796
+
1797
+
1798
+ def _get_tightbbox_for_layout_only(obj, *args, **kwargs):
1799
+ """
1800
+ Matplotlib's `.Axes.get_tightbbox` and `.Axis.get_tightbbox` support a
1801
+ *for_layout_only* kwarg; this helper tries to use the kwarg but skips it
1802
+ when encountering third-party subclasses that do not support it.
1803
+ """
1804
+ try:
1805
+ return obj.get_tightbbox(*args, **{**kwargs, "for_layout_only": True})
1806
+ except TypeError:
1807
+ return obj.get_tightbbox(*args, **kwargs)
1808
+
1809
+
1810
+ class ArtistInspector:
1811
+ """
1812
+ A helper class to inspect an `~matplotlib.artist.Artist` and return
1813
+ information about its settable properties and their current values.
1814
+ """
1815
+
1816
+ def __init__(self, o):
1817
+ r"""
1818
+ Initialize the artist inspector with an `Artist` or an iterable of
1819
+ `Artist`\s. If an iterable is used, we assume it is a homogeneous
1820
+ sequence (all `Artist`\s are of the same type) and it is your
1821
+ responsibility to make sure this is so.
1822
+ """
1823
+ if not isinstance(o, Artist):
1824
+ if np.iterable(o):
1825
+ o = list(o)
1826
+ if len(o):
1827
+ o = o[0]
1828
+
1829
+ self.oorig = o
1830
+ if not isinstance(o, type):
1831
+ o = type(o)
1832
+ self.o = o
1833
+
1834
+ self.aliasd = self.get_aliases()
1835
+
1836
+ def get_aliases(self):
1837
+ """
1838
+ Get a dict mapping property fullnames to sets of aliases for each alias
1839
+ in the :class:`~matplotlib.artist.ArtistInspector`.
1840
+
1841
+ e.g., for lines::
1842
+
1843
+ {'markerfacecolor': {'mfc'},
1844
+ 'linewidth' : {'lw'},
1845
+ }
1846
+ """
1847
+ names = [name for name in dir(self.o)
1848
+ if name.startswith(('set_', 'get_'))
1849
+ and callable(getattr(self.o, name))]
1850
+ aliases = {}
1851
+ for name in names:
1852
+ func = getattr(self.o, name)
1853
+ if not self.is_alias(func):
1854
+ continue
1855
+ propname = re.search(f"`({name[:4]}.*)`", # get_.*/set_.*
1856
+ inspect.getdoc(func)).group(1)
1857
+ aliases.setdefault(propname[4:], set()).add(name[4:])
1858
+ return aliases
1859
+
1860
+ _get_valid_values_regex = re.compile(
1861
+ r"\n\s*(?:\.\.\s+)?ACCEPTS:\s*((?:.|\n)*?)(?:$|(?:\n\n))"
1862
+ )
1863
+
1864
+ def get_valid_values(self, attr):
1865
+ """
1866
+ Get the legal arguments for the setter associated with *attr*.
1867
+
1868
+ This is done by querying the docstring of the setter for a line that
1869
+ begins with "ACCEPTS:" or ".. ACCEPTS:", and then by looking for a
1870
+ numpydoc-style documentation for the setter's first argument.
1871
+ """
1872
+
1873
+ name = 'set_%s' % attr
1874
+ if not hasattr(self.o, name):
1875
+ raise AttributeError(f'{self.o} has no function {name}')
1876
+ func = getattr(self.o, name)
1877
+
1878
+ if hasattr(func, '_kwarg_doc'):
1879
+ return func._kwarg_doc
1880
+
1881
+ docstring = inspect.getdoc(func)
1882
+ if docstring is None:
1883
+ return 'unknown'
1884
+
1885
+ if docstring.startswith('Alias for '):
1886
+ return None
1887
+
1888
+ match = self._get_valid_values_regex.search(docstring)
1889
+ if match is not None:
1890
+ return re.sub("\n *", " ", match.group(1))
1891
+
1892
+ # Much faster than list(inspect.signature(func).parameters)[1],
1893
+ # although barely relevant wrt. matplotlib's total import time.
1894
+ param_name = func.__code__.co_varnames[1]
1895
+ # We could set the presence * based on whether the parameter is a
1896
+ # varargs (it can't be a varkwargs) but it's not really worth it.
1897
+ match = re.search(fr"(?m)^ *\*?{param_name} : (.+)", docstring)
1898
+ if match:
1899
+ return match.group(1)
1900
+
1901
+ return 'unknown'
1902
+
1903
+ def _replace_path(self, source_class):
1904
+ """
1905
+ Changes the full path to the public API path that is used
1906
+ in sphinx. This is needed for links to work.
1907
+ """
1908
+ replace_dict = {'_base._AxesBase': 'Axes',
1909
+ '_axes.Axes': 'Axes'}
1910
+ for key, value in replace_dict.items():
1911
+ source_class = source_class.replace(key, value)
1912
+ return source_class
1913
+
1914
+ def get_setters(self):
1915
+ """
1916
+ Get the attribute strings with setters for object.
1917
+
1918
+ For example, for a line, return ``['markerfacecolor', 'linewidth',
1919
+ ....]``.
1920
+ """
1921
+ setters = []
1922
+ for name in dir(self.o):
1923
+ if not name.startswith('set_'):
1924
+ continue
1925
+ func = getattr(self.o, name)
1926
+ if (not callable(func)
1927
+ or self.number_of_parameters(func) < 2
1928
+ or self.is_alias(func)):
1929
+ continue
1930
+ setters.append(name[4:])
1931
+ return setters
1932
+
1933
+ @staticmethod
1934
+ @cache
1935
+ def number_of_parameters(func):
1936
+ """Return number of parameters of the callable *func*."""
1937
+ return len(inspect.signature(func).parameters)
1938
+
1939
+ @staticmethod
1940
+ @cache
1941
+ def is_alias(method):
1942
+ """
1943
+ Return whether the object *method* is an alias for another method.
1944
+ """
1945
+
1946
+ ds = inspect.getdoc(method)
1947
+ if ds is None:
1948
+ return False
1949
+
1950
+ return ds.startswith('Alias for ')
1951
+
1952
+ def aliased_name(self, s):
1953
+ """
1954
+ Return 'PROPNAME or alias' if *s* has an alias, else return 'PROPNAME'.
1955
+
1956
+ For example, for the line markerfacecolor property, which has an
1957
+ alias, return 'markerfacecolor or mfc' and for the transform
1958
+ property, which does not, return 'transform'.
1959
+ """
1960
+ aliases = ''.join(' or %s' % x for x in sorted(self.aliasd.get(s, [])))
1961
+ return s + aliases
1962
+
1963
+ _NOT_LINKABLE = {
1964
+ # A set of property setter methods that are not available in our
1965
+ # current docs. This is a workaround used to prevent trying to link
1966
+ # these setters which would lead to "target reference not found"
1967
+ # warnings during doc build.
1968
+ 'matplotlib.image._ImageBase.set_alpha',
1969
+ 'matplotlib.image._ImageBase.set_array',
1970
+ 'matplotlib.image._ImageBase.set_data',
1971
+ 'matplotlib.image._ImageBase.set_filternorm',
1972
+ 'matplotlib.image._ImageBase.set_filterrad',
1973
+ 'matplotlib.image._ImageBase.set_interpolation',
1974
+ 'matplotlib.image._ImageBase.set_interpolation_stage',
1975
+ 'matplotlib.image._ImageBase.set_resample',
1976
+ 'matplotlib.text._AnnotationBase.set_annotation_clip',
1977
+ }
1978
+
1979
+ def aliased_name_rest(self, s, target):
1980
+ """
1981
+ Return 'PROPNAME or alias' if *s* has an alias, else return 'PROPNAME',
1982
+ formatted for reST.
1983
+
1984
+ For example, for the line markerfacecolor property, which has an
1985
+ alias, return 'markerfacecolor or mfc' and for the transform
1986
+ property, which does not, return 'transform'.
1987
+ """
1988
+ # workaround to prevent "reference target not found"
1989
+ if target in self._NOT_LINKABLE:
1990
+ return f'``{s}``'
1991
+
1992
+ aliases = ''.join(
1993
+ f' or :meth:`{a} <{target}>`' for a in sorted(self.aliasd.get(s, [])))
1994
+ return f':meth:`{s} <{target}>`{aliases}'
1995
+
1996
+ def pprint_setters(self, prop=None, leadingspace=2):
1997
+ """
1998
+ If *prop* is *None*, return a list of strings of all settable
1999
+ properties and their valid values.
2000
+
2001
+ If *prop* is not *None*, it is a valid property name and that
2002
+ property will be returned as a string of property : valid
2003
+ values.
2004
+ """
2005
+ if leadingspace:
2006
+ pad = ' ' * leadingspace
2007
+ else:
2008
+ pad = ''
2009
+ if prop is not None:
2010
+ accepts = self.get_valid_values(prop)
2011
+ return f'{pad}{prop}: {accepts}'
2012
+
2013
+ lines = []
2014
+ for prop in sorted(self.get_setters()):
2015
+ accepts = self.get_valid_values(prop)
2016
+ name = self.aliased_name(prop)
2017
+ lines.append(f'{pad}{name}: {accepts}')
2018
+ return lines
2019
+
2020
+ def pprint_setters_rest(self, prop=None, leadingspace=4):
2021
+ """
2022
+ If *prop* is *None*, return a list of reST-formatted strings of all
2023
+ settable properties and their valid values.
2024
+
2025
+ If *prop* is not *None*, it is a valid property name and that
2026
+ property will be returned as a string of "property : valid"
2027
+ values.
2028
+ """
2029
+ if leadingspace:
2030
+ pad = ' ' * leadingspace
2031
+ else:
2032
+ pad = ''
2033
+ if prop is not None:
2034
+ accepts = self.get_valid_values(prop)
2035
+ return f'{pad}{prop}: {accepts}'
2036
+
2037
+ prop_and_qualnames = []
2038
+ for prop in sorted(self.get_setters()):
2039
+ # Find the parent method which actually provides the docstring.
2040
+ for cls in self.o.__mro__:
2041
+ method = getattr(cls, f"set_{prop}", None)
2042
+ if method and method.__doc__ is not None:
2043
+ break
2044
+ else: # No docstring available.
2045
+ method = getattr(self.o, f"set_{prop}")
2046
+ prop_and_qualnames.append(
2047
+ (prop, f"{method.__module__}.{method.__qualname__}"))
2048
+
2049
+ names = [self.aliased_name_rest(prop, target)
2050
+ .replace('_base._AxesBase', 'Axes')
2051
+ .replace('_axes.Axes', 'Axes')
2052
+ for prop, target in prop_and_qualnames]
2053
+ accepts = [self.get_valid_values(prop)
2054
+ for prop, _ in prop_and_qualnames]
2055
+
2056
+ col0_len = max(len(n) for n in names)
2057
+ col1_len = max(len(a) for a in accepts)
2058
+ table_formatstr = pad + ' ' + '=' * col0_len + ' ' + '=' * col1_len
2059
+
2060
+ return [
2061
+ '',
2062
+ pad + '.. table::',
2063
+ pad + ' :class: property-table',
2064
+ '',
2065
+ table_formatstr,
2066
+ pad + ' ' + 'Property'.ljust(col0_len)
2067
+ + ' ' + 'Description'.ljust(col1_len),
2068
+ table_formatstr,
2069
+ *[pad + ' ' + n.ljust(col0_len) + ' ' + a.ljust(col1_len)
2070
+ for n, a in zip(names, accepts)],
2071
+ table_formatstr,
2072
+ '',
2073
+ ]
2074
+
2075
+ def properties(self):
2076
+ """Return a dictionary mapping property name -> value."""
2077
+ o = self.oorig
2078
+ getters = [name for name in dir(o)
2079
+ if name.startswith('get_') and callable(getattr(o, name))]
2080
+ getters.sort()
2081
+ d = {}
2082
+ for name in getters:
2083
+ func = getattr(o, name)
2084
+ if self.is_alias(func):
2085
+ continue
2086
+ try:
2087
+ with warnings.catch_warnings():
2088
+ warnings.simplefilter('ignore')
2089
+ val = func()
2090
+ except Exception:
2091
+ continue
2092
+ else:
2093
+ d[name[4:]] = val
2094
+ return d
2095
+
2096
+ def pprint_getters(self):
2097
+ """Return the getters and actual values as list of strings."""
2098
+ lines = []
2099
+ for name, val in sorted(self.properties().items()):
2100
+ if getattr(val, 'shape', ()) != () and len(val) > 6:
2101
+ s = str(val[:6]) + '...'
2102
+ else:
2103
+ s = str(val)
2104
+ s = s.replace('\n', ' ')
2105
+ if len(s) > 50:
2106
+ s = s[:50] + '...'
2107
+ name = self.aliased_name(name)
2108
+ lines.append(f' {name} = {s}')
2109
+ return lines
2110
+
2111
+
2112
+ def getp(obj, property=None):
2113
+ """
2114
+ Return the value of an `.Artist`'s *property*, or print all of them.
2115
+
2116
+ Parameters
2117
+ ----------
2118
+ obj : `~matplotlib.artist.Artist`
2119
+ The queried artist; e.g., a `.Line2D`, a `.Text`, or an `~.axes.Axes`.
2120
+
2121
+ property : str or None, default: None
2122
+ If *property* is 'somename', this function returns
2123
+ ``obj.get_somename()``.
2124
+
2125
+ If it's None (or unset), it *prints* all gettable properties from
2126
+ *obj*. Many properties have aliases for shorter typing, e.g. 'lw' is
2127
+ an alias for 'linewidth'. In the output, aliases and full property
2128
+ names will be listed as:
2129
+
2130
+ property or alias = value
2131
+
2132
+ e.g.:
2133
+
2134
+ linewidth or lw = 2
2135
+
2136
+ See Also
2137
+ --------
2138
+ setp
2139
+ """
2140
+ if property is None:
2141
+ insp = ArtistInspector(obj)
2142
+ ret = insp.pprint_getters()
2143
+ print('\n'.join(ret))
2144
+ return
2145
+ return getattr(obj, 'get_' + property)()
2146
+
2147
+ # alias
2148
+ get = getp
2149
+
2150
+
2151
+ def setp(obj, *args, file=None, **kwargs):
2152
+ """
2153
+ Set one or more properties on an `.Artist`, or list allowed values.
2154
+
2155
+ Parameters
2156
+ ----------
2157
+ obj : `~matplotlib.artist.Artist` or list of `.Artist`
2158
+ The artist(s) whose properties are being set or queried. When setting
2159
+ properties, all artists are affected; when querying the allowed values,
2160
+ only the first instance in the sequence is queried.
2161
+
2162
+ For example, two lines can be made thicker and red with a single call:
2163
+
2164
+ >>> x = arange(0, 1, 0.01)
2165
+ >>> lines = plot(x, sin(2*pi*x), x, sin(4*pi*x))
2166
+ >>> setp(lines, linewidth=2, color='r')
2167
+
2168
+ file : file-like, default: `sys.stdout`
2169
+ Where `setp` writes its output when asked to list allowed values.
2170
+
2171
+ >>> with open('output.log') as file:
2172
+ ... setp(line, file=file)
2173
+
2174
+ The default, ``None``, means `sys.stdout`.
2175
+
2176
+ *args, **kwargs
2177
+ The properties to set. The following combinations are supported:
2178
+
2179
+ - Set the linestyle of a line to be dashed:
2180
+
2181
+ >>> line, = plot([1, 2, 3])
2182
+ >>> setp(line, linestyle='--')
2183
+
2184
+ - Set multiple properties at once:
2185
+
2186
+ >>> setp(line, linewidth=2, color='r')
2187
+
2188
+ - List allowed values for a line's linestyle:
2189
+
2190
+ >>> setp(line, 'linestyle')
2191
+ linestyle: {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
2192
+
2193
+ - List all properties that can be set, and their allowed values:
2194
+
2195
+ >>> setp(line)
2196
+ agg_filter: a filter function, ...
2197
+ [long output listing omitted]
2198
+
2199
+ `setp` also supports MATLAB style string/value pairs. For example, the
2200
+ following are equivalent:
2201
+
2202
+ >>> setp(lines, 'linewidth', 2, 'color', 'r') # MATLAB style
2203
+ >>> setp(lines, linewidth=2, color='r') # Python style
2204
+
2205
+ See Also
2206
+ --------
2207
+ getp
2208
+ """
2209
+
2210
+ if isinstance(obj, Artist):
2211
+ objs = [obj]
2212
+ else:
2213
+ objs = list(cbook.flatten(obj))
2214
+
2215
+ if not objs:
2216
+ return
2217
+
2218
+ insp = ArtistInspector(objs[0])
2219
+
2220
+ if not kwargs and len(args) < 2:
2221
+ if args:
2222
+ print(insp.pprint_setters(prop=args[0]), file=file)
2223
+ else:
2224
+ print('\n'.join(insp.pprint_setters()), file=file)
2225
+ return
2226
+
2227
+ if len(args) % 2:
2228
+ raise ValueError('The set args must be string, value pairs')
2229
+
2230
+ funcvals = dict(zip(args[::2], args[1::2]))
2231
+ ret = [o.update(funcvals) for o in objs] + [o.set(**kwargs) for o in objs]
2232
+ return list(cbook.flatten(ret))
2233
+
2234
+
2235
+ def _doc_cache_get(cls, kind):
2236
+ """The precomputed ``kwdoc`` text or setter names of a matplotlib_rs
2237
+ Artist class (see tools/gen_doc_cache.py), or None."""
2238
+ if not isinstance(cls, type) or not cls.__module__.startswith("matplotlib_rs"):
2239
+ return None
2240
+ if os.environ.get("MPLRS_NO_DOC_CACHE"):
2241
+ return None
2242
+ try:
2243
+ from . import _doc_cache
2244
+ except ImportError:
2245
+ return None
2246
+ entry = _doc_cache.DOCS.get((cls.__module__, cls.__qualname__))
2247
+ if entry is None or "<" in cls.__qualname__:
2248
+ return None
2249
+ mod = sys.modules.get(cls.__module__)
2250
+ if mod is not None and getattr(mod, cls.__qualname__.split(".")[0], cls) is not cls \
2251
+ and "." not in cls.__qualname__:
2252
+ return None # a class made at runtime under a cached name
2253
+ return entry[0] if kind == "kwdoc" else entry[1]
2254
+
2255
+
2256
+ def kwdoc(artist):
2257
+ r"""
2258
+ Inspect an `~matplotlib.artist.Artist` class (using `.ArtistInspector`) and
2259
+ return information about its settable properties and their current values.
2260
+
2261
+ Parameters
2262
+ ----------
2263
+ artist : `~matplotlib.artist.Artist` or an iterable of `Artist`\s
2264
+
2265
+ Returns
2266
+ -------
2267
+ str
2268
+ The settable properties of *artist*, as plain text if
2269
+ :rc:`docstring.hardcopy` is False and as an rst table (intended for
2270
+ use in Sphinx) if it is True.
2271
+ """
2272
+ if not mpl.rcParams['docstring.hardcopy']:
2273
+ cached = _doc_cache_get(artist, "kwdoc")
2274
+ if cached is not None:
2275
+ return cached
2276
+ ai = ArtistInspector(artist)
2277
+ return ('\n'.join(ai.pprint_setters_rest(leadingspace=4))
2278
+ if mpl.rcParams['docstring.hardcopy'] else
2279
+ 'Properties:\n' + '\n'.join(ai.pprint_setters(leadingspace=4)))
2280
+
2281
+ # We defer this to the end of them module, because it needs ArtistInspector
2282
+ # to be defined.
2283
+ Artist._update_set_signature_and_docstring()
2284
+
2285
+
2286
+ def _rs_owner_axes_fig(owner):
2287
+ """(axes, figure) of the owner of a Rust-owned artist view."""
2288
+ if owner is None:
2289
+ return None, None
2290
+ if hasattr(owner, "transAxes"):
2291
+ return owner, owner.get_figure(root=False)
2292
+ return None, owner
2293
+
2294
+
2295
+ class _RsOwnedTransformMixin:
2296
+ """`get_transform` reads the transform the Rust model uses."""
2297
+
2298
+ def get_transform(self):
2299
+ if self._transformSet or self.__dict__.get("_h") is None:
2300
+ return Artist.get_transform(self)
2301
+ axes, fig = _rs_owner_axes_fig(self._rs_owner)
2302
+ return _rs_transform_from_spec(self._h.get("transform"), axes, fig)