matplotlib-rs 0.0.8__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.cp313-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,1726 @@
1
+ # Vendored from matplotlib 3.11 (see licenses/LICENSE_MATPLOTLIB), adapted for matplotlib_rs.
2
+ r"""
3
+ Container classes for `.Artist`\s.
4
+
5
+ `OffsetBox`
6
+ The base of all container artists defined in this module.
7
+
8
+ `AnchoredOffsetbox`, `AnchoredText`
9
+ Anchor and align an arbitrary `.Artist` or a text relative to the parent
10
+ axes or a specific anchor point.
11
+
12
+ `DrawingArea`
13
+ A container with fixed width and height. Children have a fixed position
14
+ inside the container and may be clipped.
15
+
16
+ `HPacker`, `VPacker`
17
+ Containers for layouting their children vertically or horizontally.
18
+
19
+ `PaddedBox`
20
+ A container to add a padding around an `.Artist`.
21
+
22
+ `TextArea`
23
+ Contains a single `.Text` instance.
24
+ """
25
+
26
+ import functools
27
+ import threading
28
+
29
+ import numpy as np
30
+
31
+ import matplotlib_rs as mpl
32
+ from matplotlib_rs import _api, _docstring
33
+ import matplotlib_rs.artist as martist
34
+ import matplotlib_rs.path as mpath
35
+ import matplotlib_rs.text as mtext
36
+ import matplotlib_rs.transforms as mtransforms
37
+ from matplotlib_rs.font_manager import FontProperties
38
+ from matplotlib_rs.image import BboxImage
39
+ from matplotlib_rs.patches import (
40
+ FancyBboxPatch, FancyArrowPatch, bbox_artist as mbbox_artist)
41
+ from matplotlib_rs.transforms import Bbox, BboxBase, TransformedBbox
42
+
43
+
44
+ DEBUG = False
45
+
46
+
47
+ def _compat_get_offset(meth):
48
+ """
49
+ Decorator for the get_offset method of OffsetBox and subclasses, that
50
+ allows supporting both the new signature (self, bbox, renderer) and the old
51
+ signature (self, width, height, xdescent, ydescent, renderer).
52
+ """
53
+ sigs = [lambda self, width, height, xdescent, ydescent, renderer: locals(),
54
+ lambda self, bbox, renderer: locals()]
55
+
56
+ @functools.wraps(meth)
57
+ def get_offset(self, *args, **kwargs):
58
+ params = _api.select_matching_signature(sigs, self, *args, **kwargs)
59
+ bbox = (params["bbox"] if "bbox" in params else
60
+ Bbox.from_bounds(-params["xdescent"], -params["ydescent"],
61
+ params["width"], params["height"]))
62
+ return meth(params["self"], bbox, params["renderer"])
63
+ return get_offset
64
+
65
+
66
+ # for debugging use
67
+ def _bbox_artist(*args, **kwargs):
68
+ if DEBUG:
69
+ mbbox_artist(*args, **kwargs)
70
+
71
+
72
+ def _get_packed_offsets(widths, total, sep, mode="fixed"):
73
+ r"""
74
+ Pack boxes specified by their *widths*.
75
+
76
+ For simplicity of the description, the terminology used here assumes a
77
+ horizontal layout, but the function works equally for a vertical layout.
78
+
79
+ There are three packing *mode*\s:
80
+
81
+ - 'fixed': The elements are packed tight to the left with a spacing of
82
+ *sep* in between. If *total* is *None* the returned total will be the
83
+ right edge of the last box. A non-*None* total will be passed unchecked
84
+ to the output. In particular this means that right edge of the last
85
+ box may be further to the right than the returned total.
86
+
87
+ - 'expand': Distribute the boxes with equal spacing so that the left edge
88
+ of the first box is at 0, and the right edge of the last box is at
89
+ *total*. The parameter *sep* is ignored in this mode. A total of *None*
90
+ is accepted and considered equal to 1. The total is returned unchanged
91
+ (except for the conversion *None* to 1). If the total is smaller than
92
+ the sum of the widths, the laid out boxes will overlap.
93
+
94
+ - 'equal': If *total* is given, the total space is divided in N equal
95
+ ranges and each box is left-aligned within its subspace.
96
+ Otherwise (*total* is *None*), *sep* must be provided and each box is
97
+ left-aligned in its subspace of width ``(max(widths) + sep)``. The
98
+ total width is then calculated to be ``N * (max(widths) + sep)``.
99
+
100
+ Parameters
101
+ ----------
102
+ widths : list of float
103
+ Widths of boxes to be packed.
104
+ total : float or None
105
+ Intended total length. *None* if not used.
106
+ sep : float or None
107
+ Spacing between boxes.
108
+ mode : {'fixed', 'expand', 'equal'}
109
+ The packing mode.
110
+
111
+ Returns
112
+ -------
113
+ total : float
114
+ The total width needed to accommodate the laid out boxes.
115
+ offsets : array of float
116
+ The left offsets of the boxes.
117
+ """
118
+ _api.check_in_list(["fixed", "expand", "equal"], mode=mode)
119
+
120
+ if mode == "fixed":
121
+ offsets_ = np.cumsum([0] + [w + sep for w in widths])
122
+ offsets = offsets_[:-1]
123
+ if total is None:
124
+ total = offsets_[-1] - sep
125
+ return total, offsets
126
+
127
+ elif mode == "expand":
128
+ # This is a bit of a hack to avoid a TypeError when *total*
129
+ # is None and used in conjugation with tight layout.
130
+ if total is None:
131
+ total = 1
132
+ if len(widths) > 1:
133
+ sep = (total - sum(widths)) / (len(widths) - 1)
134
+ else:
135
+ sep = 0
136
+ offsets_ = np.cumsum([0] + [w + sep for w in widths])
137
+ offsets = offsets_[:-1]
138
+ return total, offsets
139
+
140
+ elif mode == "equal":
141
+ maxh = max(widths)
142
+ if total is None:
143
+ if sep is None:
144
+ raise ValueError("total and sep cannot both be None when "
145
+ "using layout mode 'equal'")
146
+ total = (maxh + sep) * len(widths)
147
+ else:
148
+ sep = total / len(widths) - maxh
149
+ offsets = (maxh + sep) * np.arange(len(widths))
150
+ return total, offsets
151
+
152
+
153
+ def _get_aligned_offsets(yspans, height, align="baseline"):
154
+ """
155
+ Align boxes each specified by their ``(y0, y1)`` spans.
156
+
157
+ For simplicity of the description, the terminology used here assumes a
158
+ horizontal layout (i.e., vertical alignment), but the function works
159
+ equally for a vertical layout.
160
+
161
+ Parameters
162
+ ----------
163
+ yspans
164
+ List of (y0, y1) spans of boxes to be aligned.
165
+ height : float or None
166
+ Intended total height. If None, the maximum of the heights
167
+ (``y1 - y0``) in *yspans* is used.
168
+ align : {'baseline', 'left', 'top', 'right', 'bottom', 'center'}
169
+ The alignment anchor of the boxes.
170
+
171
+ Returns
172
+ -------
173
+ (y0, y1)
174
+ y range spanned by the packing. If a *height* was originally passed
175
+ in, then for all alignments other than "baseline", a span of ``(0,
176
+ height)`` is used without checking that it is actually large enough).
177
+ descent
178
+ The descent of the packing.
179
+ offsets
180
+ The bottom offsets of the boxes.
181
+ """
182
+
183
+ _api.check_in_list(
184
+ ["baseline", "left", "top", "right", "bottom", "center"], align=align)
185
+ if height is None:
186
+ height = max(y1 - y0 for y0, y1 in yspans)
187
+
188
+ if align == "baseline":
189
+ yspan = (min(y0 for y0, y1 in yspans), max(y1 for y0, y1 in yspans))
190
+ offsets = [0] * len(yspans)
191
+ elif align in ["left", "bottom"]:
192
+ yspan = (0, height)
193
+ offsets = [-y0 for y0, y1 in yspans]
194
+ elif align in ["right", "top"]:
195
+ yspan = (0, height)
196
+ offsets = [height - y1 for y0, y1 in yspans]
197
+ elif align == "center":
198
+ yspan = (0, height)
199
+ offsets = [(height - (y1 - y0)) * .5 - y0 for y0, y1 in yspans]
200
+
201
+ return yspan, offsets
202
+
203
+
204
+ class OffsetBox(martist.Artist):
205
+ """
206
+ A simple container artist.
207
+
208
+ The child artists are meant to be drawn at a relative position to its
209
+ parent.
210
+
211
+ Being an artist itself, all keyword arguments are passed on to `.Artist`.
212
+ """
213
+ def __init__(self, **kwargs):
214
+ super().__init__()
215
+ self._internal_update(kwargs)
216
+ # Clipping has not been implemented in the OffsetBox family, so
217
+ # disable the clip flag for consistency. It can always be turned back
218
+ # on to zero effect.
219
+ self.set_clip_on(False)
220
+ self._children = []
221
+ self._offset = (0, 0)
222
+
223
+ def set_figure(self, fig):
224
+ """
225
+ Set the `.Figure` for the `.OffsetBox` and all its children.
226
+
227
+ Parameters
228
+ ----------
229
+ fig : `~matplotlib.figure.Figure`
230
+ """
231
+ super().set_figure(fig)
232
+ for c in self.get_children():
233
+ c.set_figure(fig)
234
+
235
+ @martist.Artist.axes.setter
236
+ def axes(self, ax):
237
+ # TODO deal with this better
238
+ martist.Artist.axes.fset(self, ax)
239
+ for c in self.get_children():
240
+ if c is not None:
241
+ c.axes = ax
242
+
243
+ def contains(self, mouseevent):
244
+ """
245
+ Delegate the mouse event contains-check to the children.
246
+
247
+ As a container, the `.OffsetBox` does not respond itself to
248
+ mouseevents.
249
+
250
+ Parameters
251
+ ----------
252
+ mouseevent : `~matplotlib.backend_bases.MouseEvent`
253
+
254
+ Returns
255
+ -------
256
+ contains : bool
257
+ Whether any values are within the radius.
258
+ details : dict
259
+ An artist-specific dictionary of details of the event context,
260
+ such as which points are contained in the pick radius. See the
261
+ individual Artist subclasses for details.
262
+
263
+ See Also
264
+ --------
265
+ .Artist.contains
266
+ """
267
+ if self._different_canvas(mouseevent):
268
+ return False, {}
269
+ for c in self.get_children():
270
+ a, b = c.contains(mouseevent)
271
+ if a:
272
+ return a, b
273
+ return False, {}
274
+
275
+ def set_offset(self, xy):
276
+ """
277
+ Set the offset.
278
+
279
+ Parameters
280
+ ----------
281
+ xy : (float, float) or callable
282
+ The (x, y) coordinates of the offset in display units. These can
283
+ either be given explicitly as a tuple (x, y), or by providing a
284
+ function that converts the extent into the offset. This function
285
+ must have the signature::
286
+
287
+ def offset(width, height, xdescent, ydescent, renderer) \
288
+ -> (float, float)
289
+ """
290
+ self._offset = xy
291
+ self.stale = True
292
+
293
+ @_compat_get_offset
294
+ def get_offset(self, bbox, renderer):
295
+ """
296
+ Return the offset as a tuple (x, y).
297
+
298
+ The extent parameters have to be provided to handle the case where the
299
+ offset is dynamically determined by a callable (see
300
+ `~.OffsetBox.set_offset`).
301
+
302
+ Parameters
303
+ ----------
304
+ bbox : `.Bbox`
305
+ renderer : `.RendererBase` subclass
306
+ """
307
+ return (
308
+ self._offset(bbox.width, bbox.height, -bbox.x0, -bbox.y0, renderer)
309
+ if callable(self._offset)
310
+ else self._offset)
311
+
312
+ def set_width(self, width):
313
+ """
314
+ Set the width of the box.
315
+
316
+ Parameters
317
+ ----------
318
+ width : float
319
+ """
320
+ self.width = width
321
+ self.stale = True
322
+
323
+ def set_height(self, height):
324
+ """
325
+ Set the height of the box.
326
+
327
+ Parameters
328
+ ----------
329
+ height : float
330
+ """
331
+ self.height = height
332
+ self.stale = True
333
+
334
+ def get_visible_children(self):
335
+ r"""Return a list of the visible child `.Artist`\s."""
336
+ return [c for c in self._children if c.get_visible()]
337
+
338
+ def get_children(self):
339
+ r"""Return a list of the child `.Artist`\s."""
340
+ return self._children
341
+
342
+ def _get_bbox_and_child_offsets(self, renderer):
343
+ """
344
+ Return the bbox of the offsetbox and the child offsets.
345
+
346
+ The bbox should satisfy ``x0 <= x1 and y0 <= y1``.
347
+
348
+ Parameters
349
+ ----------
350
+ renderer : `.RendererBase` subclass
351
+
352
+ Returns
353
+ -------
354
+ bbox
355
+ list of (xoffset, yoffset) pairs
356
+ """
357
+ raise NotImplementedError(
358
+ "get_bbox_and_offsets must be overridden in derived classes")
359
+
360
+ def get_bbox(self, renderer):
361
+ """Return the bbox of the offsetbox, ignoring parent offsets."""
362
+ bbox, offsets = _rs_bbox_and_child_offsets(self, renderer)
363
+ return bbox
364
+
365
+ def get_window_extent(self, renderer=None):
366
+ # docstring inherited
367
+ if renderer is None:
368
+ renderer = self.get_figure(root=True)._get_renderer()
369
+ bbox = self.get_bbox(renderer)
370
+ try: # Some subclasses redefine get_offset to take no args.
371
+ px, py = self.get_offset(bbox, renderer)
372
+ except TypeError:
373
+ px, py = self.get_offset()
374
+ return bbox.translated(px, py)
375
+
376
+ def draw(self, renderer):
377
+ """
378
+ Update the location of children if necessary and draw them
379
+ to the given *renderer*.
380
+ """
381
+ bbox, offsets = _rs_bbox_and_child_offsets(self, renderer)
382
+ px, py = self.get_offset(bbox, renderer)
383
+ for c, (ox, oy) in zip(self.get_visible_children(), offsets):
384
+ c.set_offset((px + ox, py + oy))
385
+ c.draw(renderer)
386
+ _bbox_artist(self, renderer, fill=False, props=dict(pad=0.))
387
+ self.stale = False
388
+
389
+
390
+ # matplotlib_rs: `_rs_kept.extents` holds the extents of the boxes of the
391
+ # legend that is drawing itself in this thread, by (id(box), id(renderer));
392
+ # it is None (or not set) when no legend is drawing.
393
+ #
394
+ # A box computes the extents of all the boxes inside it for its own extent,
395
+ # and again to draw them, and each of these does the same: the text of a
396
+ # legend entry was laid out a dozen times in one draw. `Legend.draw` changes
397
+ # nothing its boxes' extents depend on (only their offsets), so while it
398
+ # runs an extent is computed once.
399
+ _rs_kept = threading.local()
400
+
401
+
402
+ def _rs_bbox_and_child_offsets(box, renderer):
403
+ """``box._get_bbox_and_child_offsets(renderer)`` (see `_rs_kept`)."""
404
+ kept = getattr(_rs_kept, "extents", None)
405
+ if kept is None:
406
+ return box._get_bbox_and_child_offsets(renderer)
407
+ key = (id(box), id(renderer))
408
+ result = kept.get(key)
409
+ if result is None:
410
+ result = kept[key] = box._get_bbox_and_child_offsets(renderer)
411
+ return result
412
+
413
+
414
+ class PackerBase(OffsetBox):
415
+ def __init__(self, pad=0., sep=0., width=None, height=None,
416
+ align="baseline", mode="fixed", children=None):
417
+ """
418
+ Parameters
419
+ ----------
420
+ pad : float, default: 0.0
421
+ The boundary padding in points.
422
+
423
+ sep : float, default: 0.0
424
+ The spacing between items in points.
425
+
426
+ width, height : float, optional
427
+ Width and height of the container box in pixels, calculated if
428
+ *None*.
429
+
430
+ align : {'top', 'bottom', 'left', 'right', 'center', 'baseline'}, \
431
+ default: 'baseline'
432
+ Alignment of boxes.
433
+
434
+ mode : {'fixed', 'expand', 'equal'}, default: 'fixed'
435
+ The packing mode.
436
+
437
+ - 'fixed' packs the given `.Artist`\\s tight with *sep* spacing.
438
+ - 'expand' uses the maximal available space to distribute the
439
+ artists with equal spacing in between.
440
+ - 'equal': Each artist an equal fraction of the available space
441
+ and is left-aligned (or top-aligned) therein.
442
+
443
+ children : list of `.Artist`
444
+ The artists to pack.
445
+
446
+ Notes
447
+ -----
448
+ *pad* and *sep* are in points and will be scaled with the renderer
449
+ dpi, while *width* and *height* are in pixels.
450
+ """
451
+ super().__init__()
452
+ self.height = height
453
+ self.width = width
454
+ self.sep = sep
455
+ self.pad = pad
456
+ self.mode = mode
457
+ self.align = align
458
+ self._children = children
459
+
460
+
461
+ class VPacker(PackerBase):
462
+ """
463
+ VPacker packs its children vertically, automatically adjusting their
464
+ relative positions at draw time.
465
+
466
+ .. code-block:: none
467
+
468
+ +---------+
469
+ | Child 1 |
470
+ | Child 2 |
471
+ | Child 3 |
472
+ +---------+
473
+ """
474
+
475
+ def _get_bbox_and_child_offsets(self, renderer):
476
+ # docstring inherited
477
+ dpicor = renderer.points_to_pixels(1.)
478
+ pad = self.pad * dpicor
479
+ sep = self.sep * dpicor
480
+
481
+ if self.width is not None:
482
+ for c in self.get_visible_children():
483
+ if isinstance(c, PackerBase) and c.mode == "expand":
484
+ c.set_width(self.width)
485
+
486
+ bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
487
+ (x0, x1), xoffsets = _get_aligned_offsets(
488
+ [bbox.intervalx for bbox in bboxes], self.width, self.align)
489
+ height, yoffsets = _get_packed_offsets(
490
+ [bbox.height for bbox in bboxes], self.height, sep, self.mode)
491
+
492
+ yoffsets = height - (yoffsets + [bbox.y1 for bbox in bboxes])
493
+ ydescent = yoffsets[0]
494
+ yoffsets = yoffsets - ydescent
495
+
496
+ return (
497
+ Bbox.from_bounds(x0, -ydescent, x1 - x0, height).padded(pad),
498
+ [*zip(xoffsets, yoffsets)])
499
+
500
+
501
+ class HPacker(PackerBase):
502
+ """
503
+ HPacker packs its children horizontally, automatically adjusting their
504
+ relative positions at draw time.
505
+
506
+ .. code-block:: none
507
+
508
+ +-------------------------------+
509
+ | Child 1 Child 2 Child 3 |
510
+ +-------------------------------+
511
+ """
512
+
513
+ def _get_bbox_and_child_offsets(self, renderer):
514
+ # docstring inherited
515
+ dpicor = renderer.points_to_pixels(1.)
516
+ pad = self.pad * dpicor
517
+ sep = self.sep * dpicor
518
+
519
+ bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
520
+ if not bboxes:
521
+ return Bbox.from_bounds(0, 0, 0, 0).padded(pad), []
522
+
523
+ (y0, y1), yoffsets = _get_aligned_offsets(
524
+ [bbox.intervaly for bbox in bboxes], self.height, self.align)
525
+ width, xoffsets = _get_packed_offsets(
526
+ [bbox.width for bbox in bboxes], self.width, sep, self.mode)
527
+
528
+ x0 = bboxes[0].x0
529
+ xoffsets -= ([bbox.x0 for bbox in bboxes] - x0)
530
+
531
+ return (Bbox.from_bounds(x0, y0, width, y1 - y0).padded(pad),
532
+ [*zip(xoffsets, yoffsets)])
533
+
534
+
535
+ class PaddedBox(OffsetBox):
536
+ """
537
+ A container to add a padding around an `.Artist`.
538
+
539
+ The `.PaddedBox` contains a `.FancyBboxPatch` that is used to visualize
540
+ it when rendering.
541
+
542
+ .. code-block:: none
543
+
544
+ +----------------------------+
545
+ | |
546
+ | |
547
+ | |
548
+ | <--pad--> Artist |
549
+ | ^ |
550
+ | pad |
551
+ | v |
552
+ +----------------------------+
553
+
554
+ Attributes
555
+ ----------
556
+ pad : float
557
+ The padding in points.
558
+ patch : `.FancyBboxPatch`
559
+ When *draw_frame* is True, this `.FancyBboxPatch` is made visible and
560
+ creates a border around the box.
561
+ """
562
+
563
+ def __init__(self, child, pad=0., *, draw_frame=False, patch_attrs=None):
564
+ """
565
+ Parameters
566
+ ----------
567
+ child : `~matplotlib.artist.Artist`
568
+ The contained `.Artist`.
569
+ pad : float, default: 0.0
570
+ The padding in points. This will be scaled with the renderer dpi.
571
+ In contrast, *width* and *height* are in *pixels* and thus not
572
+ scaled.
573
+ draw_frame : bool
574
+ Whether to draw the contained `.FancyBboxPatch`.
575
+ patch_attrs : dict or None
576
+ Additional parameters passed to the contained `.FancyBboxPatch`.
577
+ """
578
+ super().__init__()
579
+ self.pad = pad
580
+ self._children = [child]
581
+ self.patch = FancyBboxPatch(
582
+ xy=(0.0, 0.0), width=1., height=1.,
583
+ facecolor='w', edgecolor='k',
584
+ mutation_scale=1, # self.prop.get_size_in_points(),
585
+ snap=True,
586
+ visible=draw_frame,
587
+ boxstyle="square,pad=0",
588
+ )
589
+ if patch_attrs is not None:
590
+ self.patch.update(patch_attrs)
591
+
592
+ def _get_bbox_and_child_offsets(self, renderer):
593
+ # docstring inherited.
594
+ pad = self.pad * renderer.points_to_pixels(1.)
595
+ return (self._children[0].get_bbox(renderer).padded(pad), [(0, 0)])
596
+
597
+ def draw(self, renderer):
598
+ # docstring inherited
599
+ bbox, offsets = self._get_bbox_and_child_offsets(renderer)
600
+ px, py = self.get_offset(bbox, renderer)
601
+ for c, (ox, oy) in zip(self.get_visible_children(), offsets):
602
+ c.set_offset((px + ox, py + oy))
603
+
604
+ self.draw_frame(renderer)
605
+
606
+ for c in self.get_visible_children():
607
+ c.draw(renderer)
608
+
609
+ self.stale = False
610
+
611
+ def update_frame(self, bbox, fontsize=None):
612
+ self.patch.set_bounds(bbox.bounds)
613
+ if fontsize:
614
+ self.patch.set_mutation_scale(fontsize)
615
+ self.stale = True
616
+
617
+ def draw_frame(self, renderer):
618
+ # update the location and size of the legend
619
+ self.update_frame(self.get_window_extent(renderer))
620
+ self.patch.draw(renderer)
621
+
622
+
623
+ class DrawingArea(OffsetBox):
624
+ """
625
+ The DrawingArea can contain any Artist as a child. The DrawingArea
626
+ has a fixed width and height. The position of children relative to
627
+ the parent is fixed. The children can be clipped at the
628
+ boundaries of the parent.
629
+ """
630
+
631
+ def __init__(self, width, height, xdescent=0., ydescent=0., clip=False):
632
+ """
633
+ Parameters
634
+ ----------
635
+ width, height : float
636
+ Width and height of the container box.
637
+ xdescent, ydescent : float
638
+ Descent of the box in x- and y-direction.
639
+ clip : bool
640
+ Whether to clip the children to the box.
641
+ """
642
+ super().__init__()
643
+ self.width = width
644
+ self.height = height
645
+ self.xdescent = xdescent
646
+ self.ydescent = ydescent
647
+ self._clip_children = clip
648
+ self.offset_transform = mtransforms.Affine2D()
649
+ self.dpi_transform = mtransforms.Affine2D()
650
+
651
+ @property
652
+ def clip_children(self):
653
+ """
654
+ If the children of this DrawingArea should be clipped
655
+ by DrawingArea bounding box.
656
+ """
657
+ return self._clip_children
658
+
659
+ @clip_children.setter
660
+ def clip_children(self, val):
661
+ self._clip_children = bool(val)
662
+ self.stale = True
663
+
664
+ def get_transform(self):
665
+ """
666
+ Return the `~matplotlib.transforms.Transform` applied to the children.
667
+ """
668
+ return self.dpi_transform + self.offset_transform
669
+
670
+ def set_transform(self, t):
671
+ """
672
+ set_transform is ignored.
673
+ """
674
+
675
+ def set_offset(self, xy):
676
+ """
677
+ Set the offset of the container.
678
+
679
+ Parameters
680
+ ----------
681
+ xy : (float, float)
682
+ The (x, y) coordinates of the offset in display units.
683
+ """
684
+ self._offset = xy
685
+ self.offset_transform.clear()
686
+ self.offset_transform.translate(xy[0], xy[1])
687
+ self.stale = True
688
+
689
+ def get_offset(self):
690
+ """Return offset of the container."""
691
+ return self._offset
692
+
693
+ def get_bbox(self, renderer):
694
+ # docstring inherited
695
+ dpi_cor = renderer.points_to_pixels(1.)
696
+ return Bbox.from_bounds(
697
+ -self.xdescent * dpi_cor, -self.ydescent * dpi_cor,
698
+ self.width * dpi_cor, self.height * dpi_cor)
699
+
700
+ def add_artist(self, a):
701
+ """Add an `.Artist` to the container box."""
702
+ self._children.append(a)
703
+ if not a.is_transform_set():
704
+ a.set_transform(self.get_transform())
705
+ if self.axes is not None:
706
+ a.axes = self.axes
707
+ fig = self.get_figure(root=False)
708
+ if fig is not None:
709
+ a.set_figure(fig)
710
+
711
+ def draw(self, renderer):
712
+ # docstring inherited
713
+
714
+ dpi_cor = renderer.points_to_pixels(1.)
715
+ self.dpi_transform.clear()
716
+ self.dpi_transform.scale(dpi_cor)
717
+
718
+ # At this point the DrawingArea has a transform
719
+ # to the display space so the path created is
720
+ # good for clipping children
721
+ tpath = mtransforms.TransformedPath(
722
+ mpath.Path([[0, 0], [0, self.height],
723
+ [self.width, self.height],
724
+ [self.width, 0]]),
725
+ self.get_transform())
726
+ for c in self._children:
727
+ if self._clip_children and not (c.clipbox or c._clippath):
728
+ c.set_clip_path(tpath)
729
+ c.draw(renderer)
730
+
731
+ _bbox_artist(self, renderer, fill=False, props=dict(pad=0.))
732
+ self.stale = False
733
+
734
+
735
+ class TextArea(OffsetBox):
736
+ """
737
+ The TextArea is a container artist for a single Text instance.
738
+
739
+ The text is placed at (0, 0) with baseline+left alignment, by default. The
740
+ width and height of the TextArea instance is the width and height of its
741
+ child text.
742
+ """
743
+
744
+ def __init__(self, s,
745
+ *,
746
+ textprops=None,
747
+ multilinebaseline=False,
748
+ ):
749
+ """
750
+ Parameters
751
+ ----------
752
+ s : str
753
+ The text to be displayed.
754
+ textprops : dict, default: {}
755
+ Dictionary of keyword parameters to be passed to the `.Text`
756
+ instance in the TextArea.
757
+ multilinebaseline : bool, default: False
758
+ Whether the baseline for multiline text is adjusted so that it
759
+ is (approximately) center-aligned with single-line text.
760
+ """
761
+ if textprops is None:
762
+ textprops = {}
763
+ self._text = mtext.Text(0, 0, s, **textprops)
764
+ super().__init__()
765
+ self._children = [self._text]
766
+ self.offset_transform = mtransforms.Affine2D()
767
+ self._baseline_transform = mtransforms.Affine2D()
768
+ self._text.set_transform(self.offset_transform +
769
+ self._baseline_transform)
770
+ self._multilinebaseline = multilinebaseline
771
+
772
+ def set_text(self, s):
773
+ """Set the text of this area as a string."""
774
+ self._text.set_text(s)
775
+ self.stale = True
776
+
777
+ def get_text(self):
778
+ """Return the string representation of this area's text."""
779
+ return self._text.get_text()
780
+
781
+ def set_multilinebaseline(self, t):
782
+ """
783
+ Set multilinebaseline.
784
+
785
+ If True, the baseline for multiline text is adjusted so that it is
786
+ (approximately) center-aligned with single-line text. This is used
787
+ e.g. by the legend implementation so that single-line labels are
788
+ baseline-aligned, but multiline labels are "center"-aligned with them.
789
+ """
790
+ self._multilinebaseline = t
791
+ self.stale = True
792
+
793
+ def get_multilinebaseline(self):
794
+ """
795
+ Get multilinebaseline.
796
+ """
797
+ return self._multilinebaseline
798
+
799
+ def set_transform(self, t):
800
+ """
801
+ set_transform is ignored.
802
+ """
803
+
804
+ def set_offset(self, xy):
805
+ """
806
+ Set the offset of the container.
807
+
808
+ Parameters
809
+ ----------
810
+ xy : (float, float)
811
+ The (x, y) coordinates of the offset in display units.
812
+ """
813
+ self._offset = xy
814
+ self.offset_transform.clear()
815
+ self.offset_transform.translate(xy[0], xy[1])
816
+ self.stale = True
817
+
818
+ def get_offset(self):
819
+ """Return offset of the container."""
820
+ return self._offset
821
+
822
+ def get_bbox(self, renderer):
823
+ # matplotlib_rs: once while a legend draws (see _rs_kept).
824
+ kept = getattr(_rs_kept, "extents", None)
825
+ if kept is None:
826
+ return self._rs_get_bbox(renderer)
827
+ key = (id(self), id(renderer))
828
+ bbox = kept.get(key)
829
+ if bbox is None:
830
+ bbox = kept[key] = self._rs_get_bbox(renderer)
831
+ return bbox
832
+
833
+ def _rs_get_bbox(self, renderer):
834
+ _, h_, d_ = mtext._get_text_metrics_with_cache(
835
+ renderer, "lp", self._text._fontproperties,
836
+ ismath="TeX" if self._text.get_usetex() else False,
837
+ dpi=self.get_figure(root=True).dpi)
838
+
839
+ bbox, info, _ = self._text._get_layout(renderer)
840
+ _last_line, (_last_width, _last_ascent, last_descent), _last_xy = info[-1]
841
+ w, h = bbox.size
842
+
843
+ self._baseline_transform.clear()
844
+
845
+ if len(info) > 1 and self._multilinebaseline:
846
+ yd_new = 0.5 * h - 0.5 * (h_ - d_)
847
+ self._baseline_transform.translate(0, last_descent - yd_new)
848
+ last_descent = yd_new
849
+ else: # single line
850
+ h_d = max(h_ - d_, h - last_descent)
851
+ h = h_d + last_descent
852
+
853
+ ha = self._text.get_horizontalalignment()
854
+ x0 = {"left": 0, "center": -w / 2, "right": -w}[ha]
855
+
856
+ return Bbox.from_bounds(x0, -last_descent, w, h)
857
+
858
+ def draw(self, renderer):
859
+ # docstring inherited
860
+ self._text.draw(renderer)
861
+ _bbox_artist(self, renderer, fill=False, props=dict(pad=0.))
862
+ self.stale = False
863
+
864
+
865
+ class AuxTransformBox(OffsetBox):
866
+ """
867
+ An OffsetBox with an auxiliary transform.
868
+
869
+ All child artists are first transformed with *aux_transform*, then
870
+ translated with an offset (the same for all children) so the bounding
871
+ box of the children matches the drawn box. (In other words, adding an
872
+ arbitrary translation to *aux_transform* has no effect as it will be
873
+ cancelled out by the later offsetting.)
874
+
875
+ `AuxTransformBox` is similar to `.DrawingArea`, except that the extent of
876
+ the box is not predetermined but calculated from the window extent of its
877
+ children, and the extent of the children will be calculated in the
878
+ transformed coordinate.
879
+ """
880
+ def __init__(self, aux_transform):
881
+ self.aux_transform = aux_transform
882
+ super().__init__()
883
+ self.offset_transform = mtransforms.Affine2D()
884
+ # ref_offset_transform makes offset_transform always relative to the
885
+ # lower-left corner of the bbox of its children.
886
+ self.ref_offset_transform = mtransforms.Affine2D()
887
+
888
+ def add_artist(self, a):
889
+ """Add an `.Artist` to the container box."""
890
+ self._children.append(a)
891
+ a.set_transform(self.get_transform())
892
+ self.stale = True
893
+
894
+ def get_transform(self):
895
+ """Return the `.Transform` applied to the children."""
896
+ return (self.aux_transform
897
+ + self.ref_offset_transform
898
+ + self.offset_transform)
899
+
900
+ def set_transform(self, t):
901
+ """
902
+ set_transform is ignored.
903
+ """
904
+
905
+ def set_offset(self, xy):
906
+ """
907
+ Set the offset of the container.
908
+
909
+ Parameters
910
+ ----------
911
+ xy : (float, float)
912
+ The (x, y) coordinates of the offset in display units.
913
+ """
914
+ self._offset = xy
915
+ self.offset_transform.clear()
916
+ self.offset_transform.translate(xy[0], xy[1])
917
+ self.stale = True
918
+
919
+ def get_offset(self):
920
+ """Return offset of the container."""
921
+ return self._offset
922
+
923
+ def get_bbox(self, renderer):
924
+ # clear the offset transforms
925
+ _off = self.offset_transform.get_matrix() # to be restored later
926
+ self.ref_offset_transform.clear()
927
+ self.offset_transform.clear()
928
+ # calculate the extent
929
+ bboxes = [c.get_window_extent(renderer) for c in self._children]
930
+ ub = Bbox.union(bboxes)
931
+ # adjust ref_offset_transform
932
+ self.ref_offset_transform.translate(-ub.x0, -ub.y0)
933
+ # restore offset transform
934
+ self.offset_transform.set_matrix(_off)
935
+ return Bbox.from_bounds(0, 0, ub.width, ub.height)
936
+
937
+ def draw(self, renderer):
938
+ # docstring inherited
939
+ for c in self._children:
940
+ c.draw(renderer)
941
+ _bbox_artist(self, renderer, fill=False, props=dict(pad=0.))
942
+ self.stale = False
943
+
944
+
945
+ class AnchoredOffsetbox(OffsetBox):
946
+ """
947
+ An OffsetBox placed according to location *loc*.
948
+
949
+ AnchoredOffsetbox has a single child. When multiple children are needed,
950
+ use an extra OffsetBox to enclose them. By default, the offset box is
951
+ anchored against its parent Axes. You may explicitly specify the
952
+ *bbox_to_anchor*.
953
+ """
954
+ zorder = 5 # zorder of the legend
955
+
956
+ # Location codes
957
+ codes = {'upper right': 1,
958
+ 'upper left': 2,
959
+ 'lower left': 3,
960
+ 'lower right': 4,
961
+ 'right': 5,
962
+ 'center left': 6,
963
+ 'center right': 7,
964
+ 'lower center': 8,
965
+ 'upper center': 9,
966
+ 'center': 10,
967
+ }
968
+
969
+ def __init__(self, loc, *,
970
+ pad=0.4, borderpad=0.5,
971
+ child=None, prop=None, frameon=True,
972
+ bbox_to_anchor=None,
973
+ bbox_transform=None,
974
+ **kwargs):
975
+ """
976
+ Parameters
977
+ ----------
978
+ loc : str
979
+ The box location. Valid locations are
980
+ 'upper left', 'upper center', 'upper right',
981
+ 'center left', 'center', 'center right',
982
+ 'lower left', 'lower center', 'lower right'.
983
+ For backward compatibility, numeric values are accepted as well.
984
+ See the parameter *loc* of `.Legend` for details.
985
+ pad : float, default: 0.4
986
+ Padding around the child as fraction of the fontsize.
987
+ borderpad : float or (float, float), default: 0.5
988
+ Padding between the offsetbox frame and the *bbox_to_anchor*.
989
+ If a float, the same padding is used for both x and y.
990
+ If a tuple of two floats, it specifies the (x, y) padding.
991
+
992
+ .. versionadded:: 3.11
993
+ The *borderpad* parameter now accepts a tuple of (x, y) paddings.
994
+ child : `.OffsetBox`
995
+ The box that will be anchored.
996
+ prop : `.FontProperties`
997
+ This is only used as a reference for paddings. If not given,
998
+ :rc:`legend.fontsize` is used.
999
+ frameon : bool
1000
+ Whether to draw a frame around the box.
1001
+ bbox_to_anchor : `.BboxBase`, 2-tuple, or 4-tuple of floats
1002
+ Box that is used to position the legend in conjunction with *loc*.
1003
+ bbox_transform : None or :class:`matplotlib.transforms.Transform`
1004
+ The transform for the bounding box (*bbox_to_anchor*).
1005
+ **kwargs
1006
+ All other parameters are passed on to `.OffsetBox`.
1007
+
1008
+ Notes
1009
+ -----
1010
+ See `.Legend` for a detailed description of the anchoring mechanism.
1011
+ """
1012
+ super().__init__(**kwargs)
1013
+
1014
+ self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform)
1015
+ self.set_child(child)
1016
+
1017
+ if isinstance(loc, str):
1018
+ loc = _api.getitem_checked(self.codes, loc=loc)
1019
+
1020
+ self.loc = loc
1021
+ self.borderpad = borderpad
1022
+ self.pad = pad
1023
+
1024
+ if prop is None:
1025
+ self.prop = FontProperties(size=mpl.rcParams["legend.fontsize"])
1026
+ else:
1027
+ self.prop = FontProperties._from_any(prop)
1028
+ if isinstance(prop, dict) and "size" not in prop:
1029
+ self.prop.set_size(mpl.rcParams["legend.fontsize"])
1030
+
1031
+ self.patch = FancyBboxPatch(
1032
+ xy=(0.0, 0.0), width=1., height=1.,
1033
+ facecolor='w', edgecolor='k',
1034
+ mutation_scale=self.prop.get_size_in_points(),
1035
+ snap=True,
1036
+ visible=frameon,
1037
+ boxstyle="square,pad=0",
1038
+ )
1039
+
1040
+ def set_child(self, child):
1041
+ """Set the child to be anchored."""
1042
+ self._child = child
1043
+ if child is not None:
1044
+ child.axes = self.axes
1045
+ self.stale = True
1046
+
1047
+ def get_child(self):
1048
+ """Return the child."""
1049
+ return self._child
1050
+
1051
+ def get_children(self):
1052
+ """Return the list of children."""
1053
+ return [self._child]
1054
+
1055
+ def get_bbox(self, renderer):
1056
+ # docstring inherited
1057
+ fontsize = renderer.points_to_pixels(self.prop.get_size_in_points())
1058
+ pad = self.pad * fontsize
1059
+ return self.get_child().get_bbox(renderer).padded(pad)
1060
+
1061
+ def get_bbox_to_anchor(self):
1062
+ """Return the bbox that the box is anchored to."""
1063
+ if self._bbox_to_anchor is None:
1064
+ return self.axes.bbox
1065
+ else:
1066
+ transform = self._bbox_to_anchor_transform
1067
+ if transform is None:
1068
+ return self._bbox_to_anchor
1069
+ else:
1070
+ return TransformedBbox(self._bbox_to_anchor, transform)
1071
+
1072
+ def set_bbox_to_anchor(self, bbox, transform=None):
1073
+ """
1074
+ Set the bbox that the box is anchored to.
1075
+
1076
+ *bbox* can be a Bbox instance, a list of [left, bottom, width,
1077
+ height], or a list of [left, bottom] where the width and
1078
+ height will be assumed to be zero. The bbox will be
1079
+ transformed to display coordinate by the given transform.
1080
+ """
1081
+ if bbox is None or isinstance(bbox, BboxBase):
1082
+ self._bbox_to_anchor = bbox
1083
+ else:
1084
+ try:
1085
+ l = len(bbox)
1086
+ except TypeError as err:
1087
+ raise ValueError(f"Invalid bbox: {bbox}") from err
1088
+
1089
+ if l == 2:
1090
+ bbox = [bbox[0], bbox[1], 0, 0]
1091
+
1092
+ self._bbox_to_anchor = Bbox.from_bounds(*bbox)
1093
+
1094
+ self._bbox_to_anchor_transform = transform
1095
+ self.stale = True
1096
+
1097
+ @_compat_get_offset
1098
+ def get_offset(self, bbox, renderer):
1099
+ # docstring inherited
1100
+ fontsize_in_pixels = renderer.points_to_pixels(self.prop.get_size_in_points())
1101
+ try:
1102
+ borderpad_x, borderpad_y = self.borderpad
1103
+ except TypeError:
1104
+ borderpad_x = self.borderpad
1105
+ borderpad_y = self.borderpad
1106
+ pad_x_pixels = borderpad_x * fontsize_in_pixels
1107
+ pad_y_pixels = borderpad_y * fontsize_in_pixels
1108
+ bbox_to_anchor = self.get_bbox_to_anchor()
1109
+ x0, y0 = _get_anchored_bbox(
1110
+ self.loc,
1111
+ Bbox.from_bounds(0, 0, bbox.width, bbox.height),
1112
+ bbox_to_anchor,
1113
+ pad_x_pixels,
1114
+ pad_y_pixels
1115
+ )
1116
+ return x0 - bbox.x0, y0 - bbox.y0
1117
+
1118
+ def update_frame(self, bbox, fontsize=None):
1119
+ self.patch.set_bounds(bbox.bounds)
1120
+ if fontsize:
1121
+ self.patch.set_mutation_scale(fontsize)
1122
+
1123
+ def draw(self, renderer):
1124
+ # docstring inherited
1125
+ if not self.get_visible():
1126
+ return
1127
+
1128
+ # update the location and size of the legend
1129
+ bbox = self.get_window_extent(renderer)
1130
+ fontsize = renderer.points_to_pixels(self.prop.get_size_in_points())
1131
+ self.update_frame(bbox, fontsize)
1132
+ self.patch.draw(renderer)
1133
+
1134
+ px, py = self.get_offset(self.get_bbox(renderer), renderer)
1135
+ self.get_child().set_offset((px, py))
1136
+ self.get_child().draw(renderer)
1137
+ self.stale = False
1138
+
1139
+
1140
+ def _get_anchored_bbox(loc, bbox, parentbbox, pad_x, pad_y):
1141
+ """
1142
+ Return the (x, y) position of the *bbox* anchored at the *parentbbox* with
1143
+ the *loc* code with the *borderpad* and padding *pad_x*, *pad_y*.
1144
+ """
1145
+ # This is only called internally and *loc* should already have been
1146
+ # validated. If 0 (None), we just let ``bbox.anchored`` raise.
1147
+ c = [None, "NE", "NW", "SW", "SE", "E", "W", "E", "S", "N", "C"][loc]
1148
+ container = parentbbox.padded(-pad_x, -pad_y)
1149
+ return bbox.anchored(c, container=container).p0
1150
+
1151
+
1152
+ class AnchoredText(AnchoredOffsetbox):
1153
+ """
1154
+ AnchoredOffsetbox with Text.
1155
+ """
1156
+
1157
+ def __init__(self, s, loc, *, pad=0.4, borderpad=0.5, prop=None, **kwargs):
1158
+ """
1159
+ Parameters
1160
+ ----------
1161
+ s : str
1162
+ Text.
1163
+
1164
+ loc : str
1165
+ Location code. See `AnchoredOffsetbox`.
1166
+
1167
+ pad : float, default: 0.4
1168
+ Padding around the text as fraction of the fontsize.
1169
+
1170
+ borderpad : float, default: 0.5
1171
+ Spacing between the offsetbox frame and the *bbox_to_anchor*.
1172
+
1173
+ prop : dict, optional
1174
+ Dictionary of keyword parameters to be passed to the
1175
+ `~matplotlib.text.Text` instance contained inside AnchoredText.
1176
+
1177
+ **kwargs
1178
+ All other parameters are passed to `AnchoredOffsetbox`.
1179
+ """
1180
+
1181
+ if prop is None:
1182
+ prop = {}
1183
+ badkwargs = {'va', 'verticalalignment'}
1184
+ if badkwargs & set(prop):
1185
+ raise ValueError(
1186
+ 'Mixing verticalalignment with AnchoredText is not supported.')
1187
+
1188
+ self.txt = TextArea(s, textprops=prop)
1189
+ fp = self.txt._text.get_fontproperties()
1190
+ super().__init__(
1191
+ loc, pad=pad, borderpad=borderpad, child=self.txt, prop=fp,
1192
+ **kwargs)
1193
+
1194
+
1195
+ class OffsetImage(OffsetBox):
1196
+ """
1197
+ Container artist for images.
1198
+
1199
+ Image data is displayed using `.BboxImage`. This image is meant to be positioned
1200
+ relative to a parent artist.
1201
+
1202
+ Parameters
1203
+ ----------
1204
+ arr: array-like or `PIL.Image.Image`
1205
+ The data to be color-coded. The interpretation depends on the
1206
+ shape:
1207
+
1208
+ - (M, N) `~numpy.ndarray` or masked array: values to be colormapped
1209
+ - (M, N, 3): RGB array
1210
+ - (M, N, 4): RGBA array
1211
+
1212
+ zoom: float, default: 1
1213
+ zoom factor:
1214
+
1215
+ - no zoom: factor =1
1216
+ - zoom in: factor > 1
1217
+ - zoom out: 0< factor < 1
1218
+
1219
+ cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
1220
+ The Colormap instance or registered colormap name used to map scalar
1221
+ data to colors. This parameter is ignored if X is RGB(A).
1222
+
1223
+ norm : str or `~matplotlib.colors.Normalize`, default: None
1224
+ Maps luminance to 0-1. This parameter is ignored if X is RGB(A).
1225
+
1226
+ interpolation : str, default: :rc:`image.interpolation`
1227
+ Supported values are 'none', 'auto', 'nearest', 'bilinear',
1228
+ 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite',
1229
+ 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell',
1230
+ 'sinc', 'lanczos', 'blackman'.
1231
+
1232
+ origin : {'upper', 'lower'}, default: :rc:`image.origin`
1233
+ Place the [0, 0] index of the array in the upper left or lower left
1234
+ corner of the Axes. The convention 'upper' is typically used for
1235
+ matrices and images.
1236
+
1237
+ filternorm : bool, default: True
1238
+ A parameter for the antigrain image resize filter
1239
+ (see the antigrain documentation).
1240
+ If filternorm is set, the filter normalizes integer values and corrects
1241
+ the rounding errors. It doesn't do anything with the source floating
1242
+ point values, it corrects only integers according to the rule of 1.0
1243
+ which means that any sum of pixel weights must be equal to 1.0. So,
1244
+ the filter function must produce a graph of the proper shape.
1245
+
1246
+ filterrad : float > 0, default: 4
1247
+ The filter radius for filters that have a radius parameter, i.e. when
1248
+ interpolation is one of: 'sinc', 'lanczos' or 'blackman'.
1249
+
1250
+ resample : bool, default: False
1251
+ When True, use a full resampling method. When False, only resample when
1252
+ the output image is larger than the input image.
1253
+
1254
+ dpi_cor: bool, default: True
1255
+ Correct for the backend DPI setting
1256
+
1257
+ **kwargs : `.BboxImage` properties
1258
+
1259
+ """
1260
+ def __init__(self, arr, *,
1261
+ zoom=1,
1262
+ cmap=None,
1263
+ norm=None,
1264
+ interpolation=None,
1265
+ origin=None,
1266
+ filternorm=True,
1267
+ filterrad=4.0,
1268
+ resample=False,
1269
+ dpi_cor=True,
1270
+ **kwargs
1271
+ ):
1272
+ super().__init__()
1273
+ self._dpi_cor = dpi_cor
1274
+
1275
+ self.image = BboxImage(bbox=self.get_window_extent,
1276
+ cmap=cmap,
1277
+ norm=norm,
1278
+ interpolation=interpolation,
1279
+ origin=origin,
1280
+ filternorm=filternorm,
1281
+ filterrad=filterrad,
1282
+ resample=resample,
1283
+ **kwargs
1284
+ )
1285
+
1286
+ self._children = [self.image]
1287
+
1288
+ self.set_zoom(zoom)
1289
+ self.set_data(arr)
1290
+
1291
+ def set_data(self, arr):
1292
+ self._data = np.asarray(arr)
1293
+ self.image.set_data(self._data)
1294
+ self.stale = True
1295
+
1296
+ def get_data(self):
1297
+ return self._data
1298
+
1299
+ def set_zoom(self, zoom):
1300
+ self._zoom = zoom
1301
+ self.stale = True
1302
+
1303
+ def get_zoom(self):
1304
+ return self._zoom
1305
+
1306
+ def get_offset(self):
1307
+ """Return offset of the container."""
1308
+ return self._offset
1309
+
1310
+ def get_children(self):
1311
+ return [self.image]
1312
+
1313
+ def get_bbox(self, renderer):
1314
+ dpi_cor = renderer.points_to_pixels(1.) if self._dpi_cor else 1.
1315
+ zoom = self.get_zoom()
1316
+ data = self.get_data()
1317
+ ny, nx = data.shape[:2]
1318
+ w, h = dpi_cor * nx * zoom, dpi_cor * ny * zoom
1319
+ return Bbox.from_bounds(0, 0, w, h)
1320
+
1321
+ def draw(self, renderer):
1322
+ # docstring inherited
1323
+ self.image.draw(renderer)
1324
+ # bbox_artist(self, renderer, fill=False, props=dict(pad=0.))
1325
+ self.stale = False
1326
+
1327
+
1328
+ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
1329
+ """
1330
+ Container for an `OffsetBox` referring to a specific position *xy*.
1331
+
1332
+ Optionally an arrow pointing from the offsetbox to *xy* can be drawn.
1333
+
1334
+ This is like `.Annotation`, but with `OffsetBox` instead of `.Text`.
1335
+ """
1336
+
1337
+ zorder = 3
1338
+
1339
+ def __str__(self):
1340
+ return f"AnnotationBbox({self.xy[0]:g},{self.xy[1]:g})"
1341
+
1342
+ @_docstring.interpd
1343
+ def __init__(self, offsetbox, xy, xybox=None, xycoords='data', boxcoords=None, *,
1344
+ frameon=True, pad=0.4, # FancyBboxPatch boxstyle.
1345
+ annotation_clip=None,
1346
+ box_alignment=(0.5, 0.5),
1347
+ bboxprops=None,
1348
+ arrowprops=None,
1349
+ fontsize=None,
1350
+ **kwargs):
1351
+ """
1352
+ Parameters
1353
+ ----------
1354
+ offsetbox : `OffsetBox`
1355
+
1356
+ xy : (float, float)
1357
+ The point *(x, y)* to annotate. The coordinate system is determined
1358
+ by *xycoords*.
1359
+
1360
+ xybox : (float, float), default: *xy*
1361
+ The position *(x, y)* to place the text at. The coordinate system
1362
+ is determined by *boxcoords*.
1363
+
1364
+ xycoords : single or two-tuple of str or `.Artist` or `.Transform` or \
1365
+ callable, default: 'data'
1366
+ The coordinate system that *xy* is given in. See the parameter
1367
+ *xycoords* in `.Annotation` for a detailed description.
1368
+
1369
+ boxcoords : single or two-tuple of str or `.Artist` or `.Transform` \
1370
+ or callable, default: value of *xycoords*
1371
+ The coordinate system that *xybox* is given in. See the parameter
1372
+ *textcoords* in `.Annotation` for a detailed description.
1373
+
1374
+ frameon : bool, default: True
1375
+ By default, the text is surrounded by a white `.FancyBboxPatch`
1376
+ (accessible as the ``patch`` attribute of the `.AnnotationBbox`).
1377
+ If *frameon* is set to False, this patch is made invisible.
1378
+
1379
+ annotation_clip: bool or None, default: None
1380
+ Whether to clip (i.e. not draw) the annotation when the annotation
1381
+ point *xy* is outside the Axes area.
1382
+
1383
+ - If *True*, the annotation will be clipped when *xy* is outside
1384
+ the Axes.
1385
+ - If *False*, the annotation will always be drawn.
1386
+ - If *None*, the annotation will be clipped when *xy* is outside
1387
+ the Axes and *xycoords* is 'data'.
1388
+
1389
+ pad : float, default: 0.4
1390
+ Padding around the offsetbox.
1391
+
1392
+ box_alignment : (float, float)
1393
+ A tuple of two floats for a vertical and horizontal alignment of
1394
+ the offset box w.r.t. the *boxcoords*.
1395
+ The lower-left corner is (0, 0) and upper-right corner is (1, 1).
1396
+
1397
+ bboxprops : dict, optional
1398
+ A dictionary of properties to set for the annotation bounding box,
1399
+ for example *boxstyle* and *alpha*. See `.FancyBboxPatch` for
1400
+ details.
1401
+
1402
+ arrowprops: dict, optional
1403
+ Arrow properties, see `.Annotation` for description.
1404
+
1405
+ fontsize: float or str, optional
1406
+ Translated to points and passed as *mutation_scale* into
1407
+ `.FancyBboxPatch` to scale attributes of the box style (e.g. pad
1408
+ or rounding_size). The name is chosen in analogy to `.Text` where
1409
+ *fontsize* defines the mutation scale as well. If not given,
1410
+ :rc:`legend.fontsize` is used. See `.Text.set_fontsize` for valid
1411
+ values.
1412
+
1413
+ **kwargs
1414
+ Other `AnnotationBbox` properties. See `.AnnotationBbox.set` for
1415
+ a list.
1416
+ """
1417
+
1418
+ martist.Artist.__init__(self)
1419
+ mtext._AnnotationBase.__init__(
1420
+ self, xy, xycoords=xycoords, annotation_clip=annotation_clip)
1421
+
1422
+ self.offsetbox = offsetbox
1423
+ self.arrowprops = arrowprops.copy() if arrowprops is not None else None
1424
+ self.set_fontsize(fontsize)
1425
+ self.xybox = xybox if xybox is not None else xy
1426
+ self.boxcoords = boxcoords if boxcoords is not None else xycoords
1427
+ self._box_alignment = box_alignment
1428
+
1429
+ if arrowprops is not None:
1430
+ self._arrow_relpos = self.arrowprops.pop("relpos", (0.5, 0.5))
1431
+ self.arrow_patch = FancyArrowPatch((0, 0), (1, 1),
1432
+ **self.arrowprops)
1433
+ else:
1434
+ self._arrow_relpos = None
1435
+ self.arrow_patch = None
1436
+
1437
+ self.patch = FancyBboxPatch( # frame
1438
+ xy=(0.0, 0.0), width=1., height=1.,
1439
+ facecolor='w', edgecolor='k',
1440
+ mutation_scale=self.prop.get_size_in_points(),
1441
+ snap=True,
1442
+ visible=frameon,
1443
+ )
1444
+ self.patch.set_boxstyle("square", pad=pad)
1445
+ if bboxprops:
1446
+ self.patch.set(**bboxprops)
1447
+
1448
+ self._internal_update(kwargs)
1449
+
1450
+ @property
1451
+ def xyann(self):
1452
+ return self.xybox
1453
+
1454
+ @xyann.setter
1455
+ def xyann(self, xyann):
1456
+ self.xybox = xyann
1457
+ self.stale = True
1458
+
1459
+ @property
1460
+ def anncoords(self):
1461
+ return self.boxcoords
1462
+
1463
+ @anncoords.setter
1464
+ def anncoords(self, coords):
1465
+ self.boxcoords = coords
1466
+ self.stale = True
1467
+
1468
+ def contains(self, mouseevent):
1469
+ if self._different_canvas(mouseevent):
1470
+ return False, {}
1471
+ if not self._check_xy(None):
1472
+ return False, {}
1473
+ return self.offsetbox.contains(mouseevent)
1474
+ # self.arrow_patch is currently not checked as this can be a line - JJ
1475
+
1476
+ def get_children(self):
1477
+ children = [self.offsetbox, self.patch]
1478
+ if self.arrow_patch:
1479
+ children.append(self.arrow_patch)
1480
+ return children
1481
+
1482
+ def set_figure(self, fig):
1483
+ if self.arrow_patch is not None:
1484
+ self.arrow_patch.set_figure(fig)
1485
+ self.offsetbox.set_figure(fig)
1486
+ martist.Artist.set_figure(self, fig)
1487
+
1488
+ def set_fontsize(self, s=None):
1489
+ """
1490
+ Set the fontsize in points.
1491
+
1492
+ If *s* is not given, reset to :rc:`legend.fontsize`.
1493
+ """
1494
+ s = mpl._val_or_rc(s, "legend.fontsize")
1495
+ self.prop = FontProperties(size=s)
1496
+ self.stale = True
1497
+
1498
+ def get_fontsize(self):
1499
+ """Return the fontsize in points."""
1500
+ return self.prop.get_size_in_points()
1501
+
1502
+ def get_window_extent(self, renderer=None):
1503
+ # docstring inherited
1504
+ if renderer is None:
1505
+ renderer = self.get_figure(root=True)._get_renderer()
1506
+ self.update_positions(renderer)
1507
+ return Bbox.union([child.get_window_extent(renderer)
1508
+ for child in self.get_children()])
1509
+
1510
+ def get_tightbbox(self, renderer=None):
1511
+ # docstring inherited
1512
+ if renderer is None:
1513
+ renderer = self.get_figure(root=True)._get_renderer()
1514
+ self.update_positions(renderer)
1515
+ return Bbox.union([child.get_tightbbox(renderer)
1516
+ for child in self.get_children()])
1517
+
1518
+ def update_positions(self, renderer):
1519
+ """Update pixel positions for the annotated point, the text, and the arrow."""
1520
+
1521
+ ox0, oy0 = self._get_xy(renderer, self.xybox, self.boxcoords)
1522
+ bbox = self.offsetbox.get_bbox(renderer)
1523
+ fw, fh = self._box_alignment
1524
+ self.offsetbox.set_offset(
1525
+ (ox0 - fw*bbox.width - bbox.x0, oy0 - fh*bbox.height - bbox.y0))
1526
+
1527
+ bbox = self.offsetbox.get_window_extent(renderer)
1528
+ self.patch.set_bounds(bbox.bounds)
1529
+
1530
+ mutation_scale = renderer.points_to_pixels(self.get_fontsize())
1531
+ self.patch.set_mutation_scale(mutation_scale)
1532
+
1533
+ if self.arrowprops:
1534
+ # Use FancyArrowPatch if self.arrowprops has "arrowstyle" key.
1535
+
1536
+ # Adjust the starting point of the arrow relative to the textbox.
1537
+ # TODO: Rotation needs to be accounted.
1538
+ arrow_begin = bbox.p0 + bbox.size * self._arrow_relpos
1539
+ arrow_end = self._get_position_xy(renderer)
1540
+ # The arrow (from arrow_begin to arrow_end) will be first clipped
1541
+ # by patchA and patchB, then shrunk by shrinkA and shrinkB (in
1542
+ # points). If patch A is not set, self.bbox_patch is used.
1543
+ self.arrow_patch.set_positions(arrow_begin, arrow_end)
1544
+
1545
+ if "mutation_scale" in self.arrowprops:
1546
+ mutation_scale = renderer.points_to_pixels(
1547
+ self.arrowprops["mutation_scale"])
1548
+ # Else, use fontsize-based mutation_scale defined above.
1549
+ self.arrow_patch.set_mutation_scale(mutation_scale)
1550
+
1551
+ patchA = self.arrowprops.get("patchA", self.patch)
1552
+ self.arrow_patch.set_patchA(patchA)
1553
+
1554
+ def draw(self, renderer):
1555
+ # docstring inherited
1556
+ if not self.get_visible() or not self._check_xy(renderer):
1557
+ return
1558
+ renderer.open_group(self.__class__.__name__, gid=self.get_gid())
1559
+ self.update_positions(renderer)
1560
+ if self.arrow_patch is not None:
1561
+ if (self.arrow_patch.get_figure(root=False) is None and
1562
+ (fig := self.get_figure(root=False)) is not None):
1563
+ self.arrow_patch.set_figure(fig)
1564
+ self.arrow_patch.draw(renderer)
1565
+ self.patch.draw(renderer)
1566
+ self.offsetbox.draw(renderer)
1567
+ renderer.close_group(self.__class__.__name__)
1568
+ self.stale = False
1569
+
1570
+
1571
+ class DraggableBase:
1572
+ """
1573
+ Helper base class for a draggable artist (legend, offsetbox).
1574
+
1575
+ Derived classes must override the following methods::
1576
+
1577
+ def save_offset(self):
1578
+ '''
1579
+ Called when the object is picked for dragging; should save the
1580
+ reference position of the artist.
1581
+ '''
1582
+
1583
+ def update_offset(self, dx, dy):
1584
+ '''
1585
+ Called during the dragging; (*dx*, *dy*) is the pixel offset from
1586
+ the point where the mouse drag started.
1587
+ '''
1588
+
1589
+ Optionally, you may override the following method::
1590
+
1591
+ def finalize_offset(self):
1592
+ '''Called when the mouse is released.'''
1593
+
1594
+ In the current implementation of `.DraggableLegend` and
1595
+ `DraggableAnnotation`, `update_offset` places the artists in display
1596
+ coordinates, and `finalize_offset` recalculates their position in axes
1597
+ coordinate and set a relevant attribute.
1598
+ """
1599
+
1600
+ def __init__(self, ref_artist, use_blit=False):
1601
+ self.ref_artist = ref_artist
1602
+ if not ref_artist.pickable():
1603
+ ref_artist.set_picker(self._picker)
1604
+ self.got_artist = False
1605
+ self._use_blit = use_blit and self.canvas.supports_blit
1606
+ callbacks = self.canvas.callbacks
1607
+ self._disconnectors = [
1608
+ functools.partial(
1609
+ callbacks.disconnect, callbacks._connect_picklable(name, func))
1610
+ for name, func in [
1611
+ ("pick_event", self.on_pick),
1612
+ ("button_release_event", self.on_release),
1613
+ ("motion_notify_event", self.on_motion),
1614
+ ]
1615
+ ]
1616
+
1617
+ @staticmethod
1618
+ def _picker(artist, mouseevent):
1619
+ # A custom picker to prevent dragging on mouse scroll events
1620
+ if mouseevent.name == "scroll_event":
1621
+ return False, {}
1622
+ return artist.contains(mouseevent)
1623
+
1624
+ # A property, not an attribute, to maintain picklability.
1625
+ canvas = property(lambda self: self.ref_artist.get_figure(root=True).canvas)
1626
+ cids = property(lambda self: [
1627
+ disconnect.args[0] for disconnect in self._disconnectors[:2]])
1628
+
1629
+ def on_motion(self, evt):
1630
+ if self._check_still_parented() and self.got_artist:
1631
+ dx = evt.x - self.mouse_x
1632
+ dy = evt.y - self.mouse_y
1633
+ self.update_offset(dx, dy)
1634
+ if self._use_blit:
1635
+ self.canvas.restore_region(self.background)
1636
+ self.ref_artist.draw(
1637
+ self.ref_artist.get_figure(root=True)._get_renderer())
1638
+ self.canvas.blit()
1639
+ else:
1640
+ self.canvas.draw()
1641
+
1642
+ def on_pick(self, evt):
1643
+ if self._check_still_parented():
1644
+ if evt.artist == self.ref_artist:
1645
+ self.mouse_x = evt.mouseevent.x
1646
+ self.mouse_y = evt.mouseevent.y
1647
+ self.save_offset()
1648
+ self.got_artist = True
1649
+ if self.got_artist and self._use_blit:
1650
+ self.ref_artist.set_animated(True)
1651
+ self.canvas.draw()
1652
+ fig = self.ref_artist.get_figure(root=False)
1653
+ self.background = self.canvas.copy_from_bbox(fig.bbox)
1654
+ self.ref_artist.draw(fig._get_renderer())
1655
+ self.canvas.blit()
1656
+
1657
+ def on_release(self, event):
1658
+ if self._check_still_parented() and self.got_artist:
1659
+ self.finalize_offset()
1660
+ self.got_artist = False
1661
+ if self._use_blit:
1662
+ self.canvas.restore_region(self.background)
1663
+ self.ref_artist.draw(self.ref_artist.figure._get_renderer())
1664
+ self.canvas.blit()
1665
+ self.ref_artist.set_animated(False)
1666
+
1667
+ def _check_still_parented(self):
1668
+ if self.ref_artist.get_figure(root=False) is None:
1669
+ self.disconnect()
1670
+ return False
1671
+ else:
1672
+ return True
1673
+
1674
+ def disconnect(self):
1675
+ """Disconnect the callbacks."""
1676
+ for disconnector in self._disconnectors:
1677
+ disconnector()
1678
+
1679
+ def save_offset(self):
1680
+ pass
1681
+
1682
+ def update_offset(self, dx, dy):
1683
+ pass
1684
+
1685
+ def finalize_offset(self):
1686
+ pass
1687
+
1688
+
1689
+ class DraggableOffsetBox(DraggableBase):
1690
+ def __init__(self, ref_artist, offsetbox, use_blit=False):
1691
+ super().__init__(ref_artist, use_blit=use_blit)
1692
+ self.offsetbox = offsetbox
1693
+
1694
+ def save_offset(self):
1695
+ offsetbox = self.offsetbox
1696
+ renderer = offsetbox.get_figure(root=True)._get_renderer()
1697
+ offset = offsetbox.get_offset(offsetbox.get_bbox(renderer), renderer)
1698
+ self.offsetbox_x, self.offsetbox_y = offset
1699
+ self.offsetbox.set_offset(offset)
1700
+
1701
+ def update_offset(self, dx, dy):
1702
+ loc_in_canvas = self.offsetbox_x + dx, self.offsetbox_y + dy
1703
+ self.offsetbox.set_offset(loc_in_canvas)
1704
+
1705
+ def get_loc_in_canvas(self):
1706
+ offsetbox = self.offsetbox
1707
+ renderer = offsetbox.get_figure(root=True)._get_renderer()
1708
+ bbox = offsetbox.get_bbox(renderer)
1709
+ ox, oy = offsetbox._offset
1710
+ loc_in_canvas = (ox + bbox.x0, oy + bbox.y0)
1711
+ return loc_in_canvas
1712
+
1713
+
1714
+ class DraggableAnnotation(DraggableBase):
1715
+ def __init__(self, annotation, use_blit=False):
1716
+ super().__init__(annotation, use_blit=use_blit)
1717
+ self.annotation = annotation
1718
+
1719
+ def save_offset(self):
1720
+ ann = self.annotation
1721
+ self.ox, self.oy = ann.get_transform().transform(ann.xyann)
1722
+
1723
+ def update_offset(self, dx, dy):
1724
+ ann = self.annotation
1725
+ ann.xyann = ann.get_transform().inverted().transform(
1726
+ (self.ox + dx, self.oy + dy))