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,2991 @@
1
+ # Vendored from matplotlib 3.11 (see licenses/LICENSE_MATPLOTLIB), adapted for matplotlib_rs.
2
+ """
3
+ Classes for the ticks and x- and y-axis.
4
+ """
5
+
6
+ import datetime
7
+ import functools
8
+ import logging
9
+ from numbers import Real
10
+ import warnings
11
+
12
+ import numpy as np
13
+
14
+ import matplotlib_rs as mpl
15
+ from matplotlib_rs import _api, cbook
16
+ import matplotlib_rs.artist as martist
17
+ import matplotlib_rs.colors as mcolors
18
+ import matplotlib_rs.lines as mlines
19
+ import matplotlib_rs.scale as mscale
20
+ import matplotlib_rs.text as mtext
21
+ import matplotlib_rs.ticker as mticker
22
+ import matplotlib_rs.transforms as mtransforms
23
+ import matplotlib_rs.units as munits
24
+ from matplotlib_rs.ticker import NullLocator
25
+
26
+ _log = logging.getLogger(__name__)
27
+
28
+ GRIDLINE_INTERPOLATION_STEPS = 180
29
+
30
+ # This list is being used for compatibility with Axes.grid, which
31
+ # allows all Line2D kwargs.
32
+ _line_inspector = martist.ArtistInspector(mlines.Line2D)
33
+ _line_param_names = _line_inspector.get_setters()
34
+ _line_param_aliases = [next(iter(d)) for d in _line_inspector.aliasd.values()]
35
+ _gridline_param_names = ['grid_' + name
36
+ for name in _line_param_names + _line_param_aliases]
37
+
38
+
39
+ class Tick(martist.Artist):
40
+ """
41
+ Abstract base class for the axis ticks, grid lines and labels.
42
+
43
+ Ticks mark a position on an Axis. They contain two lines as markers and
44
+ two labels; one each for the bottom and top positions (in case of an
45
+ `.XAxis`) or for the left and right positions (in case of a `.YAxis`).
46
+
47
+ Attributes
48
+ ----------
49
+ tick1line : `~matplotlib.lines.Line2D`
50
+ The left/bottom tick marker.
51
+ tick2line : `~matplotlib.lines.Line2D`
52
+ The right/top tick marker.
53
+ gridline : `~matplotlib.lines.Line2D`
54
+ The grid line associated with the label position.
55
+ label1 : `~matplotlib.text.Text`
56
+ The left/bottom tick label.
57
+ label2 : `~matplotlib.text.Text`
58
+ The right/top tick label.
59
+
60
+ Notes
61
+ -----
62
+ Ticks are managed though the autoscaling / view limit mechanism and therefore
63
+ need very careful handling when explicitly accessed, see :ref:`axes-tick-objects`.
64
+
65
+ The tick lines are implemented as `~matplotlib.lines.Line2D` instances using the
66
+ `~.matplotlib.markers` TICKLEFT, TICKRIGHT, TICKDOWN, TICKUP. Therefore,
67
+ properties are controlled via the marker, e.g. for the color
68
+ `.Line2D.set_markeredgecolor` and not `.Line2D.set_color`.
69
+ """
70
+ def __init__(
71
+ self, axes, loc, *,
72
+ size=None, # points
73
+ width=None,
74
+ color=None,
75
+ tickdir=None,
76
+ pad=None,
77
+ labelsize=None,
78
+ labelcolor=None,
79
+ labelfontfamily=None,
80
+ zorder=None,
81
+ gridOn=None, # defaults to axes.grid depending on axes.grid.which
82
+ tick1On=True,
83
+ tick2On=True,
84
+ label1On=True,
85
+ label2On=False,
86
+ major=True,
87
+ labelrotation=0,
88
+ labelrotation_mode=None,
89
+ grid_color=None,
90
+ grid_linestyle=None,
91
+ grid_linewidth=None,
92
+ grid_alpha=None,
93
+ **kwargs, # Other Line2D kwargs applied to gridlines.
94
+ ):
95
+ """
96
+ Parameters
97
+ ----------
98
+ loc
99
+ The tick location in data coords.
100
+ size
101
+ The tick size in points.
102
+ """
103
+ super().__init__()
104
+
105
+ if gridOn is None:
106
+ which = mpl.rcParams['axes.grid.which']
107
+ if major and which in ('both', 'major'):
108
+ gridOn = mpl.rcParams['axes.grid']
109
+ elif not major and which in ('both', 'minor'):
110
+ gridOn = mpl.rcParams['axes.grid']
111
+ else:
112
+ gridOn = False
113
+
114
+ self.set_figure(axes.get_figure(root=False))
115
+ self.axes = axes
116
+
117
+ self._loc = loc
118
+ self._major = major
119
+
120
+ name = self.__name__
121
+ major_minor = "major" if major else "minor"
122
+ self._size = mpl._val_or_rc(size, f"{name}.{major_minor}.size")
123
+ self._width = mpl._val_or_rc(width, f"{name}.{major_minor}.width")
124
+ self._base_pad = mpl._val_or_rc(pad, f"{name}.{major_minor}.pad")
125
+ color = mpl._val_or_rc(color, f"{name}.color")
126
+ labelcolor = mpl._val_or_rc(labelcolor, f"{name}.labelcolor")
127
+ if cbook._str_equal(labelcolor, 'inherit'):
128
+ # inherit from tick color
129
+ labelcolor = mpl.rcParams[f"{name}.color"]
130
+ labelsize = mpl._val_or_rc(labelsize, f"{name}.labelsize")
131
+
132
+ self._set_labelrotation(labelrotation)
133
+
134
+ if zorder is None:
135
+ if major:
136
+ zorder = mlines.Line2D.zorder + 0.01
137
+ else:
138
+ zorder = mlines.Line2D.zorder
139
+ self._zorder = zorder
140
+
141
+ grid_color = mpl._val_or_rc(
142
+ grid_color,
143
+ f"grid.{major_minor}.color",
144
+ "grid.color",
145
+ )
146
+ grid_linestyle = mpl._val_or_rc(
147
+ grid_linestyle,
148
+ f"grid.{major_minor}.linestyle",
149
+ "grid.linestyle",
150
+ )
151
+ grid_linewidth = mpl._val_or_rc(
152
+ grid_linewidth,
153
+ f"grid.{major_minor}.linewidth",
154
+ "grid.linewidth",
155
+ )
156
+ if grid_alpha is None:
157
+ if mcolors._has_alpha_channel(grid_color):
158
+ # Extract alpha from the color
159
+ # alpha precedence: kwarg > color alpha > rcParams['grid.alpha']
160
+ rgba = mcolors.to_rgba(grid_color)
161
+ grid_color = rgba[:3] # RGB only
162
+ grid_alpha = rgba[3] # Alpha from color
163
+ else:
164
+ # No alpha in color, use rcParams
165
+ grid_alpha = mpl._val_or_rc(
166
+ # grid_alpha is None so we can use the first key
167
+ mpl.rcParams[f"grid.{major_minor}.alpha"],
168
+ "grid.alpha",
169
+ )
170
+
171
+ grid_kw = {k[5:]: v for k, v in kwargs.items() if k != "rotation_mode"}
172
+
173
+ self.tick1line = mlines.Line2D(
174
+ [], [],
175
+ color=color, linestyle="none", zorder=zorder, visible=tick1On,
176
+ markeredgecolor=color, markersize=self._size, markeredgewidth=self._width,
177
+ )
178
+ self.tick2line = mlines.Line2D(
179
+ [], [],
180
+ color=color, linestyle="none", zorder=zorder, visible=tick2On,
181
+ markeredgecolor=color, markersize=self._size, markeredgewidth=self._width,
182
+ )
183
+ self.gridline = mlines.Line2D(
184
+ [], [],
185
+ color=grid_color, alpha=grid_alpha, visible=gridOn,
186
+ linestyle=grid_linestyle, linewidth=grid_linewidth, marker="",
187
+ **grid_kw,
188
+ )
189
+ self.gridline.get_path()._interpolation_steps = \
190
+ GRIDLINE_INTERPOLATION_STEPS
191
+ self.label1 = mtext.Text(
192
+ np.nan, np.nan,
193
+ fontsize=labelsize, color=labelcolor, visible=label1On,
194
+ fontfamily=labelfontfamily, rotation=self._labelrotation[1],
195
+ rotation_mode=labelrotation_mode)
196
+ self.label2 = mtext.Text(
197
+ np.nan, np.nan,
198
+ fontsize=labelsize, color=labelcolor, visible=label2On,
199
+ fontfamily=labelfontfamily, rotation=self._labelrotation[1],
200
+ rotation_mode=labelrotation_mode)
201
+
202
+ self._apply_tickdir(tickdir)
203
+
204
+ for artist in [self.tick1line, self.tick2line, self.gridline,
205
+ self.label1, self.label2]:
206
+ self._set_artist_props(artist)
207
+
208
+ self.update_position(loc)
209
+
210
+ def _set_labelrotation(self, labelrotation):
211
+ if isinstance(labelrotation, str):
212
+ mode = labelrotation
213
+ angle = 0
214
+ elif isinstance(labelrotation, (tuple, list)):
215
+ mode, angle = labelrotation
216
+ else:
217
+ mode = 'default'
218
+ angle = labelrotation
219
+ _api.check_in_list(['auto', 'default'], labelrotation=mode)
220
+ self._labelrotation = (mode, angle)
221
+
222
+ @property
223
+ def _pad(self):
224
+ return self._base_pad + self.get_tick_padding()
225
+
226
+ def _apply_tickdir(self, tickdir):
227
+ """Set tick direction. Valid values are 'out', 'in', 'inout'."""
228
+ # This method is responsible for verifying input and, in subclasses, for setting
229
+ # the tick{1,2}line markers. From the user perspective this should always be
230
+ # called through _apply_params, which further updates ticklabel positions using
231
+ # the new pads.
232
+ tickdir = mpl._val_or_rc(tickdir, f'{self.__name__}.direction')
233
+ _api.check_in_list(['in', 'out', 'inout'], tickdir=tickdir)
234
+ self._tickdir = tickdir
235
+
236
+ def get_tickdir(self):
237
+ return self._tickdir
238
+
239
+ def get_tick_padding(self):
240
+ """Get the length of the tick outside of the Axes."""
241
+ padding = {
242
+ 'in': 0.0,
243
+ 'inout': 0.5,
244
+ 'out': 1.0
245
+ }
246
+ return self._size * padding[self._tickdir]
247
+
248
+ def get_children(self):
249
+ children = [self.tick1line, self.tick2line,
250
+ self.gridline, self.label1, self.label2]
251
+ return children
252
+
253
+ def set_clip_path(self, path, transform=None):
254
+ # docstring inherited
255
+ super().set_clip_path(path, transform)
256
+ self.gridline.set_clip_path(path, transform)
257
+ self.stale = True
258
+
259
+ def contains(self, mouseevent):
260
+ """
261
+ Test whether the mouse event occurred in the Tick marks.
262
+
263
+ This function always returns false. It is more useful to test if the
264
+ axis as a whole contains the mouse rather than the set of tick marks.
265
+ """
266
+ return False, {}
267
+
268
+ def set_pad(self, val):
269
+ """
270
+ Set the tick label pad in points
271
+
272
+ Parameters
273
+ ----------
274
+ val : float
275
+ """
276
+ self._apply_params(pad=val)
277
+ self.stale = True
278
+
279
+ def get_pad(self):
280
+ """Get the value of the tick label pad in points."""
281
+ return self._base_pad
282
+
283
+ def get_loc(self):
284
+ """Return the tick location (data coords) as a scalar."""
285
+ return self._loc
286
+
287
+ @martist.allow_rasterization
288
+ def draw(self, renderer):
289
+ if not self.get_visible():
290
+ self.stale = False
291
+ return
292
+ renderer.open_group(self.__name__, gid=self.get_gid())
293
+ for artist in [self.gridline, self.tick1line, self.tick2line,
294
+ self.label1, self.label2]:
295
+ artist.draw(renderer)
296
+ renderer.close_group(self.__name__)
297
+ self.stale = False
298
+
299
+ def set_url(self, url):
300
+ """
301
+ Set the url of label1 and label2.
302
+
303
+ Parameters
304
+ ----------
305
+ url : str
306
+ """
307
+ super().set_url(url)
308
+ self.label1.set_url(url)
309
+ self.label2.set_url(url)
310
+ self.stale = True
311
+
312
+ def _set_artist_props(self, a):
313
+ a.set_figure(self.get_figure(root=False))
314
+
315
+ def get_view_interval(self):
316
+ """
317
+ Return the view limits ``(min, max)`` of the axis the tick belongs to.
318
+ """
319
+ raise NotImplementedError('Derived must override')
320
+
321
+ def _apply_params(self, **kwargs):
322
+ for name, target in [("gridOn", self.gridline),
323
+ ("tick1On", self.tick1line),
324
+ ("tick2On", self.tick2line),
325
+ ("label1On", self.label1),
326
+ ("label2On", self.label2)]:
327
+ if name in kwargs:
328
+ target.set_visible(kwargs.pop(name))
329
+ if any(k in kwargs for k in ['size', 'width', 'pad', 'tickdir']):
330
+ self._size = kwargs.pop('size', self._size)
331
+ # Width could be handled outside this block, but it is
332
+ # convenient to leave it here.
333
+ self._width = kwargs.pop('width', self._width)
334
+ self._base_pad = kwargs.pop('pad', self._base_pad)
335
+ # _apply_tickdir uses _size and _base_pad to make _pad, and also
336
+ # sets the ticklines markers.
337
+ self._apply_tickdir(kwargs.pop('tickdir', self._tickdir))
338
+ for line in (self.tick1line, self.tick2line):
339
+ line.set_markersize(self._size)
340
+ line.set_markeredgewidth(self._width)
341
+ # _get_text1_transform uses _pad from _apply_tickdir.
342
+ trans = self._get_text1_transform()[0]
343
+ self.label1.set_transform(trans)
344
+ trans = self._get_text2_transform()[0]
345
+ self.label2.set_transform(trans)
346
+ tick_kw = {k: v for k, v in kwargs.items() if k in ['color', 'zorder']}
347
+ if 'color' in kwargs:
348
+ tick_kw['markeredgecolor'] = kwargs['color']
349
+ self.tick1line.set(**tick_kw)
350
+ self.tick2line.set(**tick_kw)
351
+ for k, v in tick_kw.items():
352
+ setattr(self, '_' + k, v)
353
+
354
+ if 'labelrotation' in kwargs:
355
+ self._set_labelrotation(kwargs.pop('labelrotation'))
356
+ self.label1.set(rotation=self._labelrotation[1])
357
+ self.label2.set(rotation=self._labelrotation[1])
358
+
359
+ label_kw = {k[5:]: v for k, v in kwargs.items()
360
+ if k in ['labelsize', 'labelcolor', 'labelfontfamily',
361
+ 'labelrotation_mode']}
362
+ self.label1.set(**label_kw)
363
+ self.label2.set(**label_kw)
364
+
365
+ grid_kw = {k[5:]: v for k, v in kwargs.items()
366
+ if k in _gridline_param_names}
367
+ # If grid_color has an alpha channel and grid_alpha is not explicitly
368
+ # set, extract the alpha from the color.
369
+ if 'color' in grid_kw and 'alpha' not in grid_kw:
370
+ grid_color = grid_kw['color']
371
+ if mcolors._has_alpha_channel(grid_color):
372
+ # Convert to rgba to extract alpha
373
+ rgba = mcolors.to_rgba(grid_color)
374
+ grid_kw['color'] = rgba[:3] # RGB only
375
+ grid_kw['alpha'] = rgba[3] # Alpha channel
376
+ self.gridline.set(**grid_kw)
377
+
378
+ def update_position(self, loc):
379
+ """Set the location of tick in data coords with scalar *loc*."""
380
+ raise NotImplementedError('Derived must override')
381
+
382
+ def _get_text1_transform(self):
383
+ raise NotImplementedError('Derived must override')
384
+
385
+ def _get_text2_transform(self):
386
+ raise NotImplementedError('Derived must override')
387
+
388
+
389
+ class XTick(Tick):
390
+ """
391
+ Contains all the Artists needed to make an x tick - the tick line,
392
+ the label text and the grid line
393
+ """
394
+ __name__ = 'xtick'
395
+
396
+ def __init__(self, *args, **kwargs):
397
+ super().__init__(*args, **kwargs)
398
+ # x in data coords, y in axes coords
399
+ ax = self.axes
400
+ self.tick1line.set(
401
+ data=([0], [0]), transform=ax.get_xaxis_transform("tick1"))
402
+ self.tick2line.set(
403
+ data=([0], [1]), transform=ax.get_xaxis_transform("tick2"))
404
+ self.gridline.set(
405
+ data=([0, 0], [0, 1]), transform=ax.get_xaxis_transform("grid"))
406
+ # the y loc is 3 points below the min of y axis
407
+ trans, va, ha = self._get_text1_transform()
408
+ self.label1.set(
409
+ x=0, y=0,
410
+ verticalalignment=va, horizontalalignment=ha, transform=trans,
411
+ )
412
+ trans, va, ha = self._get_text2_transform()
413
+ self.label2.set(
414
+ x=0, y=1,
415
+ verticalalignment=va, horizontalalignment=ha, transform=trans,
416
+ )
417
+
418
+ def _get_text1_transform(self):
419
+ return self.axes.get_xaxis_text1_transform(self._pad)
420
+
421
+ def _get_text2_transform(self):
422
+ return self.axes.get_xaxis_text2_transform(self._pad)
423
+
424
+ def _apply_tickdir(self, tickdir):
425
+ # docstring inherited
426
+ super()._apply_tickdir(tickdir)
427
+ mark1, mark2 = {
428
+ 'out': (mlines.TICKDOWN, mlines.TICKUP),
429
+ 'in': (mlines.TICKUP, mlines.TICKDOWN),
430
+ 'inout': ('|', '|'),
431
+ }[self._tickdir]
432
+ self.tick1line.set_marker(mark1)
433
+ self.tick2line.set_marker(mark2)
434
+
435
+ def update_position(self, loc):
436
+ """Set the location of tick in data coords with scalar *loc*."""
437
+ self.tick1line.set_xdata((loc,))
438
+ self.tick2line.set_xdata((loc,))
439
+ self.gridline.set_xdata((loc,))
440
+ self.label1.set_x(loc)
441
+ self.label2.set_x(loc)
442
+ self._loc = loc
443
+ self.stale = True
444
+
445
+ def get_view_interval(self):
446
+ # docstring inherited
447
+ return self.axes.viewLim.intervalx
448
+
449
+
450
+ class YTick(Tick):
451
+ """
452
+ Contains all the Artists needed to make a Y tick - the tick line,
453
+ the label text and the grid line
454
+ """
455
+ __name__ = 'ytick'
456
+
457
+ def __init__(self, *args, **kwargs):
458
+ super().__init__(*args, **kwargs)
459
+ # x in axes coords, y in data coords
460
+ ax = self.axes
461
+ self.tick1line.set(
462
+ data=([0], [0]), transform=ax.get_yaxis_transform("tick1"))
463
+ self.tick2line.set(
464
+ data=([1], [0]), transform=ax.get_yaxis_transform("tick2"))
465
+ self.gridline.set(
466
+ data=([0, 1], [0, 0]), transform=ax.get_yaxis_transform("grid"))
467
+ # the y loc is 3 points below the min of y axis
468
+ trans, va, ha = self._get_text1_transform()
469
+ self.label1.set(
470
+ x=0, y=0,
471
+ verticalalignment=va, horizontalalignment=ha, transform=trans,
472
+ )
473
+ trans, va, ha = self._get_text2_transform()
474
+ self.label2.set(
475
+ x=1, y=0,
476
+ verticalalignment=va, horizontalalignment=ha, transform=trans,
477
+ )
478
+
479
+ def _get_text1_transform(self):
480
+ return self.axes.get_yaxis_text1_transform(self._pad)
481
+
482
+ def _get_text2_transform(self):
483
+ return self.axes.get_yaxis_text2_transform(self._pad)
484
+
485
+ def _apply_tickdir(self, tickdir):
486
+ # docstring inherited
487
+ super()._apply_tickdir(tickdir)
488
+ mark1, mark2 = {
489
+ 'out': (mlines.TICKLEFT, mlines.TICKRIGHT),
490
+ 'in': (mlines.TICKRIGHT, mlines.TICKLEFT),
491
+ 'inout': ('_', '_'),
492
+ }[self._tickdir]
493
+ self.tick1line.set_marker(mark1)
494
+ self.tick2line.set_marker(mark2)
495
+
496
+ def update_position(self, loc):
497
+ """Set the location of tick in data coords with scalar *loc*."""
498
+ self.tick1line.set_ydata((loc,))
499
+ self.tick2line.set_ydata((loc,))
500
+ self.gridline.set_ydata((loc,))
501
+ self.label1.set_y(loc)
502
+ self.label2.set_y(loc)
503
+ self._loc = loc
504
+ self.stale = True
505
+
506
+ def get_view_interval(self):
507
+ # docstring inherited
508
+ return self.axes.viewLim.intervaly
509
+
510
+
511
+ class Ticker:
512
+ """
513
+ A container for the objects defining tick position and format.
514
+
515
+ Attributes
516
+ ----------
517
+ locator : `~matplotlib.ticker.Locator` subclass
518
+ Determines the positions of the ticks.
519
+ formatter : `~matplotlib.ticker.Formatter` subclass
520
+ Determines the format of the tick labels.
521
+ """
522
+
523
+ def __init__(self):
524
+ self._locator = None
525
+ self._formatter = None
526
+ self._locator_is_default = True
527
+ self._formatter_is_default = True
528
+
529
+ @property
530
+ def locator(self):
531
+ return self._locator
532
+
533
+ @locator.setter
534
+ def locator(self, locator):
535
+ if not isinstance(locator, mticker.Locator):
536
+ raise TypeError('locator must be a subclass of '
537
+ 'matplotlib.ticker.Locator')
538
+ self._locator = locator
539
+
540
+ @property
541
+ def formatter(self):
542
+ return self._formatter
543
+
544
+ @formatter.setter
545
+ def formatter(self, formatter):
546
+ if not isinstance(formatter, mticker.Formatter):
547
+ raise TypeError('formatter must be a subclass of '
548
+ 'matplotlib.ticker.Formatter')
549
+ self._formatter = formatter
550
+
551
+
552
+ class _LazyTickList:
553
+ """
554
+ A descriptor for lazy instantiation of tick lists.
555
+
556
+ See comment above definition of the ``majorTicks`` and ``minorTicks``
557
+ attributes.
558
+ """
559
+
560
+ def __init__(self, major):
561
+ self._major = major
562
+
563
+ def __get__(self, instance, owner):
564
+ if instance is None:
565
+ return self
566
+ else:
567
+ # instance._get_tick() can itself try to access the majorTicks
568
+ # attribute (e.g. in certain projection classes which override
569
+ # e.g. get_xaxis_text1_transform). In order to avoid infinite
570
+ # recursion, first set the majorTicks on the instance temporarily
571
+ # to an empty list. Then create the tick; note that _get_tick()
572
+ # may call reset_ticks(). Therefore, the final tick list is
573
+ # created and assigned afterwards.
574
+ if self._major:
575
+ instance.majorTicks = []
576
+ tick = instance._get_tick(major=True)
577
+ instance.majorTicks = [tick]
578
+ return instance.majorTicks
579
+ else:
580
+ instance.minorTicks = []
581
+ tick = instance._get_tick(major=False)
582
+ instance.minorTicks = [tick]
583
+ return instance.minorTicks
584
+
585
+
586
+ class Axis(martist.Artist):
587
+ """
588
+ Base class for `.XAxis` and `.YAxis`.
589
+
590
+ Attributes
591
+ ----------
592
+ isDefault_label : bool
593
+
594
+ axes : `~matplotlib.axes.Axes`
595
+ The `~.axes.Axes` to which the Axis belongs.
596
+ major : `~matplotlib.axis.Ticker`
597
+ Determines the major tick positions and their label format.
598
+ minor : `~matplotlib.axis.Ticker`
599
+ Determines the minor tick positions and their label format.
600
+ callbacks : `~matplotlib.cbook.CallbackRegistry`
601
+
602
+ label : `~matplotlib.text.Text`
603
+ The axis label.
604
+ labelpad : float
605
+ The distance between the axis label and the tick labels.
606
+ Defaults to :rc:`axes.labelpad`.
607
+ offsetText : `~matplotlib.text.Text`
608
+ A `.Text` object containing the data offset of the ticks (if any).
609
+ pickradius : float
610
+ The acceptance radius for containment tests. See also `.Axis.contains`.
611
+ majorTicks : list of `.Tick`
612
+ The major ticks.
613
+
614
+ .. warning::
615
+
616
+ Ticks are not guaranteed to be persistent. Various operations
617
+ can create, delete and modify the Tick instances. There is an
618
+ imminent risk that changes to individual ticks will not
619
+ survive if you work on the figure further (including also
620
+ panning/zooming on a displayed figure).
621
+
622
+ Working on the individual ticks is a method of last resort.
623
+ Use `.set_tick_params` instead if possible.
624
+
625
+ minorTicks : list of `.Tick`
626
+ The minor ticks.
627
+ """
628
+ OFFSETTEXTPAD = 3
629
+ # The class used in _get_tick() to create tick instances. Must either be
630
+ # overwritten in subclasses, or subclasses must reimplement _get_tick().
631
+ _tick_class = None
632
+ converter = _api.deprecate_privatize_attribute(
633
+ "3.10",
634
+ alternative="get_converter and set_converter methods"
635
+ )
636
+
637
+ def __str__(self):
638
+ return "{}({},{})".format(
639
+ type(self).__name__, *self.axes.transAxes.transform((0, 0)))
640
+
641
+ def __init__(self, axes, *, pickradius=15, clear=True):
642
+ """
643
+ Parameters
644
+ ----------
645
+ axes : `~matplotlib.axes.Axes`
646
+ The `~.axes.Axes` to which the created Axis belongs.
647
+ pickradius : float
648
+ The acceptance radius for containment tests. See also
649
+ `.Axis.contains`.
650
+ clear : bool, default: True
651
+ Whether to clear the Axis on creation. This is not required, e.g., when
652
+ creating an Axis as part of an Axes, as ``Axes.clear`` will call
653
+ ``Axis.clear``.
654
+ .. versionadded:: 3.8
655
+ """
656
+ super().__init__()
657
+ self._remove_overlapping_locs = True
658
+
659
+ self.set_figure(axes.get_figure(root=False))
660
+
661
+ self.isDefault_label = True
662
+
663
+ self.axes = axes
664
+ self.major = Ticker()
665
+ self.minor = Ticker()
666
+ self.callbacks = cbook.CallbackRegistry(signals=["units"])
667
+
668
+ self._autolabelpos = True
669
+
670
+ self.label = mtext.Text(
671
+ np.nan, np.nan,
672
+ fontsize=mpl.rcParams['axes.labelsize'],
673
+ fontweight=mpl.rcParams['axes.labelweight'],
674
+ color=mpl.rcParams['axes.labelcolor'],
675
+ ) #: The `.Text` object of the axis label.
676
+
677
+ self._set_artist_props(self.label)
678
+ self.offsetText = mtext.Text(np.nan, np.nan)
679
+ self._set_artist_props(self.offsetText)
680
+
681
+ self.labelpad = mpl.rcParams['axes.labelpad']
682
+
683
+ self.pickradius = pickradius
684
+
685
+ # Initialize here for testing; later add API
686
+ self._major_tick_kw = dict()
687
+ self._minor_tick_kw = dict()
688
+
689
+ if clear:
690
+ self.clear()
691
+ else:
692
+ self._converter = None
693
+ self._converter_is_explicit = False
694
+ self.units = None
695
+
696
+ self._autoscale_on = True
697
+
698
+ @property
699
+ def isDefault_majloc(self):
700
+ return self.major._locator_is_default
701
+
702
+ @isDefault_majloc.setter
703
+ def isDefault_majloc(self, value):
704
+ self.major._locator_is_default = value
705
+
706
+ @property
707
+ def isDefault_majfmt(self):
708
+ return self.major._formatter_is_default
709
+
710
+ @isDefault_majfmt.setter
711
+ def isDefault_majfmt(self, value):
712
+ self.major._formatter_is_default = value
713
+
714
+ @property
715
+ def isDefault_minloc(self):
716
+ return self.minor._locator_is_default
717
+
718
+ @isDefault_minloc.setter
719
+ def isDefault_minloc(self, value):
720
+ self.minor._locator_is_default = value
721
+
722
+ @property
723
+ def isDefault_minfmt(self):
724
+ return self.minor._formatter_is_default
725
+
726
+ @isDefault_minfmt.setter
727
+ def isDefault_minfmt(self, value):
728
+ self.minor._formatter_is_default = value
729
+
730
+ def _get_shared_axes(self):
731
+ """Return a list of shared Axes for current axis."""
732
+ return self.axes._shared_axes[
733
+ self._get_axis_name()].get_siblings(self.axes)
734
+
735
+ def _get_shared_axis(self):
736
+ """Return list of shared axis for current axis."""
737
+ name = self._get_axis_name()
738
+ return [ax._axis_map[name] for ax in self._get_shared_axes()]
739
+
740
+ def _get_axis_name(self):
741
+ """Return the axis name."""
742
+ return next(name for name, axis in self.axes._axis_map.items()
743
+ if axis is self)
744
+
745
+ # During initialization, Axis objects often create ticks that are later
746
+ # unused; this turns out to be a very slow step. Instead, use a custom
747
+ # descriptor to make the tick lists lazy and instantiate them as needed.
748
+ majorTicks = _LazyTickList(major=True)
749
+ minorTicks = _LazyTickList(major=False)
750
+
751
+ def get_remove_overlapping_locs(self):
752
+ return self._remove_overlapping_locs
753
+
754
+ def set_remove_overlapping_locs(self, val):
755
+ self._remove_overlapping_locs = bool(val)
756
+
757
+ remove_overlapping_locs = property(
758
+ get_remove_overlapping_locs, set_remove_overlapping_locs,
759
+ doc=('If minor ticker locations that overlap with major '
760
+ 'ticker locations should be trimmed.'))
761
+
762
+ def set_label_coords(self, x, y, transform=None):
763
+ """
764
+ Set the coordinates of the label.
765
+
766
+ By default, the x coordinate of the y label and the y coordinate of the
767
+ x label are determined by the tick label bounding boxes, but this can
768
+ lead to poor alignment of multiple labels if there are multiple Axes.
769
+
770
+ You can also specify the coordinate system of the label with the
771
+ transform. If None, the default coordinate system will be the axes
772
+ coordinate system: (0, 0) is bottom left, (0.5, 0.5) is center, etc.
773
+ """
774
+ self._autolabelpos = False
775
+ if transform is None:
776
+ transform = self.axes.transAxes
777
+
778
+ self.label.set_transform(transform)
779
+ self.label.set_position((x, y))
780
+ self.stale = True
781
+
782
+ def get_transform(self):
783
+ """Return the transform used in the Axis' scale"""
784
+ return self._scale.get_transform()
785
+
786
+ def get_scale(self):
787
+ """Return this Axis' scale (as a str)."""
788
+ return self._scale.name
789
+
790
+ def _set_scale(self, value, **kwargs):
791
+ if not isinstance(value, mscale.ScaleBase):
792
+ self._scale = mscale.scale_factory(value, self, **kwargs)
793
+ else:
794
+ self._scale = value
795
+ self._scale.set_default_locators_and_formatters(self)
796
+
797
+ self.isDefault_majloc = True
798
+ self.isDefault_minloc = True
799
+ self.isDefault_majfmt = True
800
+ self.isDefault_minfmt = True
801
+
802
+ # This method is directly wrapped by Axes.set_{x,y}scale.
803
+ def _set_axes_scale(self, value, **kwargs):
804
+ """
805
+ Set this Axis' scale.
806
+
807
+ Parameters
808
+ ----------
809
+ value : str or `.ScaleBase`
810
+ The axis scale type to apply. Valid string values are the names of scale
811
+ classes ("linear", "log", "function",...). These may be the names of any
812
+ of the :ref:`built-in scales<builtin_scales>` or of any custom scales
813
+ registered using `matplotlib.scale.register_scale`.
814
+
815
+ **kwargs
816
+ If *value* is a string, keywords are passed to the instantiation method of
817
+ the respective class.
818
+ """
819
+ name = self._get_axis_name()
820
+ old_default_lims = (self.get_major_locator()
821
+ .nonsingular(-np.inf, np.inf))
822
+ for ax in self._get_shared_axes():
823
+ ax._axis_map[name]._set_scale(value, **kwargs)
824
+ ax._update_transScale()
825
+ ax.stale = True
826
+ new_default_lims = (self.get_major_locator()
827
+ .nonsingular(-np.inf, np.inf))
828
+ if old_default_lims != new_default_lims:
829
+ # Force autoscaling now, to take advantage of the scale locator's
830
+ # nonsingular() before it possibly gets swapped out by the user.
831
+ self.axes.autoscale_view(
832
+ **{f"scale{k}": k == name for k in self.axes._axis_names})
833
+
834
+ def limit_range_for_scale(self, vmin, vmax):
835
+ """
836
+ Return the range *vmin*, *vmax*, restricted to the domain supported by the
837
+ current scale.
838
+ """
839
+ return self._scale.limit_range_for_scale(vmin, vmax, self.get_minpos())
840
+
841
+ def _nan_out_of_scale_range(self, data):
842
+ """
843
+ Return *data* with values that are out of range for this axis's scale
844
+ replaced by NaN. E.g. ``<=0`` on a log axis.
845
+ """
846
+ data = np.asanyarray(data, dtype=float)
847
+ valid = self._scale.val_in_range(data)
848
+ return data if np.all(valid) else np.where(valid, data, np.nan)
849
+
850
+ def _get_autoscale_on(self):
851
+ """Return whether this Axis is autoscaled."""
852
+ return self._autoscale_on
853
+
854
+ def _set_autoscale_on(self, b):
855
+ """
856
+ Set whether this Axis is autoscaled when drawing or by `.Axes.autoscale_view`.
857
+
858
+ If b is None, then the value is not changed.
859
+
860
+ Parameters
861
+ ----------
862
+ b : bool
863
+
864
+ See Also
865
+ --------
866
+ matplotlib.axes.Axes.autoscale
867
+ matplotlib.axes.Axes.set_autoscale_on
868
+ matplotlib.axes.Axes.get_autoscalex_on
869
+ matplotlib.axes.Axes.set_autoscalex_on
870
+ matplotlib.axes.Axes.get_autoscaley_on
871
+ matplotlib.axes.Axes.set_autoscaley_on
872
+ """
873
+ if b is not None:
874
+ self._autoscale_on = b
875
+
876
+ def get_children(self):
877
+ return [self.label, self.offsetText,
878
+ *self.get_major_ticks(), *self.get_minor_ticks()]
879
+
880
+ def _reset_major_tick_kw(self):
881
+ self._major_tick_kw.clear()
882
+ self._major_tick_kw['gridOn'] = (
883
+ mpl.rcParams['axes.grid'] and
884
+ mpl.rcParams['axes.grid.which'] in ('both', 'major'))
885
+
886
+ def _reset_minor_tick_kw(self):
887
+ self._minor_tick_kw.clear()
888
+ self._minor_tick_kw['gridOn'] = (
889
+ mpl.rcParams['axes.grid'] and
890
+ mpl.rcParams['axes.grid.which'] in ('both', 'minor'))
891
+
892
+ def clear(self):
893
+ """
894
+ Clear the axis.
895
+
896
+ This resets axis properties to their default values:
897
+
898
+ - the label
899
+ - the scale
900
+ - locators, formatters and ticks
901
+ - major and minor grid
902
+ - units
903
+ - registered callbacks
904
+ """
905
+ self.label._reset_visual_defaults()
906
+ # The above resets the label formatting using text rcParams,
907
+ # so we then update the formatting using axes rcParams
908
+ self.label.set_color(mpl.rcParams['axes.labelcolor'])
909
+ self.label.set_fontsize(mpl.rcParams['axes.labelsize'])
910
+ self.label.set_fontweight(mpl.rcParams['axes.labelweight'])
911
+ self.offsetText._reset_visual_defaults()
912
+ self.labelpad = mpl.rcParams['axes.labelpad']
913
+
914
+ self._init()
915
+
916
+ self._set_scale('linear')
917
+
918
+ # Clear the callback registry for this axis, or it may "leak"
919
+ self.callbacks = cbook.CallbackRegistry(signals=["units"])
920
+
921
+ # whether the grids are on
922
+ self._major_tick_kw['gridOn'] = (
923
+ mpl.rcParams['axes.grid'] and
924
+ mpl.rcParams['axes.grid.which'] in ('both', 'major'))
925
+ self._minor_tick_kw['gridOn'] = (
926
+ mpl.rcParams['axes.grid'] and
927
+ mpl.rcParams['axes.grid.which'] in ('both', 'minor'))
928
+ self.reset_ticks()
929
+
930
+ self._converter = None
931
+ self._converter_is_explicit = False
932
+ self.units = None
933
+ self.stale = True
934
+
935
+ def reset_ticks(self):
936
+ """
937
+ Re-initialize the major and minor Tick lists.
938
+
939
+ Each list starts with a single fresh Tick.
940
+ """
941
+ # Restore the lazy tick lists.
942
+ try:
943
+ del self.majorTicks
944
+ except AttributeError:
945
+ pass
946
+ try:
947
+ del self.minorTicks
948
+ except AttributeError:
949
+ pass
950
+ try:
951
+ self.set_clip_path(self.axes.patch)
952
+ except AttributeError:
953
+ pass
954
+
955
+ def minorticks_on(self):
956
+ """
957
+ Display default minor ticks on the Axis, depending on the scale
958
+ (`~.axis.Axis.get_scale`).
959
+
960
+ Scales use specific minor locators:
961
+
962
+ - log: `~.LogLocator`
963
+ - symlog: `~.SymmetricalLogLocator`
964
+ - asinh: `~.AsinhLocator`
965
+ - logit: `~.LogitLocator`
966
+ - default: `~.AutoMinorLocator`
967
+
968
+ Displaying minor ticks may reduce performance; you may turn them off
969
+ using `minorticks_off()` if drawing speed is a problem.
970
+ """
971
+ scale = self.get_scale()
972
+ if scale == 'log':
973
+ s = self._scale
974
+ self.set_minor_locator(mticker.LogLocator(s.base, s.subs))
975
+ elif scale == 'symlog':
976
+ s = self._scale
977
+ self.set_minor_locator(
978
+ mticker.SymmetricalLogLocator(s._transform, s.subs))
979
+ elif scale == 'asinh':
980
+ s = self._scale
981
+ self.set_minor_locator(
982
+ mticker.AsinhLocator(s.linear_width, base=s._base,
983
+ subs=s._subs))
984
+ elif scale == 'logit':
985
+ self.set_minor_locator(mticker.LogitLocator(minor=True))
986
+ else:
987
+ self.set_minor_locator(mticker.AutoMinorLocator())
988
+
989
+ def minorticks_off(self):
990
+ """Remove minor ticks from the Axis."""
991
+ self.set_minor_locator(mticker.NullLocator())
992
+
993
+ def set_tick_params(self, which='major', reset=False, **kwargs):
994
+ """
995
+ Set appearance parameters for ticks, ticklabels, and gridlines.
996
+
997
+ For documentation of keyword arguments, see
998
+ :meth:`matplotlib.axes.Axes.tick_params`.
999
+
1000
+ See Also
1001
+ --------
1002
+ .Axis.get_tick_params
1003
+ View the current style settings for ticks, ticklabels, and
1004
+ gridlines.
1005
+ """
1006
+ _api.check_in_list(['major', 'minor', 'both'], which=which)
1007
+ kwtrans = self._translate_tick_params(kwargs)
1008
+
1009
+ # the kwargs are stored in self._major/minor_tick_kw so that any
1010
+ # future new ticks will automatically get them
1011
+ if reset:
1012
+ if which in ['major', 'both']:
1013
+ self._reset_major_tick_kw()
1014
+ self._major_tick_kw.update(kwtrans)
1015
+ if which in ['minor', 'both']:
1016
+ self._reset_minor_tick_kw()
1017
+ self._minor_tick_kw.update(kwtrans)
1018
+ self.reset_ticks()
1019
+ else:
1020
+ if which in ['major', 'both']:
1021
+ self._major_tick_kw.update(kwtrans)
1022
+ for tick in self.majorTicks:
1023
+ tick._apply_params(**kwtrans)
1024
+ if which in ['minor', 'both']:
1025
+ self._minor_tick_kw.update(kwtrans)
1026
+ for tick in self.minorTicks:
1027
+ tick._apply_params(**kwtrans)
1028
+ # labelOn and labelcolor also apply to the offset text.
1029
+ if 'label1On' in kwtrans or 'label2On' in kwtrans:
1030
+ self.offsetText.set_visible(
1031
+ self._major_tick_kw.get('label1On', False)
1032
+ or self._major_tick_kw.get('label2On', False))
1033
+ if 'labelcolor' in kwtrans:
1034
+ self.offsetText.set_color(kwtrans['labelcolor'])
1035
+
1036
+ self.stale = True
1037
+
1038
+ def get_tick_params(self, which='major'):
1039
+ """
1040
+ Get appearance parameters for ticks, ticklabels, and gridlines.
1041
+
1042
+ .. versionadded:: 3.7
1043
+
1044
+ Parameters
1045
+ ----------
1046
+ which : {'major', 'minor'}, default: 'major'
1047
+ The group of ticks for which the parameters are retrieved.
1048
+
1049
+ Returns
1050
+ -------
1051
+ dict
1052
+ Properties for styling tick elements added to the axis.
1053
+
1054
+ Notes
1055
+ -----
1056
+ This method returns the appearance parameters for styling *new*
1057
+ elements added to this axis and may be different from the values
1058
+ on current elements if they were modified directly by the user
1059
+ (e.g., via ``set_*`` methods on individual tick objects).
1060
+
1061
+ Examples
1062
+ --------
1063
+ ::
1064
+
1065
+ >>> ax.yaxis.set_tick_params(labelsize=30, labelcolor='red',
1066
+ ... direction='out', which='major')
1067
+ >>> ax.yaxis.get_tick_params(which='major')
1068
+ {'direction': 'out',
1069
+ 'left': True,
1070
+ 'right': False,
1071
+ 'labelleft': True,
1072
+ 'labelright': False,
1073
+ 'gridOn': False,
1074
+ 'labelsize': 30,
1075
+ 'labelcolor': 'red'}
1076
+ >>> ax.yaxis.get_tick_params(which='minor')
1077
+ {'left': True,
1078
+ 'right': False,
1079
+ 'labelleft': True,
1080
+ 'labelright': False,
1081
+ 'gridOn': False}
1082
+
1083
+
1084
+ """
1085
+ _api.check_in_list(['major', 'minor'], which=which)
1086
+ if which == 'major':
1087
+ return self._translate_tick_params(
1088
+ self._major_tick_kw, reverse=True
1089
+ )
1090
+ return self._translate_tick_params(self._minor_tick_kw, reverse=True)
1091
+
1092
+ @classmethod
1093
+ def _translate_tick_params(cls, kw, reverse=False):
1094
+ """
1095
+ Translate the kwargs supported by `.Axis.set_tick_params` to kwargs
1096
+ supported by `.Tick._apply_params`.
1097
+
1098
+ In particular, this maps axis specific names like 'top', 'left'
1099
+ to the generic tick1, tick2 logic of the axis. Additionally, there
1100
+ are some other name translations.
1101
+
1102
+ Returns a new dict of translated kwargs.
1103
+
1104
+ Note: Use reverse=True to translate from those supported by
1105
+ `.Tick._apply_params` back to those supported by
1106
+ `.Axis.set_tick_params`.
1107
+ """
1108
+ kw_ = {**kw}
1109
+
1110
+ # The following lists may be moved to a more accessible location.
1111
+ allowed_keys = [
1112
+ 'size', 'width', 'color', 'tickdir', 'pad',
1113
+ 'labelsize', 'labelcolor', 'labelfontfamily', 'zorder', 'gridOn',
1114
+ 'tick1On', 'tick2On', 'label1On', 'label2On',
1115
+ 'length', 'direction', 'left', 'bottom', 'right', 'top',
1116
+ 'labelleft', 'labelbottom', 'labelright', 'labeltop',
1117
+ 'labelrotation', 'labelrotation_mode',
1118
+ *_gridline_param_names]
1119
+
1120
+ keymap = {
1121
+ # tick_params key -> axis key
1122
+ 'length': 'size',
1123
+ 'direction': 'tickdir',
1124
+ 'rotation': 'labelrotation',
1125
+ 'rotation_mode': 'labelrotation_mode',
1126
+ 'left': 'tick1On',
1127
+ 'bottom': 'tick1On',
1128
+ 'right': 'tick2On',
1129
+ 'top': 'tick2On',
1130
+ 'labelleft': 'label1On',
1131
+ 'labelbottom': 'label1On',
1132
+ 'labelright': 'label2On',
1133
+ 'labeltop': 'label2On',
1134
+ }
1135
+ if reverse:
1136
+ kwtrans = {}
1137
+ is_x_axis = cls.axis_name == 'x'
1138
+ y_axis_keys = ['left', 'right', 'labelleft', 'labelright']
1139
+ for oldkey, newkey in keymap.items():
1140
+ if newkey in kw_:
1141
+ if is_x_axis and oldkey in y_axis_keys:
1142
+ continue
1143
+ else:
1144
+ kwtrans[oldkey] = kw_.pop(newkey)
1145
+ else:
1146
+ kwtrans = {
1147
+ newkey: kw_.pop(oldkey)
1148
+ for oldkey, newkey in keymap.items() if oldkey in kw_
1149
+ }
1150
+ if 'colors' in kw_:
1151
+ c = kw_.pop('colors')
1152
+ kwtrans['color'] = c
1153
+ kwtrans['labelcolor'] = c
1154
+ # Maybe move the checking up to the caller of this method.
1155
+ for key in kw_:
1156
+ if key not in allowed_keys:
1157
+ raise ValueError(
1158
+ "keyword %s is not recognized; valid keywords are %s"
1159
+ % (key, allowed_keys))
1160
+ kwtrans.update(kw_)
1161
+ return kwtrans
1162
+
1163
+ def set_clip_path(self, path, transform=None):
1164
+ super().set_clip_path(path, transform)
1165
+ for child in self.majorTicks + self.minorTicks:
1166
+ child.set_clip_path(path, transform)
1167
+ self.stale = True
1168
+
1169
+ def get_view_interval(self):
1170
+ """Return the ``(min, max)`` view limits of this axis."""
1171
+ raise NotImplementedError('Derived must override')
1172
+
1173
+ def set_view_interval(self, vmin, vmax, ignore=False):
1174
+ """
1175
+ Set the axis view limits. This method is for internal use; Matplotlib
1176
+ users should typically use e.g. `~.Axes.set_xlim` or `~.Axes.set_ylim`.
1177
+
1178
+ If *ignore* is False (the default), this method will never reduce the
1179
+ preexisting view limits, only expand them if *vmin* or *vmax* are not
1180
+ within them. Moreover, the order of *vmin* and *vmax* does not matter;
1181
+ the orientation of the axis will not change.
1182
+
1183
+ If *ignore* is True, the view limits will be set exactly to ``(vmin,
1184
+ vmax)`` in that order.
1185
+ """
1186
+ raise NotImplementedError('Derived must override')
1187
+
1188
+ def get_data_interval(self):
1189
+ """Return the ``(min, max)`` data limits of this axis."""
1190
+ raise NotImplementedError('Derived must override')
1191
+
1192
+ def set_data_interval(self, vmin, vmax, ignore=False):
1193
+ """
1194
+ Set the axis data limits. This method is for internal use.
1195
+
1196
+ If *ignore* is False (the default), this method will never reduce the
1197
+ preexisting data limits, only expand them if *vmin* or *vmax* are not
1198
+ within them. Moreover, the order of *vmin* and *vmax* does not matter;
1199
+ the orientation of the axis will not change.
1200
+
1201
+ If *ignore* is True, the data limits will be set exactly to ``(vmin,
1202
+ vmax)`` in that order.
1203
+ """
1204
+ raise NotImplementedError('Derived must override')
1205
+
1206
+ def get_inverted(self):
1207
+ """
1208
+ Return whether this Axis is oriented in the "inverse" direction.
1209
+
1210
+ The "normal" direction is increasing to the right for the x-axis and to
1211
+ the top for the y-axis; the "inverse" direction is increasing to the
1212
+ left for the x-axis and to the bottom for the y-axis.
1213
+ """
1214
+ low, high = self.get_view_interval()
1215
+ return high < low
1216
+
1217
+ def set_inverted(self, inverted):
1218
+ """
1219
+ Set whether this Axis is oriented in the "inverse" direction.
1220
+
1221
+ The "normal" direction is increasing to the right for the x-axis and to
1222
+ the top for the y-axis; the "inverse" direction is increasing to the
1223
+ left for the x-axis and to the bottom for the y-axis.
1224
+ """
1225
+ a, b = self.get_view_interval()
1226
+ # cast to bool to avoid bad interaction between python 3.8 and np.bool_
1227
+ self._set_lim(*sorted((a, b), reverse=bool(inverted)), auto=None)
1228
+
1229
+ def set_default_intervals(self):
1230
+ """
1231
+ Set the default limits for the axis data and view interval if they
1232
+ have not been not mutated yet.
1233
+ """
1234
+ # this is mainly in support of custom object plotting. For
1235
+ # example, if someone passes in a datetime object, we do not
1236
+ # know automagically how to set the default min/max of the
1237
+ # data and view limits. The unit conversion AxisInfo
1238
+ # interface provides a hook for custom types to register
1239
+ # default limits through the AxisInfo.default_limits
1240
+ # attribute, and the derived code below will check for that
1241
+ # and use it if it's available (else just use 0..1)
1242
+
1243
+ def _set_lim(self, v0, v1, *, emit=True, auto):
1244
+ """
1245
+ Set view limits.
1246
+
1247
+ This method is a helper for the Axes ``set_xlim``, ``set_ylim``, and
1248
+ ``set_zlim`` methods.
1249
+
1250
+ Parameters
1251
+ ----------
1252
+ v0, v1 : float
1253
+ The view limits. (Passing *v0* as a (low, high) pair is not
1254
+ supported; normalization must occur in the Axes setters.)
1255
+ emit : bool, default: True
1256
+ Whether to notify observers of limit change.
1257
+ auto : bool or None, default: False
1258
+ Whether to turn on autoscaling of the x-axis. True turns on, False
1259
+ turns off, None leaves unchanged.
1260
+ """
1261
+ name = self._get_axis_name()
1262
+
1263
+ self.axes._process_unit_info([(name, (v0, v1))], convert=False)
1264
+ v0 = self.axes._validate_converted_limits(v0, self.convert_units)
1265
+ v1 = self.axes._validate_converted_limits(v1, self.convert_units)
1266
+
1267
+ if v0 is None or v1 is None:
1268
+ # Axes init calls set_xlim(0, 1) before get_xlim() can be called,
1269
+ # so only grab the limits if we really need them.
1270
+ old0, old1 = self.get_view_interval()
1271
+ if v0 is None:
1272
+ v0 = old0
1273
+ if v1 is None:
1274
+ v1 = old1
1275
+
1276
+ if self.get_scale() == 'log' and (v0 <= 0 or v1 <= 0):
1277
+ # Axes init calls set_xlim(0, 1) before get_xlim() can be called,
1278
+ # so only grab the limits if we really need them.
1279
+ old0, old1 = self.get_view_interval()
1280
+ if v0 <= 0:
1281
+ _api.warn_external(f"Attempt to set non-positive {name}lim on "
1282
+ f"a log-scaled axis will be ignored.")
1283
+ v0 = old0
1284
+ if v1 <= 0:
1285
+ _api.warn_external(f"Attempt to set non-positive {name}lim on "
1286
+ f"a log-scaled axis will be ignored.")
1287
+ v1 = old1
1288
+ if v0 == v1:
1289
+ _api.warn_external(
1290
+ f"Attempting to set identical low and high {name}lims "
1291
+ f"makes transformation singular; automatically expanding.")
1292
+ reverse = bool(v0 > v1) # explicit cast needed for python3.8+np.bool_.
1293
+ v0, v1 = self.get_major_locator().nonsingular(v0, v1)
1294
+ v0, v1 = self.limit_range_for_scale(v0, v1)
1295
+ v0, v1 = sorted([v0, v1], reverse=bool(reverse))
1296
+
1297
+ self.set_view_interval(v0, v1, ignore=True)
1298
+ # Mark viewlims as no longer stale without triggering an autoscale.
1299
+ for ax in self._get_shared_axes():
1300
+ ax._stale_viewlims[name] = False
1301
+ self._set_autoscale_on(auto)
1302
+
1303
+ if emit:
1304
+ self.axes.callbacks.process(f"{name}lim_changed", self.axes)
1305
+ # Call all of the other Axes that are shared with this one
1306
+ for other in self._get_shared_axes():
1307
+ if other is self.axes:
1308
+ continue
1309
+ other._axis_map[name]._set_lim(v0, v1, emit=False, auto=auto)
1310
+ if emit:
1311
+ other.callbacks.process(f"{name}lim_changed", other)
1312
+ if ((other_fig := other.get_figure(root=False)) !=
1313
+ self.get_figure(root=False)):
1314
+ other_fig.canvas.draw_idle()
1315
+
1316
+ self.stale = True
1317
+ return v0, v1
1318
+
1319
+ def _set_artist_props(self, a):
1320
+ if a is None:
1321
+ return
1322
+ a.set_figure(self.get_figure(root=False))
1323
+
1324
+ @staticmethod
1325
+ def _tick_group_visible(kw):
1326
+ """
1327
+ Check if any of the tick group components are visible.
1328
+ Takes in self._major_tick_kw or self._minor_tick_kw.
1329
+ """
1330
+ return (kw.get('tick1On') is not False or
1331
+ kw.get('tick2On') is not False or
1332
+ kw.get('label1On') is not False or
1333
+ kw.get('label2On') is not False or
1334
+ kw.get('gridOn') is not False)
1335
+
1336
+ def _update_ticks(self):
1337
+ """
1338
+ Update ticks (position and labels) using the current data interval of
1339
+ the axes. Return the list of ticks that will be drawn.
1340
+ """
1341
+ # Check if major ticks should be computed.
1342
+ # Skip if using NullLocator or if all visible components are off.
1343
+ if (self._tick_group_visible(self._major_tick_kw)
1344
+ and not isinstance(self.get_major_locator(), NullLocator)):
1345
+ major_locs = self.get_majorticklocs()
1346
+ major_labels = self.major.formatter.format_ticks(major_locs)
1347
+ major_ticks = self.get_major_ticks(len(major_locs))
1348
+ for tick, loc, label in zip(major_ticks, major_locs, major_labels):
1349
+ tick.update_position(loc)
1350
+ tick.label1.set_text(label)
1351
+ tick.label2.set_text(label)
1352
+ else:
1353
+ major_ticks = []
1354
+
1355
+ # Check if minor ticks should be computed.
1356
+ if (self._tick_group_visible(self._minor_tick_kw)
1357
+ and not isinstance(self.get_minor_locator(), NullLocator)):
1358
+ minor_locs = self.get_minorticklocs()
1359
+ minor_labels = self.minor.formatter.format_ticks(minor_locs)
1360
+ minor_ticks = self.get_minor_ticks(len(minor_locs))
1361
+ for tick, loc, label in zip(minor_ticks, minor_locs, minor_labels):
1362
+ tick.update_position(loc)
1363
+ tick.label1.set_text(label)
1364
+ tick.label2.set_text(label)
1365
+ else:
1366
+ minor_ticks = []
1367
+
1368
+ ticks = [*major_ticks, *minor_ticks]
1369
+ if not ticks:
1370
+ return []
1371
+
1372
+ view_low, view_high = self.get_view_interval()
1373
+ if view_low > view_high:
1374
+ view_low, view_high = view_high, view_low
1375
+
1376
+ if (hasattr(self, "axes") and self.axes.name == '3d'
1377
+ and mpl.rcParams['axes3d.automargin']):
1378
+ # In mpl3.8, the margin was 1/48. Due to the change in automargin
1379
+ # behavior in mpl3.9, we need to adjust this to compensate for a
1380
+ # zoom factor of 2/48, giving us a 23/24 modifier. So the new
1381
+ # margin is 0.019965277777777776 = 1/48*23/24.
1382
+ margin = 0.019965277777777776
1383
+ delta = view_high - view_low
1384
+ view_high = view_high - delta * margin
1385
+ view_low = view_low + delta * margin
1386
+
1387
+ interval_t = self.get_transform().transform([view_low, view_high])
1388
+
1389
+ ticks_to_draw = []
1390
+ for tick in ticks:
1391
+ try:
1392
+ loc_t = self.get_transform().transform(tick.get_loc())
1393
+ except AssertionError:
1394
+ # transforms.transform doesn't allow masked values but
1395
+ # some scales might make them, so we need this try/except.
1396
+ pass
1397
+ else:
1398
+ if mtransforms._interval_contains_close(interval_t, loc_t):
1399
+ ticks_to_draw.append(tick)
1400
+
1401
+ return ticks_to_draw
1402
+
1403
+ def _get_ticklabel_bboxes(self, ticks, renderer):
1404
+ """Return lists of bboxes for ticks' label1's and label2's."""
1405
+ return ([tick.label1.get_window_extent(renderer)
1406
+ for tick in ticks
1407
+ if tick.label1.get_visible() and tick.label1.get_in_layout()],
1408
+ [tick.label2.get_window_extent(renderer)
1409
+ for tick in ticks
1410
+ if tick.label2.get_visible() and tick.label2.get_in_layout()])
1411
+
1412
+ def get_tightbbox(self, renderer=None, *, for_layout_only=False):
1413
+ """
1414
+ Return a bounding box that encloses the axis. It only accounts
1415
+ tick labels, axis label, and offsetText.
1416
+
1417
+ If *for_layout_only* is True, then the width of the label (if this
1418
+ is an x-axis) or the height of the label (if this is a y-axis) is
1419
+ collapsed to near zero. This allows tight/constrained_layout to ignore
1420
+ too-long labels when doing their layout.
1421
+ """
1422
+ if not self.get_visible() or for_layout_only and not self.get_in_layout():
1423
+ return
1424
+ if renderer is None:
1425
+ renderer = self.get_figure(root=True)._get_renderer()
1426
+ ticks_to_draw = self._update_ticks()
1427
+
1428
+ self._update_label_position(renderer)
1429
+
1430
+ # go back to just this axis's tick labels
1431
+ tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1432
+
1433
+ self._update_offset_text_position(tlb1, tlb2)
1434
+ self.offsetText.set_text(self.major.formatter.get_offset())
1435
+
1436
+ bboxes = [
1437
+ *(a.get_window_extent(renderer)
1438
+ for a in [self.offsetText]
1439
+ if a.get_visible()),
1440
+ *tlb1, *tlb2,
1441
+ ]
1442
+ # take care of label
1443
+ if self.label.get_visible():
1444
+ bb = self.label.get_window_extent(renderer)
1445
+ # for constrained/tight_layout, we want to ignore the label's
1446
+ # width/height because the adjustments they make can't be improved.
1447
+ # this code collapses the relevant direction
1448
+ if for_layout_only:
1449
+ if self.axis_name == "x" and bb.width > 0:
1450
+ bb.x0 = (bb.x0 + bb.x1) / 2 - 0.5
1451
+ bb.x1 = bb.x0 + 1.0
1452
+ if self.axis_name == "y" and bb.height > 0:
1453
+ bb.y0 = (bb.y0 + bb.y1) / 2 - 0.5
1454
+ bb.y1 = bb.y0 + 1.0
1455
+ bboxes.append(bb)
1456
+ bboxes = [b for b in bboxes if b._is_finite()]
1457
+ if bboxes:
1458
+ return mtransforms.Bbox.union(bboxes)
1459
+ else:
1460
+ return None
1461
+
1462
+ def get_tick_padding(self):
1463
+ values = []
1464
+ if len(self.majorTicks):
1465
+ values.append(self.majorTicks[0].get_tick_padding())
1466
+ if len(self.minorTicks):
1467
+ values.append(self.minorTicks[0].get_tick_padding())
1468
+ return max(values, default=0)
1469
+
1470
+ @martist.allow_rasterization
1471
+ def draw(self, renderer):
1472
+ # docstring inherited
1473
+
1474
+ if not self.get_visible():
1475
+ return
1476
+ renderer.open_group('matplotlib.axis', gid=self.get_gid())
1477
+
1478
+ ticks_to_draw = self._update_ticks()
1479
+ tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1480
+
1481
+ for tick in ticks_to_draw:
1482
+ tick.draw(renderer)
1483
+
1484
+ # Shift label away from axes to avoid overlapping ticklabels.
1485
+ self._update_label_position(renderer)
1486
+ self.label.draw(renderer)
1487
+
1488
+ self._update_offset_text_position(tlb1, tlb2)
1489
+ self.offsetText.set_text(self.major.formatter.get_offset())
1490
+ self.offsetText.draw(renderer)
1491
+
1492
+ renderer.close_group(__name__)
1493
+ self.stale = False
1494
+
1495
+ def get_gridlines(self):
1496
+ """
1497
+ Return this Axis' grid lines as a list of `.Line2D`.
1498
+
1499
+ .. warning::
1500
+
1501
+ Ticks and their constituent parts, including grid lines, are not
1502
+ persistent. Various operations can create, delete, and modify the tick
1503
+ instances; see :ref:`axes-tick-objects`.
1504
+
1505
+ You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1506
+ to define and query grid styling; see :ref:`axes-ticks-styling`.
1507
+ """
1508
+ ticks = self.get_major_ticks()
1509
+ return cbook.silent_list('Line2D gridline',
1510
+ [tick.gridline for tick in ticks])
1511
+
1512
+ def set_label(self, s):
1513
+ """Assigning legend labels is not supported. Raises RuntimeError."""
1514
+ raise RuntimeError(
1515
+ "A legend label cannot be assigned to an Axis. Did you mean to "
1516
+ "set the axis label via set_label_text()?")
1517
+
1518
+ def get_label(self):
1519
+ """
1520
+ [*Discouraged*] Return the axis label as a Text instance.
1521
+
1522
+ .. admonition:: Discouraged
1523
+
1524
+ This overrides `.Artist.get_label`, which is for legend labels, with a new
1525
+ semantic. It is recommended to use the attribute ``Axis.label`` instead.
1526
+ """
1527
+ return self.label
1528
+
1529
+ def get_offset_text(self):
1530
+ """Return the axis offsetText as a Text instance."""
1531
+ return self.offsetText
1532
+
1533
+ def get_pickradius(self):
1534
+ """Return the depth of the axis used by the picker."""
1535
+ return self._pickradius
1536
+
1537
+ def get_majorticklabels(self):
1538
+ """
1539
+ Return this Axis' major tick labels, as a list of `~.text.Text`.
1540
+
1541
+ .. warning::
1542
+
1543
+ Ticks and their constituent parts, including tick labels, are not
1544
+ persistent. Various operations can create, delete, and modify the tick
1545
+ instances; see :ref:`axes-tick-objects`.
1546
+
1547
+ You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1548
+ to define and query tick styling; see :ref:`axes-ticks-styling`.
1549
+ """
1550
+ self._update_ticks()
1551
+ ticks = self.get_major_ticks()
1552
+ labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
1553
+ labels2 = [tick.label2 for tick in ticks if tick.label2.get_visible()]
1554
+ return labels1 + labels2
1555
+
1556
+ def get_minorticklabels(self):
1557
+ """
1558
+ Return this Axis' minor tick labels, as a list of `~.text.Text`.
1559
+
1560
+ .. warning::
1561
+
1562
+ Ticks and their constituent parts, including tick labels, are not
1563
+ persistent. Various operations can create, delete, and modify the tick
1564
+ instances; see :ref:`axes-tick-objects`.
1565
+
1566
+ You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1567
+ to define and query tick styling; see :ref:`axes-ticks-styling`.
1568
+ """
1569
+ self._update_ticks()
1570
+ ticks = self.get_minor_ticks()
1571
+ labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
1572
+ labels2 = [tick.label2 for tick in ticks if tick.label2.get_visible()]
1573
+ return labels1 + labels2
1574
+
1575
+ def get_ticklabels(self, minor=False, which=None):
1576
+ """
1577
+ Get this Axis' tick labels.
1578
+
1579
+ .. warning::
1580
+
1581
+ Ticks and their constituent parts, including tick labels, are not
1582
+ persistent. Various operations can create, delete, and modify the tick
1583
+ instances; see :ref:`axes-tick-objects`.
1584
+
1585
+ You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1586
+ to define and query tick styling; see :ref:`axes-ticks-styling`.
1587
+
1588
+ Parameters
1589
+ ----------
1590
+ minor : bool
1591
+ Whether to return the minor or the major ticklabels.
1592
+
1593
+ which : None, ('minor', 'major', 'both')
1594
+ Overrides *minor*.
1595
+
1596
+ Selects which ticklabels to return
1597
+
1598
+ Returns
1599
+ -------
1600
+ list of `~matplotlib.text.Text`
1601
+ """
1602
+ if which is not None:
1603
+ if which == 'minor':
1604
+ return self.get_minorticklabels()
1605
+ elif which == 'major':
1606
+ return self.get_majorticklabels()
1607
+ elif which == 'both':
1608
+ return self.get_majorticklabels() + self.get_minorticklabels()
1609
+ else:
1610
+ _api.check_in_list(['major', 'minor', 'both'], which=which)
1611
+ if minor:
1612
+ return self.get_minorticklabels()
1613
+ return self.get_majorticklabels()
1614
+
1615
+ def get_majorticklines(self):
1616
+ """
1617
+ Return this Axis' major tick lines as a list of `.Line2D`.
1618
+
1619
+ .. warning::
1620
+
1621
+ Ticks and their constituent parts, including tick lines, are not
1622
+ persistent. Various operations can create, delete, and modify the tick
1623
+ instances; see :ref:`axes-tick-objects`.
1624
+
1625
+ You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1626
+ to define and query tick styling; see :ref:`axes-ticks-styling`.
1627
+ """
1628
+ lines = []
1629
+ ticks = self.get_major_ticks()
1630
+ for tick in ticks:
1631
+ lines.append(tick.tick1line)
1632
+ lines.append(tick.tick2line)
1633
+ return cbook.silent_list('Line2D ticklines', lines)
1634
+
1635
+ def get_minorticklines(self):
1636
+ """
1637
+ Return this Axis' minor tick lines as a list of `.Line2D`.
1638
+
1639
+ .. warning::
1640
+
1641
+ Ticks and their constituent parts, including tick lines, are not
1642
+ persistent. Various operations can create, delete, and modify the tick
1643
+ instances; see :ref:`axes-tick-objects`.
1644
+
1645
+ You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1646
+ to define and query tick styling; see :ref:`axes-ticks-styling`.
1647
+ """
1648
+ lines = []
1649
+ ticks = self.get_minor_ticks()
1650
+ for tick in ticks:
1651
+ lines.append(tick.tick1line)
1652
+ lines.append(tick.tick2line)
1653
+ return cbook.silent_list('Line2D ticklines', lines)
1654
+
1655
+ def get_ticklines(self, minor=False):
1656
+ """
1657
+ Return this Axis' tick lines as a list of `.Line2D`.
1658
+
1659
+ .. warning::
1660
+
1661
+ Ticks and their constituent parts, including tick lines, are not
1662
+ persistent. Various operations can create, delete, and modify the tick
1663
+ instances; see :ref:`axes-tick-objects`.
1664
+
1665
+ You should generally use `.Axis.set_tick_params` / `.Axis.get_tick_params`
1666
+ to define and query tick styling; see :ref:`axes-ticks-styling`.
1667
+ """
1668
+ if minor:
1669
+ return self.get_minorticklines()
1670
+ return self.get_majorticklines()
1671
+
1672
+ def get_majorticklocs(self):
1673
+ """Return this Axis' major tick locations in data coordinates."""
1674
+ return self.major.locator()
1675
+
1676
+ def get_minorticklocs(self):
1677
+ """Return this Axis' minor tick locations in data coordinates."""
1678
+ # Remove minor ticks duplicating major ticks.
1679
+ minor_locs = np.asarray(self.minor.locator())
1680
+ if self.remove_overlapping_locs:
1681
+ major_locs = self.major.locator()
1682
+ transform = self._scale.get_transform()
1683
+ tr_minor_locs = transform.transform(minor_locs)
1684
+ tr_major_locs = transform.transform(major_locs)
1685
+ lo, hi = sorted(transform.transform(self.get_view_interval()))
1686
+ # Use the transformed view limits as scale. 1e-5 is the default
1687
+ # rtol for np.isclose.
1688
+ tol = (hi - lo) * 1e-5
1689
+ mask = np.isclose(tr_minor_locs[:, None], tr_major_locs[None, :],
1690
+ atol=tol, rtol=0).any(axis=1)
1691
+ minor_locs = minor_locs[~mask]
1692
+ return minor_locs
1693
+
1694
+ def get_ticklocs(self, *, minor=False):
1695
+ """
1696
+ Return this Axis' tick locations in data coordinates.
1697
+
1698
+ The locations are not clipped to the current axis limits and hence
1699
+ may contain locations that are not visible in the output.
1700
+
1701
+ Parameters
1702
+ ----------
1703
+ minor : bool, default: False
1704
+ True to return the minor tick directions,
1705
+ False to return the major tick directions.
1706
+
1707
+ Returns
1708
+ -------
1709
+ array of tick locations
1710
+ """
1711
+ return self.get_minorticklocs() if minor else self.get_majorticklocs()
1712
+
1713
+ def get_ticks_direction(self, minor=False):
1714
+ """
1715
+ Return an array of this Axis' tick directions.
1716
+
1717
+ Parameters
1718
+ ----------
1719
+ minor : bool, default: False
1720
+ True to return the minor tick directions,
1721
+ False to return the major tick directions.
1722
+
1723
+ Returns
1724
+ -------
1725
+ array of tick directions
1726
+ """
1727
+ if minor:
1728
+ return np.array(
1729
+ [tick._tickdir for tick in self.get_minor_ticks()])
1730
+ else:
1731
+ return np.array(
1732
+ [tick._tickdir for tick in self.get_major_ticks()])
1733
+
1734
+ def _get_tick(self, major):
1735
+ """Return the default tick instance."""
1736
+ if self._tick_class is None:
1737
+ raise NotImplementedError(
1738
+ f"The Axis subclass {self.__class__.__name__} must define "
1739
+ "_tick_class or reimplement _get_tick()")
1740
+ tick_kw = self._major_tick_kw if major else self._minor_tick_kw
1741
+ return self._tick_class(self.axes, 0, major=major, **tick_kw)
1742
+
1743
+ def _get_tick_label_size(self, axis_name):
1744
+ """
1745
+ Return the text size of tick labels for this Axis.
1746
+
1747
+ This is a convenience function to avoid having to create a `Tick` in
1748
+ `.get_tick_space`, since it is expensive.
1749
+ """
1750
+ tick_kw = self._major_tick_kw
1751
+ size = tick_kw.get('labelsize',
1752
+ mpl.rcParams[f'{axis_name}tick.labelsize'])
1753
+ return mtext.FontProperties(size=size).get_size_in_points()
1754
+
1755
+ def _copy_tick_props(self, src, dest):
1756
+ """Copy the properties from *src* tick to *dest* tick."""
1757
+ if src is None or dest is None:
1758
+ return
1759
+ dest.label1.update_from(src.label1)
1760
+ dest.label2.update_from(src.label2)
1761
+ dest.tick1line.update_from(src.tick1line)
1762
+ dest.tick2line.update_from(src.tick2line)
1763
+ dest.gridline.update_from(src.gridline)
1764
+ dest.update_from(src)
1765
+ dest._loc = src._loc
1766
+ dest._size = src._size
1767
+ dest._width = src._width
1768
+ dest._base_pad = src._base_pad
1769
+ dest._labelrotation = src._labelrotation
1770
+ dest._zorder = src._zorder
1771
+ dest._tickdir = src._tickdir
1772
+
1773
+ def get_label_text(self):
1774
+ """Get the text of the label."""
1775
+ return self.label.get_text()
1776
+
1777
+ def get_major_locator(self):
1778
+ """Get the locator of the major ticker."""
1779
+ return self.major.locator
1780
+
1781
+ def get_minor_locator(self):
1782
+ """Get the locator of the minor ticker."""
1783
+ return self.minor.locator
1784
+
1785
+ def get_major_formatter(self):
1786
+ """Get the formatter of the major ticker."""
1787
+ return self.major.formatter
1788
+
1789
+ def get_minor_formatter(self):
1790
+ """Get the formatter of the minor ticker."""
1791
+ return self.minor.formatter
1792
+
1793
+ def get_major_ticks(self, numticks=None):
1794
+ r"""
1795
+ Return the list of major `.Tick`\s.
1796
+
1797
+ .. warning::
1798
+
1799
+ Ticks are not guaranteed to be persistent. Various operations
1800
+ can create, delete and modify the Tick instances. There is an
1801
+ imminent risk that changes to individual ticks will not
1802
+ survive if you work on the figure further (including also
1803
+ panning/zooming on a displayed figure).
1804
+
1805
+ Working on the individual ticks is a method of last resort.
1806
+ Use `.set_tick_params` instead if possible.
1807
+ """
1808
+ if numticks is None:
1809
+ numticks = len(self.get_majorticklocs())
1810
+
1811
+ while len(self.majorTicks) < numticks:
1812
+ # Update the new tick label properties from the old.
1813
+ tick = self._get_tick(major=True)
1814
+ self.majorTicks.append(tick)
1815
+ self._copy_tick_props(self.majorTicks[0], tick)
1816
+
1817
+ return self.majorTicks[:numticks]
1818
+
1819
+ def get_minor_ticks(self, numticks=None):
1820
+ r"""
1821
+ Return the list of minor `.Tick`\s.
1822
+
1823
+ .. warning::
1824
+
1825
+ Ticks are not guaranteed to be persistent. Various operations
1826
+ can create, delete and modify the Tick instances. There is an
1827
+ imminent risk that changes to individual ticks will not
1828
+ survive if you work on the figure further (including also
1829
+ panning/zooming on a displayed figure).
1830
+
1831
+ Working on the individual ticks is a method of last resort.
1832
+ Use `.set_tick_params` instead if possible.
1833
+ """
1834
+ if numticks is None:
1835
+ numticks = len(self.get_minorticklocs())
1836
+
1837
+ while len(self.minorTicks) < numticks:
1838
+ # Update the new tick label properties from the old.
1839
+ tick = self._get_tick(major=False)
1840
+ self.minorTicks.append(tick)
1841
+ self._copy_tick_props(self.minorTicks[0], tick)
1842
+
1843
+ return self.minorTicks[:numticks]
1844
+
1845
+ def grid(self, visible=None, which='major', **kwargs):
1846
+ """
1847
+ Configure the grid lines.
1848
+
1849
+ Parameters
1850
+ ----------
1851
+ visible : bool or None
1852
+ Whether to show the grid lines. If any *kwargs* are supplied, it
1853
+ is assumed you want the grid on and *visible* will be set to True.
1854
+
1855
+ If *visible* is *None* and there are no *kwargs*, this toggles the
1856
+ visibility of the lines.
1857
+
1858
+ which : {'major', 'minor', 'both'}
1859
+ The grid lines to apply the changes on.
1860
+
1861
+ **kwargs : `~matplotlib.lines.Line2D` properties
1862
+ Define the line properties of the grid, e.g.::
1863
+
1864
+ grid(color='r', linestyle='-', linewidth=2)
1865
+ """
1866
+ if kwargs:
1867
+ if visible is None:
1868
+ visible = True
1869
+ elif not visible: # something false-like but not None
1870
+ _api.warn_external('First parameter to grid() is false, '
1871
+ 'but line properties are supplied. The '
1872
+ 'grid will be enabled.')
1873
+ visible = True
1874
+ which = which.lower()
1875
+ _api.check_in_list(['major', 'minor', 'both'], which=which)
1876
+ gridkw = {f'grid_{name}': value for name, value in kwargs.items()}
1877
+ if which in ['minor', 'both']:
1878
+ gridkw['gridOn'] = (not self._minor_tick_kw['gridOn']
1879
+ if visible is None else visible)
1880
+ self.set_tick_params(which='minor', **gridkw)
1881
+ if which in ['major', 'both']:
1882
+ gridkw['gridOn'] = (not self._major_tick_kw['gridOn']
1883
+ if visible is None else visible)
1884
+ self.set_tick_params(which='major', **gridkw)
1885
+ self.stale = True
1886
+
1887
+ def update_units(self, data):
1888
+ """
1889
+ Introspect *data* for units converter and update the
1890
+ ``axis.get_converter`` instance if necessary. Return *True*
1891
+ if *data* is registered for unit conversion.
1892
+ """
1893
+ if not self._converter_is_explicit:
1894
+ converter = munits.registry.get_converter(data)
1895
+ else:
1896
+ converter = self._converter
1897
+
1898
+ if converter is None:
1899
+ return False
1900
+
1901
+ neednew = self._converter != converter
1902
+ self._set_converter(converter)
1903
+ default = self._converter.default_units(data, self)
1904
+ if default is not None and self.units is None:
1905
+ self.set_units(default)
1906
+
1907
+ elif neednew:
1908
+ self._update_axisinfo()
1909
+ self.stale = True
1910
+ return True
1911
+
1912
+ def _update_axisinfo(self):
1913
+ """
1914
+ Check the axis converter for the stored units to see if the
1915
+ axis info needs to be updated.
1916
+ """
1917
+ if self._converter is None:
1918
+ return
1919
+
1920
+ info = self._converter.axisinfo(self.units, self)
1921
+
1922
+ if info is None:
1923
+ return
1924
+ if info.majloc is not None and \
1925
+ self.major.locator != info.majloc and self.isDefault_majloc:
1926
+ self.set_major_locator(info.majloc)
1927
+ self.isDefault_majloc = True
1928
+ if info.minloc is not None and \
1929
+ self.minor.locator != info.minloc and self.isDefault_minloc:
1930
+ self.set_minor_locator(info.minloc)
1931
+ self.isDefault_minloc = True
1932
+ if info.majfmt is not None and \
1933
+ self.major.formatter != info.majfmt and self.isDefault_majfmt:
1934
+ self.set_major_formatter(info.majfmt)
1935
+ self.isDefault_majfmt = True
1936
+ if info.minfmt is not None and \
1937
+ self.minor.formatter != info.minfmt and self.isDefault_minfmt:
1938
+ self.set_minor_formatter(info.minfmt)
1939
+ self.isDefault_minfmt = True
1940
+ if info.label is not None and self.isDefault_label:
1941
+ self.set_label_text(info.label)
1942
+ self.isDefault_label = True
1943
+
1944
+ self.set_default_intervals()
1945
+
1946
+ def have_units(self):
1947
+ return self._converter is not None or self.units is not None
1948
+
1949
+ def convert_units(self, x):
1950
+ # If x is natively supported by Matplotlib, doesn't need converting
1951
+ if munits._is_natively_supported(x):
1952
+ return x
1953
+
1954
+ if self._converter is None:
1955
+ self._set_converter(munits.registry.get_converter(x))
1956
+
1957
+ if self._converter is None:
1958
+ return x
1959
+ try:
1960
+ ret = self._converter.convert(x, self.units, self)
1961
+ except Exception as e:
1962
+ raise munits.ConversionError('Failed to convert value(s) to axis '
1963
+ f'units: {x!r}') from e
1964
+ return ret
1965
+
1966
+ def get_converter(self):
1967
+ """
1968
+ Get the unit converter for axis.
1969
+
1970
+ Returns
1971
+ -------
1972
+ `~matplotlib.units.ConversionInterface` or None
1973
+ """
1974
+ return self._converter
1975
+
1976
+ def set_converter(self, converter):
1977
+ """
1978
+ Set the unit converter for axis.
1979
+
1980
+ Parameters
1981
+ ----------
1982
+ converter : `~matplotlib.units.ConversionInterface`
1983
+ """
1984
+ self._set_converter(converter)
1985
+ self._converter_is_explicit = True
1986
+
1987
+ def _set_converter(self, converter):
1988
+ if self._converter is converter or self._converter == converter:
1989
+ return
1990
+ if self._converter_is_explicit:
1991
+ raise RuntimeError("Axis already has an explicit converter set")
1992
+ elif (
1993
+ self._converter is not None and
1994
+ not isinstance(converter, type(self._converter)) and
1995
+ not isinstance(self._converter, type(converter))
1996
+ ):
1997
+ _api.warn_external(
1998
+ "This axis already has a converter set and "
1999
+ "is updating to a potentially incompatible converter"
2000
+ )
2001
+ self._converter = converter
2002
+
2003
+ def set_units(self, u):
2004
+ """
2005
+ Set the units for axis.
2006
+
2007
+ Parameters
2008
+ ----------
2009
+ u : units tag
2010
+
2011
+ Notes
2012
+ -----
2013
+ The units of any shared axis will also be updated.
2014
+ """
2015
+ if u == self.units:
2016
+ return
2017
+ for axis in self._get_shared_axis():
2018
+ axis.units = u
2019
+ axis._update_axisinfo()
2020
+ axis.callbacks.process('units')
2021
+ axis.stale = True
2022
+
2023
+ def get_units(self):
2024
+ """Return the units for axis."""
2025
+ return self.units
2026
+
2027
+ def set_label_text(self, label, fontdict=None, **kwargs):
2028
+ """
2029
+ Set the text value of the axis label.
2030
+
2031
+ Parameters
2032
+ ----------
2033
+ label : str
2034
+ Text string.
2035
+ fontdict : dict
2036
+ Text properties.
2037
+
2038
+ .. admonition:: Discouraged
2039
+
2040
+ The use of *fontdict* is discouraged. Parameters should be passed as
2041
+ individual keyword arguments or using dictionary-unpacking
2042
+ ``set_label_text(..., **fontdict)``.
2043
+
2044
+ **kwargs
2045
+ Merged into fontdict.
2046
+ """
2047
+ self.isDefault_label = False
2048
+ self.label.set_text(label)
2049
+ if fontdict is not None:
2050
+ self.label.update(fontdict)
2051
+ self.label.update(kwargs)
2052
+ self.stale = True
2053
+ return self.label
2054
+
2055
+ def set_major_formatter(self, formatter):
2056
+ """
2057
+ Set the formatter of the major ticker.
2058
+
2059
+ In addition to a `~matplotlib.ticker.Formatter` instance,
2060
+ this also accepts a ``str`` or function.
2061
+
2062
+ For a ``str`` a `~matplotlib.ticker.StrMethodFormatter` is used.
2063
+ The field used for the value must be labeled ``'x'`` and the field used
2064
+ for the position must be labeled ``'pos'``.
2065
+ See the `~matplotlib.ticker.StrMethodFormatter` documentation for
2066
+ more information.
2067
+
2068
+ For a function, a `~matplotlib.ticker.FuncFormatter` is used.
2069
+ The function must take two inputs (a tick value ``x`` and a
2070
+ position ``pos``), and return a string containing the corresponding
2071
+ tick label.
2072
+ See the `~matplotlib.ticker.FuncFormatter` documentation for
2073
+ more information.
2074
+
2075
+ Parameters
2076
+ ----------
2077
+ formatter : `~matplotlib.ticker.Formatter`, ``str``, or function
2078
+ """
2079
+ self._set_formatter(formatter, self.major)
2080
+
2081
+ def set_minor_formatter(self, formatter):
2082
+ """
2083
+ Set the formatter of the minor ticker.
2084
+
2085
+ In addition to a `~matplotlib.ticker.Formatter` instance,
2086
+ this also accepts a ``str`` or function.
2087
+ See `.Axis.set_major_formatter` for more information.
2088
+
2089
+ Parameters
2090
+ ----------
2091
+ formatter : `~matplotlib.ticker.Formatter`, ``str``, or function
2092
+ """
2093
+ self._set_formatter(formatter, self.minor)
2094
+
2095
+ def _set_formatter(self, formatter, level):
2096
+ if isinstance(formatter, str):
2097
+ formatter = mticker.StrMethodFormatter(formatter)
2098
+ # Don't allow any other TickHelper to avoid easy-to-make errors,
2099
+ # like using a Locator instead of a Formatter.
2100
+ elif (callable(formatter) and
2101
+ not isinstance(formatter, mticker.TickHelper)):
2102
+ formatter = mticker.FuncFormatter(formatter)
2103
+ else:
2104
+ _api.check_isinstance(mticker.Formatter, formatter=formatter)
2105
+
2106
+ if (isinstance(formatter, mticker.FixedFormatter)
2107
+ and len(formatter.seq) > 0
2108
+ and not isinstance(level.locator, mticker.FixedLocator)
2109
+ and not (hasattr(level.locator, 'base') and
2110
+ isinstance(level.locator.base, mticker.FixedLocator))):
2111
+ _api.warn_external('FixedFormatter should only be used together '
2112
+ 'with FixedLocator')
2113
+
2114
+ if level == self.major:
2115
+ self.isDefault_majfmt = False
2116
+ else:
2117
+ self.isDefault_minfmt = False
2118
+
2119
+ level.formatter = formatter
2120
+ formatter.set_axis(self)
2121
+ self.stale = True
2122
+
2123
+ def set_major_locator(self, locator):
2124
+ """
2125
+ Set the locator of the major ticker.
2126
+
2127
+ Parameters
2128
+ ----------
2129
+ locator : `~matplotlib.ticker.Locator`
2130
+ """
2131
+ _api.check_isinstance(mticker.Locator, locator=locator)
2132
+ self.isDefault_majloc = False
2133
+ self.major.locator = locator
2134
+ if self.major.formatter:
2135
+ self.major.formatter._set_locator(locator)
2136
+ locator.set_axis(self)
2137
+ self.stale = True
2138
+
2139
+ def set_minor_locator(self, locator):
2140
+ """
2141
+ Set the locator of the minor ticker.
2142
+
2143
+ Parameters
2144
+ ----------
2145
+ locator : `~matplotlib.ticker.Locator`
2146
+ """
2147
+ _api.check_isinstance(mticker.Locator, locator=locator)
2148
+ self.isDefault_minloc = False
2149
+ self.minor.locator = locator
2150
+ if self.minor.formatter:
2151
+ self.minor.formatter._set_locator(locator)
2152
+ locator.set_axis(self)
2153
+ self.stale = True
2154
+
2155
+ def set_pickradius(self, pickradius):
2156
+ """
2157
+ Set the depth of the axis used by the picker.
2158
+
2159
+ Parameters
2160
+ ----------
2161
+ pickradius : float
2162
+ The acceptance radius for containment tests.
2163
+ See also `.Axis.contains`.
2164
+ """
2165
+ if not isinstance(pickradius, Real) or pickradius < 0:
2166
+ raise ValueError("pick radius should be a distance")
2167
+ self._pickradius = pickradius
2168
+
2169
+ pickradius = property(
2170
+ get_pickradius, set_pickradius, doc="The acceptance radius for "
2171
+ "containment tests. See also `.Axis.contains`.")
2172
+
2173
+ # Helper for set_ticklabels. Defining it here makes it picklable.
2174
+ @staticmethod
2175
+ def _format_with_dict(tickd, x, pos):
2176
+ return tickd.get(x, "")
2177
+
2178
+ def set_ticklabels(self, labels, *, minor=False, fontdict=None, **kwargs):
2179
+ r"""
2180
+ [*Discouraged*] Set this Axis' tick labels with list of string labels.
2181
+
2182
+ .. admonition:: Discouraged
2183
+
2184
+ The use of this method is discouraged, because of the dependency on
2185
+ tick positions. In most cases, you'll want to use
2186
+ ``Axes.set_[x/y/z]ticks(positions, labels)`` or ``Axis.set_ticks``
2187
+ instead.
2188
+
2189
+ If you are using this method, you should always fix the tick
2190
+ positions before, e.g. by using `.Axis.set_ticks` or by explicitly
2191
+ setting a `~.ticker.FixedLocator`. Otherwise, ticks are free to
2192
+ move and the labels may end up in unexpected positions.
2193
+
2194
+ Parameters
2195
+ ----------
2196
+ labels : sequence of str or of `.Text`\s
2197
+ Texts for labeling each tick location in the sequence set by
2198
+ `.Axis.set_ticks`; the number of labels must match the number of locations.
2199
+ The labels are used as is, via a `.FixedFormatter` (without further
2200
+ formatting).
2201
+
2202
+ minor : bool
2203
+ If True, set minor ticks instead of major ticks.
2204
+
2205
+ fontdict : dict, optional
2206
+
2207
+ .. admonition:: Discouraged
2208
+
2209
+ The use of *fontdict* is discouraged. Parameters should be passed as
2210
+ individual keyword arguments or using dictionary-unpacking
2211
+ ``set_ticklabels(..., **fontdict)``.
2212
+
2213
+ A dictionary controlling the appearance of the ticklabels.
2214
+ The default *fontdict* is::
2215
+
2216
+ {'fontsize': rcParams['axes.titlesize'],
2217
+ 'fontweight': rcParams['axes.titleweight'],
2218
+ 'verticalalignment': 'baseline',
2219
+ 'horizontalalignment': loc}
2220
+
2221
+ **kwargs
2222
+ Text properties.
2223
+
2224
+ .. warning::
2225
+
2226
+ This only sets the properties of the current ticks, which is
2227
+ only sufficient for static plots.
2228
+
2229
+ Ticks are not guaranteed to be persistent. Various operations
2230
+ can create, delete and modify the Tick instances. There is an
2231
+ imminent risk that these settings can get lost if you work on
2232
+ the figure further (including also panning/zooming on a
2233
+ displayed figure).
2234
+
2235
+ Use `.set_tick_params` instead if possible.
2236
+
2237
+ Returns
2238
+ -------
2239
+ list of `.Text`\s
2240
+ For each tick, includes ``tick.label1`` if it is visible, then
2241
+ ``tick.label2`` if it is visible, in that order.
2242
+ """
2243
+ try:
2244
+ labels = [t.get_text() if hasattr(t, 'get_text') else t
2245
+ for t in labels]
2246
+ except TypeError:
2247
+ raise TypeError(f"{labels=!r} must be a sequence") from None
2248
+ locator = (self.get_minor_locator() if minor
2249
+ else self.get_major_locator())
2250
+ if not labels:
2251
+ formatter = mticker.NullFormatter()
2252
+ elif (isinstance(locator, mticker.FixedLocator) or
2253
+ (hasattr(locator, 'base') and
2254
+ isinstance(locator.base, mticker.FixedLocator))):
2255
+ # Also handles locators that wrap a FixedLocator (e.g. RadialLocator).
2256
+ fixed_locator = (locator if isinstance(locator, mticker.FixedLocator)
2257
+ else locator.base)
2258
+ # Passing [] as a list of labels is often used as a way to
2259
+ # remove all tick labels, so only error for > 0 labels
2260
+ if len(fixed_locator.locs) != len(labels) and len(labels) != 0:
2261
+ raise ValueError(
2262
+ "The number of FixedLocator locations"
2263
+ f" ({len(fixed_locator.locs)}), usually from a call to"
2264
+ " set_ticks, does not match"
2265
+ f" the number of labels ({len(labels)}).")
2266
+ tickd = {loc: lab for loc, lab in zip(fixed_locator.locs, labels)}
2267
+ func = functools.partial(self._format_with_dict, tickd)
2268
+ formatter = mticker.FuncFormatter(func)
2269
+ else:
2270
+ _api.warn_external(
2271
+ "set_ticklabels() should only be used with a fixed number of "
2272
+ "ticks, i.e. after set_ticks() or using a FixedLocator. "
2273
+ "Otherwise, ticks may be mislabeled.")
2274
+ formatter = mticker.FixedFormatter(labels)
2275
+
2276
+ with warnings.catch_warnings():
2277
+ warnings.filterwarnings(
2278
+ "ignore",
2279
+ message="FixedFormatter should only be used together with FixedLocator")
2280
+ if minor:
2281
+ self.set_minor_formatter(formatter)
2282
+ locs = self.get_minorticklocs()
2283
+ ticks = self.get_minor_ticks(len(locs))
2284
+ else:
2285
+ self.set_major_formatter(formatter)
2286
+ locs = self.get_majorticklocs()
2287
+ ticks = self.get_major_ticks(len(locs))
2288
+
2289
+ ret = []
2290
+ if fontdict is not None:
2291
+ kwargs.update(fontdict)
2292
+ for pos, (loc, tick) in enumerate(zip(locs, ticks)):
2293
+ tick.update_position(loc)
2294
+ tick_label = formatter(loc, pos)
2295
+ # deal with label1
2296
+ tick.label1.set_text(tick_label)
2297
+ tick.label1._internal_update(kwargs)
2298
+ # deal with label2
2299
+ tick.label2.set_text(tick_label)
2300
+ tick.label2._internal_update(kwargs)
2301
+ # only return visible tick labels
2302
+ if tick.label1.get_visible():
2303
+ ret.append(tick.label1)
2304
+ if tick.label2.get_visible():
2305
+ ret.append(tick.label2)
2306
+
2307
+ self.stale = True
2308
+ return ret
2309
+
2310
+ def _set_tick_locations(self, ticks, *, minor=False):
2311
+ # see docstring of set_ticks
2312
+
2313
+ # XXX if the user changes units, the information will be lost here
2314
+ ticks = self.convert_units(ticks)
2315
+ locator = mticker.FixedLocator(ticks) # validate ticks early.
2316
+ if len(ticks):
2317
+ old_vmin, old_vmax = self.get_view_interval()
2318
+ for axis in self._get_shared_axis():
2319
+ # set_view_interval maintains any preexisting inversion.
2320
+ axis.set_view_interval(min(ticks), max(ticks))
2321
+ new_vmin, new_vmax = self.get_view_interval()
2322
+ if old_vmin != new_vmin or old_vmax != new_vmax:
2323
+ self.axes.callbacks.process(
2324
+ f"{self._get_axis_name()}lim_changed",
2325
+ self.axes,
2326
+ )
2327
+ self.axes.stale = True
2328
+ if minor:
2329
+ self.set_minor_locator(locator)
2330
+ return self.get_minor_ticks(len(ticks))
2331
+ else:
2332
+ self.set_major_locator(locator)
2333
+ return self.get_major_ticks(len(ticks))
2334
+
2335
+ def set_ticks(self, ticks, labels=None, *, minor=False, **kwargs):
2336
+ """
2337
+ Set this Axis' tick locations and optionally tick labels.
2338
+
2339
+ If necessary, the view limits of the Axis are expanded so that all
2340
+ given ticks are visible.
2341
+
2342
+ Parameters
2343
+ ----------
2344
+ ticks : 1D array-like
2345
+ Array of tick locations (either floats or in axis units). The axis
2346
+ `.Locator` is replaced by a `~.ticker.FixedLocator`.
2347
+
2348
+ Pass an empty list (``set_ticks([])``) to remove all ticks.
2349
+
2350
+ Some tick formatters will not label arbitrary tick positions;
2351
+ e.g. log formatters only label decade ticks by default. In
2352
+ such a case you can set a formatter explicitly on the axis
2353
+ using `.Axis.set_major_formatter` or provide formatted
2354
+ *labels* yourself.
2355
+
2356
+ labels : list of str, optional
2357
+ Tick labels for each location in *ticks*; must have the same length as
2358
+ *ticks*. If set, the labels are used as is, via a `.FixedFormatter`.
2359
+ If not set, the labels are generated using the axis tick `.Formatter`.
2360
+
2361
+ minor : bool, default: False
2362
+ If ``False``, set only the major ticks; if ``True``, only the minor ticks.
2363
+
2364
+ **kwargs
2365
+ `.Text` properties for the labels. Using these is only allowed if
2366
+ you pass *labels*. In other cases, please use `~.Axes.tick_params`.
2367
+
2368
+ Notes
2369
+ -----
2370
+ The mandatory expansion of the view limits is an intentional design
2371
+ choice to prevent the surprise of a non-visible tick. If you need
2372
+ other limits, you should set the limits explicitly after setting the
2373
+ ticks.
2374
+ """
2375
+ if labels is None and kwargs:
2376
+ first_key = next(iter(kwargs))
2377
+ raise ValueError(
2378
+ f"Incorrect use of keyword argument {first_key!r}. Keyword arguments "
2379
+ "other than 'minor' modify the text labels and can only be used if "
2380
+ "'labels' are passed as well.")
2381
+ result = self._set_tick_locations(ticks, minor=minor)
2382
+ if labels is not None:
2383
+ self.set_ticklabels(labels, minor=minor, **kwargs)
2384
+ return result
2385
+
2386
+ def _get_tick_boxes_siblings(self, renderer):
2387
+ """
2388
+ Get the bounding boxes for this `.axis` and its siblings
2389
+ as set by `.Figure.align_xlabels` or `.Figure.align_ylabels`.
2390
+
2391
+ By default, it just gets bboxes for *self*.
2392
+ """
2393
+ # Get the Grouper keeping track of x or y label groups for this figure.
2394
+ name = self._get_axis_name()
2395
+ if name not in self.get_figure(root=False)._align_label_groups:
2396
+ return [], []
2397
+ grouper = self.get_figure(root=False)._align_label_groups[name]
2398
+ bboxes = []
2399
+ bboxes2 = []
2400
+ # If we want to align labels from other Axes:
2401
+ for ax in grouper.get_siblings(self.axes):
2402
+ axis = ax._axis_map[name]
2403
+ ticks_to_draw = axis._update_ticks()
2404
+ tlb, tlb2 = axis._get_ticklabel_bboxes(ticks_to_draw, renderer)
2405
+ bboxes.extend(tlb)
2406
+ bboxes2.extend(tlb2)
2407
+ return bboxes, bboxes2
2408
+
2409
+ def _update_label_position(self, renderer):
2410
+ """
2411
+ Update the label position based on the bounding box enclosing
2412
+ all the ticklabels and axis spine.
2413
+ """
2414
+ raise NotImplementedError('Derived must override')
2415
+
2416
+ def _update_offset_text_position(self, bboxes, bboxes2):
2417
+ """
2418
+ Update the offset text position based on the sequence of bounding
2419
+ boxes of all the ticklabels.
2420
+ """
2421
+ raise NotImplementedError('Derived must override')
2422
+
2423
+ def axis_date(self, tz=None):
2424
+ """
2425
+ Set up axis ticks and labels to treat data along this Axis as dates.
2426
+
2427
+ Parameters
2428
+ ----------
2429
+ tz : str or `datetime.tzinfo`, default: :rc:`timezone`
2430
+ The timezone used to create date labels.
2431
+ """
2432
+ # By providing a sample datetime instance with the desired timezone,
2433
+ # the registered converter can be selected, and the "units" attribute,
2434
+ # which is the timezone, can be set.
2435
+ if isinstance(tz, str):
2436
+ from matplotlib_rs._vendor.dateutil import tz as dateutil_tz
2437
+ tz = dateutil_tz.gettz(tz)
2438
+ self.update_units(datetime.datetime(2009, 1, 1, 0, 0, 0, 0, tz))
2439
+
2440
+ def get_tick_space(self):
2441
+ """Return the estimated number of ticks that can fit on the axis."""
2442
+ # Must be overridden in the subclass
2443
+ raise NotImplementedError()
2444
+
2445
+ def _get_ticks_position(self):
2446
+ """
2447
+ Helper for `XAxis.get_ticks_position` and `YAxis.get_ticks_position`.
2448
+
2449
+ Check the visibility of tick1line, label1, tick2line, and label2 on
2450
+ the first major and the first minor ticks, provided these ticks are used
2451
+ i.e. the corresponding locator is not a NullLocator, and return
2452
+
2453
+ - 1 if only tick1line and label1 are visible (which corresponds to
2454
+ "bottom" for the x-axis and "left" for the y-axis);
2455
+ - 2 if only tick2line and label2 are visible (which corresponds to
2456
+ "top" for the x-axis and "right" for the y-axis);
2457
+ - "default" if only tick1line, tick2line and label1 are visible;
2458
+ - "unknown" otherwise.
2459
+ """
2460
+ representative_ticks = []
2461
+ if not isinstance(self.get_major_locator(), NullLocator):
2462
+ representative_ticks.append(self.majorTicks[0])
2463
+ if not isinstance(self.get_minor_locator(), NullLocator):
2464
+ representative_ticks.append(self.minorTicks[0])
2465
+
2466
+ if all(tick.tick1line.get_visible()
2467
+ and not tick.tick2line.get_visible()
2468
+ and tick.label1.get_visible()
2469
+ and not tick.label2.get_visible()
2470
+ for tick in representative_ticks):
2471
+ return 1
2472
+ elif all(tick.tick2line.get_visible()
2473
+ and not tick.tick1line.get_visible()
2474
+ and tick.label2.get_visible()
2475
+ and not tick.label1.get_visible()
2476
+ for tick in representative_ticks):
2477
+ return 2
2478
+ elif all(tick.tick1line.get_visible()
2479
+ and tick.tick2line.get_visible()
2480
+ and tick.label1.get_visible()
2481
+ and not tick.label2.get_visible()
2482
+ for tick in representative_ticks):
2483
+ return "default"
2484
+ else:
2485
+ return "unknown"
2486
+
2487
+ def get_label_position(self):
2488
+ """
2489
+ Return the label position (top or bottom)
2490
+ """
2491
+ return self.label_position
2492
+
2493
+ def set_label_position(self, position):
2494
+ """
2495
+ Set the label position (top or bottom)
2496
+
2497
+ Parameters
2498
+ ----------
2499
+ position : {'top', 'bottom'}
2500
+ """
2501
+ raise NotImplementedError()
2502
+
2503
+ def get_minpos(self):
2504
+ raise NotImplementedError()
2505
+
2506
+
2507
+ def _make_getset_interval(method_name, lim_name, attr_name):
2508
+ """
2509
+ Helper to generate ``get_{data,view}_interval`` and
2510
+ ``set_{data,view}_interval`` implementations.
2511
+ """
2512
+
2513
+ def getter(self):
2514
+ # docstring inherited.
2515
+ return getattr(getattr(self.axes, lim_name), attr_name)
2516
+
2517
+ def setter(self, vmin, vmax, ignore=False):
2518
+ # docstring inherited.
2519
+ if ignore:
2520
+ setattr(getattr(self.axes, lim_name), attr_name, (vmin, vmax))
2521
+ else:
2522
+ oldmin, oldmax = getter(self)
2523
+ if oldmin < oldmax:
2524
+ setter(self, min(vmin, vmax, oldmin), max(vmin, vmax, oldmax),
2525
+ ignore=True)
2526
+ else:
2527
+ setter(self, max(vmin, vmax, oldmin), min(vmin, vmax, oldmax),
2528
+ ignore=True)
2529
+ self.stale = True
2530
+
2531
+ getter.__name__ = f"get_{method_name}_interval"
2532
+ setter.__name__ = f"set_{method_name}_interval"
2533
+
2534
+ return getter, setter
2535
+
2536
+
2537
+ class XAxis(Axis):
2538
+ __name__ = 'xaxis'
2539
+ axis_name = 'x' #: Read-only name identifying the axis.
2540
+ _tick_class = XTick
2541
+
2542
+ def __init__(self, *args, **kwargs):
2543
+ super().__init__(*args, **kwargs)
2544
+ self._init()
2545
+
2546
+ def _init(self):
2547
+ """
2548
+ Initialize the label and offsetText instance values and
2549
+ `label_position` / `offset_text_position`.
2550
+ """
2551
+ # x in axes coords, y in display coords (to be updated at draw time by
2552
+ # _update_label_positions and _update_offset_text_position).
2553
+ self.label.set(
2554
+ x=0.5, y=0,
2555
+ verticalalignment='top', horizontalalignment='center',
2556
+ transform=mtransforms.blended_transform_factory(
2557
+ self.axes.transAxes, mtransforms.IdentityTransform()),
2558
+ )
2559
+ self.label_position = 'bottom'
2560
+
2561
+ if mpl.rcParams['xtick.labelcolor'] == 'inherit':
2562
+ tick_color = mpl.rcParams['xtick.color']
2563
+ else:
2564
+ tick_color = mpl.rcParams['xtick.labelcolor']
2565
+
2566
+ self.offsetText.set(
2567
+ x=1, y=0,
2568
+ verticalalignment='top', horizontalalignment='right',
2569
+ transform=mtransforms.blended_transform_factory(
2570
+ self.axes.transAxes, mtransforms.IdentityTransform()),
2571
+ fontsize=mpl.rcParams['xtick.labelsize'],
2572
+ color=tick_color
2573
+ )
2574
+ self.offset_text_position = 'bottom'
2575
+
2576
+ def contains(self, mouseevent):
2577
+ """Test whether the mouse event occurred in the x-axis."""
2578
+ if self._different_canvas(mouseevent):
2579
+ return False, {}
2580
+ x, y = mouseevent.x, mouseevent.y
2581
+ try:
2582
+ trans = self.axes.transAxes.inverted()
2583
+ xaxes, yaxes = trans.transform((x, y))
2584
+ except ValueError:
2585
+ return False, {}
2586
+ (l, b), (r, t) = self.axes.transAxes.transform([(0, 0), (1, 1)])
2587
+ inaxis = 0 <= xaxes <= 1 and (
2588
+ b - self._pickradius < y < b or
2589
+ t < y < t + self._pickradius)
2590
+ return inaxis, {}
2591
+
2592
+ def set_label_position(self, position):
2593
+ """
2594
+ Set the label position (top or bottom)
2595
+
2596
+ Parameters
2597
+ ----------
2598
+ position : {'top', 'bottom'}
2599
+ """
2600
+ self.label.set_verticalalignment(_api.getitem_checked({
2601
+ 'top': 'baseline', 'bottom': 'top',
2602
+ }, position=position))
2603
+ self.label_position = position
2604
+ self.stale = True
2605
+
2606
+ def _update_label_position(self, renderer):
2607
+ """
2608
+ Update the label position based on the bounding box enclosing
2609
+ all the ticklabels and axis spine
2610
+ """
2611
+ if not self._autolabelpos:
2612
+ return
2613
+
2614
+ # get bounding boxes for this axis and any siblings
2615
+ # that have been set by `fig.align_xlabels()`
2616
+ bboxes, bboxes2 = self._get_tick_boxes_siblings(renderer=renderer)
2617
+ x, y = self.label.get_position()
2618
+
2619
+ if self.label_position == 'bottom':
2620
+ # Union with extents of the bottom spine if present, of the axes otherwise.
2621
+ bbox = mtransforms.Bbox.union([
2622
+ *bboxes, self.axes.spines.get("bottom", self.axes).get_window_extent()])
2623
+ self.label.set_position(
2624
+ (x, bbox.y0 - self.labelpad * self.get_figure(root=True).dpi / 72))
2625
+ else:
2626
+ # Union with extents of the top spine if present, of the axes otherwise.
2627
+ bbox = mtransforms.Bbox.union([
2628
+ *bboxes2, self.axes.spines.get("top", self.axes).get_window_extent()])
2629
+ self.label.set_position(
2630
+ (x, bbox.y1 + self.labelpad * self.get_figure(root=True).dpi / 72))
2631
+
2632
+ def _update_offset_text_position(self, bboxes, bboxes2):
2633
+ """
2634
+ Update the offset_text position based on the sequence of bounding
2635
+ boxes of all the ticklabels
2636
+ """
2637
+ x, y = self.offsetText.get_position()
2638
+ if not hasattr(self, '_tick_position'):
2639
+ self._tick_position = 'bottom'
2640
+ if self._tick_position == 'bottom':
2641
+ if not len(bboxes):
2642
+ bottom = self.axes.bbox.ymin
2643
+ else:
2644
+ bbox = mtransforms.Bbox.union(bboxes)
2645
+ bottom = bbox.y0
2646
+ y = bottom - self.OFFSETTEXTPAD * self.get_figure(root=True).dpi / 72
2647
+ else:
2648
+ if not len(bboxes2):
2649
+ top = self.axes.bbox.ymax
2650
+ else:
2651
+ bbox = mtransforms.Bbox.union(bboxes2)
2652
+ top = bbox.y1
2653
+ y = top + self.OFFSETTEXTPAD * self.get_figure(root=True).dpi / 72
2654
+ self.offsetText.set_position((x, y))
2655
+
2656
+ def set_ticks_position(self, position):
2657
+ """
2658
+ Set the ticks position.
2659
+
2660
+ Parameters
2661
+ ----------
2662
+ position : {'top', 'bottom', 'both', 'default', 'none'}
2663
+ 'both' sets the ticks to appear on both positions, but does not
2664
+ change the tick labels. 'default' resets the tick positions to
2665
+ the default: ticks on both positions, labels at bottom. 'none'
2666
+ can be used if you don't want any ticks. 'none' and 'both'
2667
+ affect only the ticks, not the labels.
2668
+ """
2669
+ if position == 'top':
2670
+ self.set_tick_params(which='both', top=True, labeltop=True,
2671
+ bottom=False, labelbottom=False)
2672
+ self._tick_position = 'top'
2673
+ self.offsetText.set_verticalalignment('bottom')
2674
+ elif position == 'bottom':
2675
+ self.set_tick_params(which='both', top=False, labeltop=False,
2676
+ bottom=True, labelbottom=True)
2677
+ self._tick_position = 'bottom'
2678
+ self.offsetText.set_verticalalignment('top')
2679
+ elif position == 'both':
2680
+ self.set_tick_params(which='both', top=True,
2681
+ bottom=True)
2682
+ elif position == 'none':
2683
+ self.set_tick_params(which='both', top=False,
2684
+ bottom=False)
2685
+ elif position == 'default':
2686
+ self.set_tick_params(which='both', top=True, labeltop=False,
2687
+ bottom=True, labelbottom=True)
2688
+ self._tick_position = 'bottom'
2689
+ self.offsetText.set_verticalalignment('top')
2690
+ else:
2691
+ _api.check_in_list(['top', 'bottom', 'both', 'default', 'none'],
2692
+ position=position)
2693
+ self.stale = True
2694
+
2695
+ def tick_top(self):
2696
+ """
2697
+ Move ticks and ticklabels (if present) to the top of the Axes.
2698
+ """
2699
+ label = True
2700
+ if 'label1On' in self._major_tick_kw:
2701
+ label = (self._major_tick_kw['label1On']
2702
+ or self._major_tick_kw['label2On'])
2703
+ self.set_ticks_position('top')
2704
+ # If labels were turned off before this was called, leave them off.
2705
+ self.set_tick_params(which='both', labeltop=label)
2706
+
2707
+ def tick_bottom(self):
2708
+ """
2709
+ Move ticks and ticklabels (if present) to the bottom of the Axes.
2710
+ """
2711
+ label = True
2712
+ if 'label1On' in self._major_tick_kw:
2713
+ label = (self._major_tick_kw['label1On']
2714
+ or self._major_tick_kw['label2On'])
2715
+ self.set_ticks_position('bottom')
2716
+ # If labels were turned off before this was called, leave them off.
2717
+ self.set_tick_params(which='both', labelbottom=label)
2718
+
2719
+ def get_ticks_position(self):
2720
+ """
2721
+ Return the ticks position ("top", "bottom", "default", or "unknown").
2722
+ """
2723
+ return {1: "bottom", 2: "top",
2724
+ "default": "default", "unknown": "unknown"}[
2725
+ self._get_ticks_position()]
2726
+
2727
+ get_view_interval, set_view_interval = _make_getset_interval(
2728
+ "view", "viewLim", "intervalx")
2729
+ get_data_interval, set_data_interval = _make_getset_interval(
2730
+ "data", "dataLim", "intervalx")
2731
+
2732
+ def get_minpos(self):
2733
+ return self.axes.dataLim.minposx
2734
+
2735
+ def set_default_intervals(self):
2736
+ # docstring inherited
2737
+ # only change view if dataLim has not changed and user has
2738
+ # not changed the view:
2739
+ if (not self.axes.dataLim.mutatedx() and
2740
+ not self.axes.viewLim.mutatedx()):
2741
+ if self._converter is not None:
2742
+ info = self._converter.axisinfo(self.units, self)
2743
+ if info.default_limits is not None:
2744
+ xmin, xmax = self.convert_units(info.default_limits)
2745
+ self.axes.viewLim.intervalx = xmin, xmax
2746
+ self.stale = True
2747
+
2748
+ def get_tick_space(self):
2749
+ ends = mtransforms.Bbox.unit().transformed(
2750
+ self.axes.transAxes - self.get_figure(root=False).dpi_scale_trans)
2751
+ length = ends.width * 72
2752
+ # There is a heuristic here that the aspect ratio of tick text
2753
+ # is no more than 3:1
2754
+ size = self._get_tick_label_size('x') * 3
2755
+ if size > 0:
2756
+ return int(np.floor(length / size))
2757
+ else:
2758
+ return 2**31 - 1
2759
+
2760
+
2761
+ class YAxis(Axis):
2762
+ __name__ = 'yaxis'
2763
+ axis_name = 'y' #: Read-only name identifying the axis.
2764
+ _tick_class = YTick
2765
+
2766
+ def __init__(self, *args, **kwargs):
2767
+ super().__init__(*args, **kwargs)
2768
+ self._init()
2769
+
2770
+ def _init(self):
2771
+ """
2772
+ Initialize the label and offsetText instance values and
2773
+ `label_position` / `offset_text_position`.
2774
+ """
2775
+ # x in display coords, y in axes coords (to be updated at draw time by
2776
+ # _update_label_positions and _update_offset_text_position).
2777
+ self.label.set(
2778
+ x=0, y=0.5,
2779
+ verticalalignment='bottom', horizontalalignment='center',
2780
+ rotation='vertical', rotation_mode='anchor',
2781
+ transform=mtransforms.blended_transform_factory(
2782
+ mtransforms.IdentityTransform(), self.axes.transAxes),
2783
+ )
2784
+ self.label_position = 'left'
2785
+
2786
+ if mpl.rcParams['ytick.labelcolor'] == 'inherit':
2787
+ tick_color = mpl.rcParams['ytick.color']
2788
+ else:
2789
+ tick_color = mpl.rcParams['ytick.labelcolor']
2790
+
2791
+ # x in axes coords, y in display coords(!).
2792
+ self.offsetText.set(
2793
+ x=0, y=0.5,
2794
+ verticalalignment='baseline', horizontalalignment='left',
2795
+ transform=mtransforms.blended_transform_factory(
2796
+ self.axes.transAxes, mtransforms.IdentityTransform()),
2797
+ fontsize=mpl.rcParams['ytick.labelsize'],
2798
+ color=tick_color
2799
+ )
2800
+ self.offset_text_position = 'left'
2801
+
2802
+ def contains(self, mouseevent):
2803
+ # docstring inherited
2804
+ if self._different_canvas(mouseevent):
2805
+ return False, {}
2806
+ x, y = mouseevent.x, mouseevent.y
2807
+ try:
2808
+ trans = self.axes.transAxes.inverted()
2809
+ xaxes, yaxes = trans.transform((x, y))
2810
+ except ValueError:
2811
+ return False, {}
2812
+ (l, b), (r, t) = self.axes.transAxes.transform([(0, 0), (1, 1)])
2813
+ inaxis = 0 <= yaxes <= 1 and (
2814
+ l - self._pickradius < x < l or
2815
+ r < x < r + self._pickradius)
2816
+ return inaxis, {}
2817
+
2818
+ def set_label_position(self, position):
2819
+ """
2820
+ Set the label position (left or right)
2821
+
2822
+ Parameters
2823
+ ----------
2824
+ position : {'left', 'right'}
2825
+ """
2826
+ self.label.set_rotation_mode('anchor')
2827
+ self.label.set_verticalalignment(_api.getitem_checked({
2828
+ 'left': 'bottom', 'right': 'top',
2829
+ }, position=position))
2830
+ self.label_position = position
2831
+ self.stale = True
2832
+
2833
+ def _update_label_position(self, renderer):
2834
+ """
2835
+ Update the label position based on the bounding box enclosing
2836
+ all the ticklabels and axis spine
2837
+ """
2838
+ if not self._autolabelpos:
2839
+ return
2840
+
2841
+ # get bounding boxes for this axis and any siblings
2842
+ # that have been set by `fig.align_ylabels()`
2843
+ bboxes, bboxes2 = self._get_tick_boxes_siblings(renderer=renderer)
2844
+ x, y = self.label.get_position()
2845
+
2846
+ if self.label_position == 'left':
2847
+ # Union with extents of the left spine if present, of the axes otherwise.
2848
+ bbox = mtransforms.Bbox.union([
2849
+ *bboxes, self.axes.spines.get("left", self.axes).get_window_extent()])
2850
+ self.label.set_position(
2851
+ (bbox.x0 - self.labelpad * self.get_figure(root=True).dpi / 72, y))
2852
+ else:
2853
+ # Union with extents of the right spine if present, of the axes otherwise.
2854
+ bbox = mtransforms.Bbox.union([
2855
+ *bboxes2, self.axes.spines.get("right", self.axes).get_window_extent()])
2856
+ self.label.set_position(
2857
+ (bbox.x1 + self.labelpad * self.get_figure(root=True).dpi / 72, y))
2858
+
2859
+ def _update_offset_text_position(self, bboxes, bboxes2):
2860
+ """
2861
+ Update the offset_text position based on the sequence of bounding
2862
+ boxes of all the ticklabels
2863
+ """
2864
+ x, _ = self.offsetText.get_position()
2865
+ if 'outline' in self.axes.spines:
2866
+ # Special case for colorbars:
2867
+ bbox = self.axes.spines['outline'].get_window_extent()
2868
+ else:
2869
+ bbox = self.axes.bbox
2870
+ top = bbox.ymax
2871
+ self.offsetText.set_position(
2872
+ (x, top + self.OFFSETTEXTPAD * self.get_figure(root=True).dpi / 72)
2873
+ )
2874
+
2875
+ def set_offset_position(self, position):
2876
+ """
2877
+ Parameters
2878
+ ----------
2879
+ position : {'left', 'right'}
2880
+ """
2881
+ x, y = self.offsetText.get_position()
2882
+ x = _api.getitem_checked({'left': 0, 'right': 1}, position=position)
2883
+
2884
+ self.offsetText.set_ha(position)
2885
+ self.offsetText.set_position((x, y))
2886
+ self.stale = True
2887
+
2888
+ def set_ticks_position(self, position):
2889
+ """
2890
+ Set the ticks position.
2891
+
2892
+ Parameters
2893
+ ----------
2894
+ position : {'left', 'right', 'both', 'default', 'none'}
2895
+ 'both' sets the ticks to appear on both positions, but does not
2896
+ change the tick labels. 'default' resets the tick positions to
2897
+ the default: ticks on both positions, labels at left. 'none'
2898
+ can be used if you don't want any ticks. 'none' and 'both'
2899
+ affect only the ticks, not the labels.
2900
+ """
2901
+ if position == 'right':
2902
+ self.set_tick_params(which='both', right=True, labelright=True,
2903
+ left=False, labelleft=False)
2904
+ self.set_offset_position(position)
2905
+ elif position == 'left':
2906
+ self.set_tick_params(which='both', right=False, labelright=False,
2907
+ left=True, labelleft=True)
2908
+ self.set_offset_position(position)
2909
+ elif position == 'both':
2910
+ self.set_tick_params(which='both', right=True,
2911
+ left=True)
2912
+ elif position == 'none':
2913
+ self.set_tick_params(which='both', right=False,
2914
+ left=False)
2915
+ elif position == 'default':
2916
+ self.set_tick_params(which='both', right=True, labelright=False,
2917
+ left=True, labelleft=True)
2918
+ else:
2919
+ _api.check_in_list(['left', 'right', 'both', 'default', 'none'],
2920
+ position=position)
2921
+ self.stale = True
2922
+
2923
+ def tick_right(self):
2924
+ """
2925
+ Move ticks and ticklabels (if present) to the right of the Axes.
2926
+ """
2927
+ label = True
2928
+ if 'label1On' in self._major_tick_kw:
2929
+ label = (self._major_tick_kw['label1On']
2930
+ or self._major_tick_kw['label2On'])
2931
+ self.set_ticks_position('right')
2932
+ # if labels were turned off before this was called
2933
+ # leave them off
2934
+ self.set_tick_params(which='both', labelright=label)
2935
+
2936
+ def tick_left(self):
2937
+ """
2938
+ Move ticks and ticklabels (if present) to the left of the Axes.
2939
+ """
2940
+ label = True
2941
+ if 'label1On' in self._major_tick_kw:
2942
+ label = (self._major_tick_kw['label1On']
2943
+ or self._major_tick_kw['label2On'])
2944
+ self.set_ticks_position('left')
2945
+ # if labels were turned off before this was called
2946
+ # leave them off
2947
+ self.set_tick_params(which='both', labelleft=label)
2948
+
2949
+ def get_ticks_position(self):
2950
+ """
2951
+ Return the ticks position ("left", "right", "default", or "unknown").
2952
+ """
2953
+ return {1: "left", 2: "right",
2954
+ "default": "default", "unknown": "unknown"}[
2955
+ self._get_ticks_position()]
2956
+
2957
+ get_view_interval, set_view_interval = _make_getset_interval(
2958
+ "view", "viewLim", "intervaly")
2959
+ get_data_interval, set_data_interval = _make_getset_interval(
2960
+ "data", "dataLim", "intervaly")
2961
+
2962
+ def get_minpos(self):
2963
+ return self.axes.dataLim.minposy
2964
+
2965
+ def set_default_intervals(self):
2966
+ # docstring inherited
2967
+ # only change view if dataLim has not changed and user has
2968
+ # not changed the view:
2969
+ if (not self.axes.dataLim.mutatedy() and
2970
+ not self.axes.viewLim.mutatedy()):
2971
+ if self._converter is not None:
2972
+ info = self._converter.axisinfo(self.units, self)
2973
+ if info.default_limits is not None:
2974
+ ymin, ymax = self.convert_units(info.default_limits)
2975
+ self.axes.viewLim.intervaly = ymin, ymax
2976
+ self.stale = True
2977
+
2978
+ def get_tick_space(self):
2979
+ ends = mtransforms.Bbox.unit().transformed(
2980
+ self.axes.transAxes - self.get_figure(root=False).dpi_scale_trans)
2981
+ length = ends.height * 72
2982
+ # Having a spacing of at least 2 just looks good.
2983
+ size = self._get_tick_label_size('y') * 2
2984
+ if size > 0:
2985
+ return int(np.floor(length / size))
2986
+ else:
2987
+ return 2**31 - 1
2988
+
2989
+
2990
+ from . import axis as _rs_axis # noqa: E402
2991
+ _rs_axis._rs_other_axis_classes.append(Axis)