ultraplot 0.99.3__py3-none-any.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.
- ultraplot/__init__.py +115 -0
- ultraplot/__init__.py.rej +58 -0
- ultraplot/axes/__init__.py +42 -0
- ultraplot/axes/base.py +3240 -0
- ultraplot/axes/cartesian.py +1425 -0
- ultraplot/axes/geo.py +1675 -0
- ultraplot/axes/plot.py +4569 -0
- ultraplot/axes/polar.py +381 -0
- ultraplot/axes/shared.py +186 -0
- ultraplot/axes/three.py +34 -0
- ultraplot/cmaps/Algae.rgb +256 -0
- ultraplot/cmaps/Amp.rgb +256 -0
- ultraplot/cmaps/BR.rgb +256 -0
- ultraplot/cmaps/Balance.rgb +256 -0
- ultraplot/cmaps/Blues1_r.xml +17 -0
- ultraplot/cmaps/Blues2.xml +16 -0
- ultraplot/cmaps/Blues3.xml +25 -0
- ultraplot/cmaps/Blues4_r.xml +17 -0
- ultraplot/cmaps/Blues5.xml +16 -0
- ultraplot/cmaps/Blues6.xml +25 -0
- ultraplot/cmaps/Blues7.xml +16 -0
- ultraplot/cmaps/Blues8.xml +17 -0
- ultraplot/cmaps/Blues9.xml +1 -0
- ultraplot/cmaps/Boreal.json +53 -0
- ultraplot/cmaps/Browns1.xml +16 -0
- ultraplot/cmaps/Browns2.xml +26 -0
- ultraplot/cmaps/Browns3.xml +17 -0
- ultraplot/cmaps/Browns4.xml +17 -0
- ultraplot/cmaps/Browns5.xml +26 -0
- ultraplot/cmaps/Browns6.xml +17 -0
- ultraplot/cmaps/Browns7.xml +19 -0
- ultraplot/cmaps/Browns8.xml +11 -0
- ultraplot/cmaps/Browns9.xml +1 -0
- ultraplot/cmaps/ColdHot.rgb +229 -0
- ultraplot/cmaps/Crest.rgb +256 -0
- ultraplot/cmaps/Curl.rgb +512 -0
- ultraplot/cmaps/Deep.rgb +256 -0
- ultraplot/cmaps/Delta.rgb +512 -0
- ultraplot/cmaps/Dense.rgb +256 -0
- ultraplot/cmaps/Div.json +71 -0
- ultraplot/cmaps/DryWet.json +73 -0
- ultraplot/cmaps/Dusk.json +53 -0
- ultraplot/cmaps/Fire.json +53 -0
- ultraplot/cmaps/Flare.rgb +256 -0
- ultraplot/cmaps/Glacial.json +53 -0
- ultraplot/cmaps/Greens1_r.xml +26 -0
- ultraplot/cmaps/Greens2.xml +28 -0
- ultraplot/cmaps/Greens3_r.xml +28 -0
- ultraplot/cmaps/Greens4.xml +17 -0
- ultraplot/cmaps/Greens5.xml +16 -0
- ultraplot/cmaps/Greens6_r.xml +16 -0
- ultraplot/cmaps/Greens7.xml +16 -0
- ultraplot/cmaps/Greens8.xml +26 -0
- ultraplot/cmaps/Haline.rgb +256 -0
- ultraplot/cmaps/Ice.rgb +256 -0
- ultraplot/cmaps/IceFire.rgb +256 -0
- ultraplot/cmaps/Mako.rgb +256 -0
- ultraplot/cmaps/Marine.json +53 -0
- ultraplot/cmaps/Matter.rgb +256 -0
- ultraplot/cmaps/Mono.txt +256 -0
- ultraplot/cmaps/MonoCycle.txt +256 -0
- ultraplot/cmaps/NegPos.json +71 -0
- ultraplot/cmaps/Oranges1.xml +27 -0
- ultraplot/cmaps/Oranges2.xml +26 -0
- ultraplot/cmaps/Oranges3.xml +15 -0
- ultraplot/cmaps/Oranges4.xml +23 -0
- ultraplot/cmaps/Oxy.rgb +256 -0
- ultraplot/cmaps/Phase.rgb +256 -0
- ultraplot/cmaps/Purples1_r.xml +16 -0
- ultraplot/cmaps/Purples2.xml +17 -0
- ultraplot/cmaps/Purples3.xml +18 -0
- ultraplot/cmaps/Reds1.xml +26 -0
- ultraplot/cmaps/Reds2.xml +22 -0
- ultraplot/cmaps/Reds3.xml +23 -0
- ultraplot/cmaps/Reds4.xml +26 -0
- ultraplot/cmaps/Reds5.xml +17 -0
- ultraplot/cmaps/Rocket.rgb +256 -0
- ultraplot/cmaps/Solar.rgb +256 -0
- ultraplot/cmaps/Speed.rgb +256 -0
- ultraplot/cmaps/Stellar.json +53 -0
- ultraplot/cmaps/Sunrise.json +53 -0
- ultraplot/cmaps/Sunset.json +53 -0
- ultraplot/cmaps/Tempo.rgb +256 -0
- ultraplot/cmaps/Thermal.rgb +256 -0
- ultraplot/cmaps/Turbid.rgb +256 -0
- ultraplot/cmaps/Vivid.xml +11 -0
- ultraplot/cmaps/Vlag.rgb +256 -0
- ultraplot/cmaps/Yellows1.xml +17 -0
- ultraplot/cmaps/Yellows2.xml +17 -0
- ultraplot/cmaps/Yellows3.xml +17 -0
- ultraplot/cmaps/Yellows4.xml +17 -0
- ultraplot/cmaps/acton.txt +256 -0
- ultraplot/cmaps/bam.txt +256 -0
- ultraplot/cmaps/bamO.txt +256 -0
- ultraplot/cmaps/bamako.txt +256 -0
- ultraplot/cmaps/batlow.txt +256 -0
- ultraplot/cmaps/batlowK.txt +256 -0
- ultraplot/cmaps/batlowW.txt +256 -0
- ultraplot/cmaps/berlin.txt +256 -0
- ultraplot/cmaps/bilbao.txt +256 -0
- ultraplot/cmaps/broc.txt +256 -0
- ultraplot/cmaps/brocO.txt +256 -0
- ultraplot/cmaps/buda.txt +256 -0
- ultraplot/cmaps/bukavu.txt +256 -0
- ultraplot/cmaps/cork.txt +256 -0
- ultraplot/cmaps/corkO.txt +256 -0
- ultraplot/cmaps/davos.txt +256 -0
- ultraplot/cmaps/devon.txt +256 -0
- ultraplot/cmaps/fes.txt +256 -0
- ultraplot/cmaps/hawaii.txt +256 -0
- ultraplot/cmaps/imola.txt +256 -0
- ultraplot/cmaps/lajolla.txt +256 -0
- ultraplot/cmaps/lapaz.txt +256 -0
- ultraplot/cmaps/lisbon.txt +256 -0
- ultraplot/cmaps/nuuk.txt +256 -0
- ultraplot/cmaps/oleron.txt +256 -0
- ultraplot/cmaps/oslo.txt +256 -0
- ultraplot/cmaps/roma.txt +256 -0
- ultraplot/cmaps/romaO.txt +256 -0
- ultraplot/cmaps/tofino.txt +256 -0
- ultraplot/cmaps/tokyo.txt +256 -0
- ultraplot/cmaps/turku.txt +256 -0
- ultraplot/cmaps/vanimo.txt +256 -0
- ultraplot/cmaps/vik.txt +256 -0
- ultraplot/cmaps/vikO.txt +256 -0
- ultraplot/colors/opencolor.txt +132 -0
- ultraplot/colors/xkcd.txt +951 -0
- ultraplot/colors.py +3241 -0
- ultraplot/colors.py.rej +243 -0
- ultraplot/config.py +1809 -0
- ultraplot/constructor.py +1633 -0
- ultraplot/cycles/538.hex +2 -0
- ultraplot/cycles/FlatUI.hex +1 -0
- ultraplot/cycles/Qual1.rgb +7 -0
- ultraplot/cycles/Qual2.rgb +13 -0
- ultraplot/cycles/bmh.hex +2 -0
- ultraplot/cycles/classic.hex +2 -0
- ultraplot/cycles/colorblind.hex +2 -0
- ultraplot/cycles/colorblind10.hex +2 -0
- ultraplot/cycles/default.hex +2 -0
- ultraplot/cycles/ggplot.hex +1 -0
- ultraplot/cycles/seaborn.hex +2 -0
- ultraplot/cycles/tableau.hex +2 -0
- ultraplot/demos.py +1201 -0
- ultraplot/externals/__init__.py +5 -0
- ultraplot/externals/hsluv.py +330 -0
- ultraplot/figure.py +2102 -0
- ultraplot/fonts/FiraMath-Bold.ttf +0 -0
- ultraplot/fonts/FiraMath-ExtraLight.ttf +0 -0
- ultraplot/fonts/FiraMath-Heavy.ttf +0 -0
- ultraplot/fonts/FiraMath-Light.ttf +0 -0
- ultraplot/fonts/FiraMath-Medium.ttf +0 -0
- ultraplot/fonts/FiraMath-Regular.ttf +0 -0
- ultraplot/fonts/FiraMath-SemiBold.ttf +0 -0
- ultraplot/fonts/FiraMath-UltraLight.ttf +0 -0
- ultraplot/fonts/FiraSans-Black.ttf +0 -0
- ultraplot/fonts/FiraSans-BlackItalic.ttf +0 -0
- ultraplot/fonts/FiraSans-Bold.ttf +0 -0
- ultraplot/fonts/FiraSans-BoldItalic.ttf +0 -0
- ultraplot/fonts/FiraSans-ExtraBold.ttf +0 -0
- ultraplot/fonts/FiraSans-ExtraBoldItalic.ttf +0 -0
- ultraplot/fonts/FiraSans-ExtraLight.ttf +0 -0
- ultraplot/fonts/FiraSans-ExtraLightItalic.ttf +0 -0
- ultraplot/fonts/FiraSans-Italic.ttf +0 -0
- ultraplot/fonts/FiraSans-Light.ttf +0 -0
- ultraplot/fonts/FiraSans-LightItalic.ttf +0 -0
- ultraplot/fonts/FiraSans-Medium.ttf +0 -0
- ultraplot/fonts/FiraSans-MediumItalic.ttf +0 -0
- ultraplot/fonts/FiraSans-Regular.ttf +0 -0
- ultraplot/fonts/FiraSans-SemiBold.ttf +0 -0
- ultraplot/fonts/FiraSans-SemiBoldItalic.ttf +0 -0
- ultraplot/fonts/LICENSE_FIRAMATH.txt +92 -0
- ultraplot/fonts/LICENSE_FIRASANS.txt +97 -0
- ultraplot/fonts/LICENSE_NOTOSANS.txt +202 -0
- ultraplot/fonts/LICENSE_NOTOSERIF.txt +93 -0
- ultraplot/fonts/LICENSE_OPENSANS.txt +202 -0
- ultraplot/fonts/LICENSE_ROBOTO.txt +202 -0
- ultraplot/fonts/LICENSE_SOURCESANS.txt +93 -0
- ultraplot/fonts/LICENSE_SOURCESERIF.txt +93 -0
- ultraplot/fonts/LICENSE_TEXGYRE.txt +29 -0
- ultraplot/fonts/LICENSE_UBUNTU.txt +96 -0
- ultraplot/fonts/NotoSans-Bold.ttf +0 -0
- ultraplot/fonts/NotoSans-BoldItalic.ttf +0 -0
- ultraplot/fonts/NotoSans-Italic.ttf +0 -0
- ultraplot/fonts/NotoSans-Regular.ttf +0 -0
- ultraplot/fonts/NotoSerif-Bold.ttf +0 -0
- ultraplot/fonts/NotoSerif-BoldItalic.ttf +0 -0
- ultraplot/fonts/NotoSerif-Italic.ttf +0 -0
- ultraplot/fonts/NotoSerif-Regular.ttf +0 -0
- ultraplot/fonts/OpenSans-Bold.ttf +0 -0
- ultraplot/fonts/OpenSans-BoldItalic.ttf +0 -0
- ultraplot/fonts/OpenSans-Italic.ttf +0 -0
- ultraplot/fonts/OpenSans-Regular.ttf +0 -0
- ultraplot/fonts/OpenSans-Semibold.ttf +0 -0
- ultraplot/fonts/OpenSans-SemiboldItalic.ttf +0 -0
- ultraplot/fonts/Roboto-Black.ttf +0 -0
- ultraplot/fonts/Roboto-BlackItalic.ttf +0 -0
- ultraplot/fonts/Roboto-Bold.ttf +0 -0
- ultraplot/fonts/Roboto-BoldItalic.ttf +0 -0
- ultraplot/fonts/Roboto-Italic.ttf +0 -0
- ultraplot/fonts/Roboto-Light.ttf +0 -0
- ultraplot/fonts/Roboto-LightItalic.ttf +0 -0
- ultraplot/fonts/Roboto-Medium.ttf +0 -0
- ultraplot/fonts/Roboto-MediumItalic.ttf +0 -0
- ultraplot/fonts/Roboto-Regular.ttf +0 -0
- ultraplot/fonts/SourceSansPro-Black.ttf +0 -0
- ultraplot/fonts/SourceSansPro-BlackItalic.ttf +0 -0
- ultraplot/fonts/SourceSansPro-Bold.ttf +0 -0
- ultraplot/fonts/SourceSansPro-BoldItalic.ttf +0 -0
- ultraplot/fonts/SourceSansPro-ExtraLight.ttf +0 -0
- ultraplot/fonts/SourceSansPro-ExtraLightItalic.ttf +0 -0
- ultraplot/fonts/SourceSansPro-Italic.ttf +0 -0
- ultraplot/fonts/SourceSansPro-Light.ttf +0 -0
- ultraplot/fonts/SourceSansPro-LightItalic.ttf +0 -0
- ultraplot/fonts/SourceSansPro-Regular.ttf +0 -0
- ultraplot/fonts/SourceSansPro-SemiBold.ttf +0 -0
- ultraplot/fonts/SourceSansPro-SemiBoldItalic.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-Black.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-BlackItalic.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-Bold.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-BoldItalic.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-ExtraLight.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-ExtraLightItalic.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-Italic.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-Light.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-LightItalic.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-Regular.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-SemiBold.ttf +0 -0
- ultraplot/fonts/SourceSerifPro-SemiBoldItalic.ttf +0 -0
- ultraplot/fonts/Ubuntu-Bold.ttf +0 -0
- ultraplot/fonts/Ubuntu-BoldItalic.ttf +0 -0
- ultraplot/fonts/Ubuntu-Italic.ttf +0 -0
- ultraplot/fonts/Ubuntu-Light.ttf +0 -0
- ultraplot/fonts/Ubuntu-LightItalic.ttf +0 -0
- ultraplot/fonts/Ubuntu-Medium.ttf +0 -0
- ultraplot/fonts/Ubuntu-MediumItalic.ttf +0 -0
- ultraplot/fonts/Ubuntu-Regular.ttf +0 -0
- ultraplot/fonts/texgyreadventor-bold.ttf +0 -0
- ultraplot/fonts/texgyreadventor-bolditalic.ttf +0 -0
- ultraplot/fonts/texgyreadventor-italic.ttf +0 -0
- ultraplot/fonts/texgyreadventor-regular.ttf +0 -0
- ultraplot/fonts/texgyrebonum-bold.ttf +0 -0
- ultraplot/fonts/texgyrebonum-bolditalic.ttf +0 -0
- ultraplot/fonts/texgyrebonum-italic.ttf +0 -0
- ultraplot/fonts/texgyrebonum-regular.ttf +0 -0
- ultraplot/fonts/texgyrechorus-mediumitalic.ttf +0 -0
- ultraplot/fonts/texgyrecursor-bold.ttf +0 -0
- ultraplot/fonts/texgyrecursor-bolditalic.ttf +0 -0
- ultraplot/fonts/texgyrecursor-italic.ttf +0 -0
- ultraplot/fonts/texgyrecursor-regular.ttf +0 -0
- ultraplot/fonts/texgyreheros-bold.ttf +0 -0
- ultraplot/fonts/texgyreheros-bolditalic.ttf +0 -0
- ultraplot/fonts/texgyreheros-italic.ttf +0 -0
- ultraplot/fonts/texgyreheros-regular.ttf +0 -0
- ultraplot/fonts/texgyrepagella-bold.ttf +0 -0
- ultraplot/fonts/texgyrepagella-bolditalic.ttf +0 -0
- ultraplot/fonts/texgyrepagella-italic.ttf +0 -0
- ultraplot/fonts/texgyrepagella-regular.ttf +0 -0
- ultraplot/fonts/texgyreschola-bold.ttf +0 -0
- ultraplot/fonts/texgyreschola-bolditalic.ttf +0 -0
- ultraplot/fonts/texgyreschola-italic.ttf +0 -0
- ultraplot/fonts/texgyreschola-regular.ttf +0 -0
- ultraplot/fonts/texgyretermes-bold.ttf +0 -0
- ultraplot/fonts/texgyretermes-bolditalic.ttf +0 -0
- ultraplot/fonts/texgyretermes-italic.ttf +0 -0
- ultraplot/fonts/texgyretermes-regular.ttf +0 -0
- ultraplot/gridspec.py +1698 -0
- ultraplot/internals/__init__.py +529 -0
- ultraplot/internals/benchmarks.py +26 -0
- ultraplot/internals/context.py +44 -0
- ultraplot/internals/docstring.py +139 -0
- ultraplot/internals/fonts.py +75 -0
- ultraplot/internals/guides.py +167 -0
- ultraplot/internals/inputs.py +862 -0
- ultraplot/internals/labels.py +85 -0
- ultraplot/internals/rcsetup.py +1933 -0
- ultraplot/internals/versions.py +61 -0
- ultraplot/internals/warnings.py +122 -0
- ultraplot/proj.py +325 -0
- ultraplot/scale.py +966 -0
- ultraplot/tests/__init__.py +28 -0
- ultraplot/tests/baseline/test_align_labels.png +0 -0
- ultraplot/tests/baseline/test_aligned_outer_guides.png +0 -0
- ultraplot/tests/baseline/test_aspect_ratios.png +0 -0
- ultraplot/tests/baseline/test_auto_diverging1.png +0 -0
- ultraplot/tests/baseline/test_auto_legend.png +0 -0
- ultraplot/tests/baseline/test_auto_reverse.png +0 -0
- ultraplot/tests/baseline/test_autodiverging3.png +0 -0
- ultraplot/tests/baseline/test_autodiverging4.png +0 -0
- ultraplot/tests/baseline/test_autodiverging5.png +0 -0
- ultraplot/tests/baseline/test_axes_colors.png +0 -0
- ultraplot/tests/baseline/test_bar_vectors.png +0 -0
- ultraplot/tests/baseline/test_bar_width.png +0 -0
- ultraplot/tests/baseline/test_both_ticklabels.png +0 -0
- ultraplot/tests/baseline/test_bounds_ticks.png +0 -0
- ultraplot/tests/baseline/test_boxplot_colors.png +0 -0
- ultraplot/tests/baseline/test_boxplot_vectors.png +0 -0
- ultraplot/tests/baseline/test_cartopy_contours.png +0 -0
- ultraplot/tests/baseline/test_cartopy_labels.png +0 -0
- ultraplot/tests/baseline/test_cartopy_manual.png +0 -0
- ultraplot/tests/baseline/test_centered_legends.png +0 -0
- ultraplot/tests/baseline/test_cmap_cycles.png +0 -0
- ultraplot/tests/baseline/test_colorbar.png +0 -0
- ultraplot/tests/baseline/test_colorbar_ticks.png +0 -0
- ultraplot/tests/baseline/test_colormap_mode.png +0 -0
- ultraplot/tests/baseline/test_column_iteration.png +0 -0
- ultraplot/tests/baseline/test_complex_ticks.png +0 -0
- ultraplot/tests/baseline/test_contour_labels.png +0 -0
- ultraplot/tests/baseline/test_contour_legend_with_label.png +0 -0
- ultraplot/tests/baseline/test_contour_legend_without_label.png +0 -0
- ultraplot/tests/baseline/test_contour_negative.png +0 -0
- ultraplot/tests/baseline/test_contour_single.png +0 -0
- ultraplot/tests/baseline/test_cutoff_ticks.png +0 -0
- ultraplot/tests/baseline/test_data_keyword.png +0 -0
- ultraplot/tests/baseline/test_discrete_ticks.png +0 -0
- ultraplot/tests/baseline/test_discrete_vs_fixed.png +0 -0
- ultraplot/tests/baseline/test_drawing_in_projection_with_globe.png +0 -0
- ultraplot/tests/baseline/test_drawing_in_projection_without_globe.png +0 -0
- ultraplot/tests/baseline/test_edge_fix.png +0 -0
- ultraplot/tests/baseline/test_flow_functions.png +0 -0
- ultraplot/tests/baseline/test_font_adjustments.png +0 -0
- ultraplot/tests/baseline/test_geographic_multiple_projections.png +0 -0
- ultraplot/tests/baseline/test_geographic_single_projection.png +0 -0
- ultraplot/tests/baseline/test_gray_adjustment.png +0 -0
- ultraplot/tests/baseline/test_histogram_legend.png +0 -0
- ultraplot/tests/baseline/test_histogram_types.png +0 -0
- ultraplot/tests/baseline/test_ignore_message.png +0 -0
- ultraplot/tests/baseline/test_inbounds_data.png +0 -0
- ultraplot/tests/baseline/test_init_format.png +0 -0
- ultraplot/tests/baseline/test_inner_title_zorder.png +0 -0
- ultraplot/tests/baseline/test_inset_basic.png +0 -0
- ultraplot/tests/baseline/test_inset_colorbars.png +0 -0
- ultraplot/tests/baseline/test_inset_colors_1.png +0 -0
- ultraplot/tests/baseline/test_inset_colors_2.png +0 -0
- ultraplot/tests/baseline/test_inset_zoom_update.png +0 -0
- ultraplot/tests/baseline/test_invalid_dist.png +0 -0
- ultraplot/tests/baseline/test_invalid_plot.png +0 -0
- ultraplot/tests/baseline/test_keep_guide_labels.png +0 -0
- ultraplot/tests/baseline/test_label_settings.png +0 -0
- ultraplot/tests/baseline/test_level_restriction.png +0 -0
- ultraplot/tests/baseline/test_levels_with_vmin_vmax.png +0 -0
- ultraplot/tests/baseline/test_locale_formatting.png +0 -0
- ultraplot/tests/baseline/test_locale_formatting_en_US.UTF-8.png +0 -0
- ultraplot/tests/baseline/test_manual_labels.png +0 -0
- ultraplot/tests/baseline/test_multi_formatting.png +0 -0
- ultraplot/tests/baseline/test_multiple_calls.png +0 -0
- ultraplot/tests/baseline/test_on_the_fly_mappable.png +0 -0
- ultraplot/tests/baseline/test_outer_align.png +0 -0
- ultraplot/tests/baseline/test_panel_dist.png +0 -0
- ultraplot/tests/baseline/test_panels_suplabels_three_hor_panels.png +0 -0
- ultraplot/tests/baseline/test_panels_with_sharing.png +0 -0
- ultraplot/tests/baseline/test_panels_without_sharing_1.png +0 -0
- ultraplot/tests/baseline/test_panels_without_sharing_2.png +0 -0
- ultraplot/tests/baseline/test_parametric_colors.png +0 -0
- ultraplot/tests/baseline/test_parametric_labels.png +0 -0
- ultraplot/tests/baseline/test_patch_format.png +0 -0
- ultraplot/tests/baseline/test_pie_charts.png +0 -0
- ultraplot/tests/baseline/test_pint_quantities.png +0 -0
- ultraplot/tests/baseline/test_polar_projections.png +0 -0
- ultraplot/tests/baseline/test_projection_dicts.png +0 -0
- ultraplot/tests/baseline/test_qualitative_colormaps_1.png +0 -0
- ultraplot/tests/baseline/test_qualitative_colormaps_2.png +0 -0
- ultraplot/tests/baseline/test_reversed_levels.png +0 -0
- ultraplot/tests/baseline/test_scatter_alpha.png +0 -0
- ultraplot/tests/baseline/test_scatter_args.png +0 -0
- ultraplot/tests/baseline/test_scatter_cycle.png +0 -0
- ultraplot/tests/baseline/test_scatter_inbounds.png +0 -0
- ultraplot/tests/baseline/test_scatter_sizes.png +0 -0
- ultraplot/tests/baseline/test_seaborn_heatmap.png +0 -0
- ultraplot/tests/baseline/test_seaborn_hist.png +0 -0
- ultraplot/tests/baseline/test_seaborn_relational.png +0 -0
- ultraplot/tests/baseline/test_seaborn_swarmplot.png +0 -0
- ultraplot/tests/baseline/test_segmented_norm.png +0 -0
- ultraplot/tests/baseline/test_segmented_norm_ticks.png +0 -0
- ultraplot/tests/baseline/test_share_all_basic.png +0 -0
- ultraplot/tests/baseline/test_singleton_legend.png +0 -0
- ultraplot/tests/baseline/test_span_labels.png +0 -0
- ultraplot/tests/baseline/test_spine_offset.png +0 -0
- ultraplot/tests/baseline/test_spine_side.png +0 -0
- ultraplot/tests/baseline/test_standardized_input.png +0 -0
- ultraplot/tests/baseline/test_statistical_boxplot.png +0 -0
- ultraplot/tests/baseline/test_three_axes.png +0 -0
- ultraplot/tests/baseline/test_tick_direction.png +0 -0
- ultraplot/tests/baseline/test_tick_labels.png +0 -0
- ultraplot/tests/baseline/test_tick_length.png +0 -0
- ultraplot/tests/baseline/test_tick_width.png +0 -0
- ultraplot/tests/baseline/test_title_deflection.png +0 -0
- ultraplot/tests/baseline/test_triangular_functions.png +0 -0
- ultraplot/tests/baseline/test_tuple_handles.png +0 -0
- ultraplot/tests/baseline/test_twin_axes_1.png +0 -0
- ultraplot/tests/baseline/test_twin_axes_2.png +0 -0
- ultraplot/tests/baseline/test_twin_axes_3.png +0 -0
- ultraplot/tests/baseline/test_uneven_levels.png +0 -0
- ultraplot/tests/test_1dplots.py +373 -0
- ultraplot/tests/test_2dplots.py +354 -0
- ultraplot/tests/test_axes.py +179 -0
- ultraplot/tests/test_colorbar.py +253 -0
- ultraplot/tests/test_docs.py +78 -0
- ultraplot/tests/test_format.py +340 -0
- ultraplot/tests/test_geographic.py +116 -0
- ultraplot/tests/test_imshow.py +110 -0
- ultraplot/tests/test_inset.py +28 -0
- ultraplot/tests/test_integration.py +149 -0
- ultraplot/tests/test_legend.py +181 -0
- ultraplot/tests/test_projections.py +138 -0
- ultraplot/tests/test_statistical_plotting.py +77 -0
- ultraplot/tests/test_subplots.py +174 -0
- ultraplot/ticker.py +879 -0
- ultraplot/ui.py +233 -0
- ultraplot/utils.py +912 -0
- ultraplot-0.99.3.dist-info/LICENSE.txt +427 -0
- ultraplot-0.99.3.dist-info/METADATA +88 -0
- ultraplot-0.99.3.dist-info/RECORD +416 -0
- ultraplot-0.99.3.dist-info/WHEEL +5 -0
- ultraplot-0.99.3.dist-info/entry_points.txt +2 -0
- ultraplot-0.99.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1425 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
The standard Cartesian axes used for most ultraplot figures.
|
|
4
|
+
"""
|
|
5
|
+
import copy
|
|
6
|
+
import inspect
|
|
7
|
+
|
|
8
|
+
import matplotlib.dates as mdates
|
|
9
|
+
import matplotlib.ticker as mticker
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
from .. import constructor
|
|
13
|
+
from .. import scale as pscale
|
|
14
|
+
from .. import ticker as pticker
|
|
15
|
+
from ..config import rc
|
|
16
|
+
from ..internals import ic # noqa: F401
|
|
17
|
+
from ..internals import _not_none, _pop_rc, _version_mpl, docstring, labels, warnings
|
|
18
|
+
from . import plot, shared
|
|
19
|
+
|
|
20
|
+
__all__ = ["CartesianAxes"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Tuple of date converters
|
|
24
|
+
DATE_CONVERTERS = (mdates.DateConverter,)
|
|
25
|
+
if hasattr(mdates, "_SwitchableDateConverter"):
|
|
26
|
+
DATE_CONVERTERS += (mdates._SwitchableDateConverter,)
|
|
27
|
+
|
|
28
|
+
# Opposite side keywords
|
|
29
|
+
OPPOSITE_SIDE = {
|
|
30
|
+
"left": "right",
|
|
31
|
+
"right": "left",
|
|
32
|
+
"bottom": "top",
|
|
33
|
+
"top": "bottom",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# Format docstring
|
|
38
|
+
_format_docstring = """
|
|
39
|
+
aspect : {'auto', 'equal'} or float, optional
|
|
40
|
+
The data aspect ratio. See `~matplotlib.axes.Axes.set_aspect`
|
|
41
|
+
for details.
|
|
42
|
+
xlabel, ylabel : str, optional
|
|
43
|
+
The x and y axis labels. Applied with `~matplotlib.axes.Axes.set_xlabel`
|
|
44
|
+
and `~matplotlib.axes.Axes.set_ylabel`.
|
|
45
|
+
xlabel_kw, ylabel_kw : dict-like, optional
|
|
46
|
+
Additional axis label settings applied with `~matplotlib.axes.Axes.set_xlabel`
|
|
47
|
+
and `~matplotlib.axes.Axes.set_ylabel`. See also `labelpad`, `labelcolor`,
|
|
48
|
+
`labelsize`, and `labelweight` below.
|
|
49
|
+
xlim, ylim : 2-tuple of floats or None, optional
|
|
50
|
+
The x and y axis data limits. Applied with `~matplotlib.axes.Axes.set_xlim`
|
|
51
|
+
and `~matplotlib.axes.Axes.set_ylim`.
|
|
52
|
+
xmin, ymin : float, optional
|
|
53
|
+
The x and y minimum data limits. Useful if you do not want
|
|
54
|
+
to set the maximum limits.
|
|
55
|
+
xmax, ymax : float, optional
|
|
56
|
+
The x and y maximum data limits. Useful if you do not want
|
|
57
|
+
to set the minimum limits.
|
|
58
|
+
xreverse, yreverse : bool, optional
|
|
59
|
+
Whether to "reverse" the x and y axis direction. Makes the x and
|
|
60
|
+
y axes ascend left-to-right and top-to-bottom, respectively.
|
|
61
|
+
xscale, yscale : scale-spec, optional
|
|
62
|
+
The x and y axis scales. Passed to the `~ultraplot.scale.Scale` constructor.
|
|
63
|
+
For example, ``xscale='log'`` applies logarithmic scaling, and
|
|
64
|
+
``xscale=('cutoff', 100, 2)`` applies a `~ultraplot.scale.CutoffScale`.
|
|
65
|
+
xscale_kw, yscale_kw : dict-like, optional
|
|
66
|
+
The x and y axis scale settings. Passed to `~ultraplot.scale.Scale`.
|
|
67
|
+
xmargin, ymargin, margin : float, default: :rc:`margin`
|
|
68
|
+
The default margin between plotted content and the x and y axis spines in
|
|
69
|
+
axes-relative coordinates. This is useful if you don't witch to explicitly set
|
|
70
|
+
axis limits. Use the keyword `margin` to set both at once.
|
|
71
|
+
xbounds, ybounds : 2-tuple of float, optional
|
|
72
|
+
The x and y axis data bounds within which to draw the spines. For example,
|
|
73
|
+
``xlim=(0, 4)`` combined with ``xbounds=(2, 4)`` will prevent the spines
|
|
74
|
+
from meeting at the origin. This also applies ``xspineloc='bottom'`` and
|
|
75
|
+
``yspineloc='left'`` by default if both spines are currently visible.
|
|
76
|
+
xtickrange, ytickrange : 2-tuple of float, optional
|
|
77
|
+
The x and y axis data ranges within which major tick marks are labelled.
|
|
78
|
+
For example, ``xlim=(-5, 5)`` combined with ``xtickrange=(-1, 1)`` and a
|
|
79
|
+
tick interval of 1 will only label the ticks marks at -1, 0, and 1. See
|
|
80
|
+
`~ultraplot.ticker.AutoFormatter` for details.
|
|
81
|
+
xwraprange, ywraprange : 2-tuple of float, optional
|
|
82
|
+
The x and y axis data ranges with which major tick mark values are wrapped. For
|
|
83
|
+
example, ``xwraprange=(0, 3)`` causes the values 0 through 9 to be formatted as
|
|
84
|
+
0, 1, 2, 0, 1, 2, 0, 1, 2, 0. See `~ultraplot.ticker.AutoFormatter` for details. This
|
|
85
|
+
can be combined with `xtickrange` and `ytickrange` to make "stacked" line plots.
|
|
86
|
+
xloc, yloc : optional
|
|
87
|
+
Shorthands for `xspineloc`, `yspineloc`.
|
|
88
|
+
xspineloc, yspineloc : {'b', 't', 'l', 'r', 'bottom', 'top', 'left', 'right', \
|
|
89
|
+
'both', 'neither', 'none', 'zero', 'center'} or 2-tuple, optional
|
|
90
|
+
The x and y spine locations. Applied with `~matplotlib.spines.Spine.set_position`.
|
|
91
|
+
Propagates to `tickloc` unless specified otherwise.
|
|
92
|
+
xtickloc, ytickloc : {'b', 't', 'l', 'r', 'bottom', 'top', 'left', 'right', \
|
|
93
|
+
'both', 'neither', 'none'}, optional
|
|
94
|
+
Which x and y axis spines should have major and minor tick marks. Inherits from
|
|
95
|
+
`spineloc` by default and propagates to `ticklabelloc` unless specified otherwise.
|
|
96
|
+
xticklabelloc, yticklabelloc : {'b', 't', 'l', 'r', 'bottom', 'top', 'left', 'right', \
|
|
97
|
+
'both', 'neither', 'none'}, optional
|
|
98
|
+
Which x and y axis spines should have major tick labels. Inherits from `tickloc`
|
|
99
|
+
by default and propagates to `labelloc` and `offsetloc` unless specified otherwise.
|
|
100
|
+
xlabelloc, ylabelloc : \
|
|
101
|
+
{'b', 't', 'l', 'r', 'bottom', 'top', 'left', 'right'}, optional
|
|
102
|
+
Which x and y axis spines should have axis labels. Inherits from
|
|
103
|
+
`ticklabelloc` by default (if `ticklabelloc` is a single side).
|
|
104
|
+
xoffsetloc, yoffsetloc : \
|
|
105
|
+
{'b', 't', 'l', 'r', 'bottom', 'top', 'left', 'right'}, optional
|
|
106
|
+
Which x and y axis spines should have the axis offset indicator. Inherits from
|
|
107
|
+
`ticklabelloc` by default (if `ticklabelloc` is a single side).
|
|
108
|
+
xtickdir, ytickdir, tickdir : {'out', 'in', 'inout'}, optional
|
|
109
|
+
Direction that major and minor tick marks point for the x and y axis.
|
|
110
|
+
Use the keyword `tickdir` to control both.
|
|
111
|
+
xticklabeldir, yticklabeldir : {'in', 'out'}, optional
|
|
112
|
+
Whether to place x and y axis tick label text inside or outside the axes.
|
|
113
|
+
Propagates to `xtickdir` and `ytickdir` unless specified otherwise.
|
|
114
|
+
xrotation, yrotation : float, default: 0
|
|
115
|
+
The rotation for x and y axis tick labels.
|
|
116
|
+
for normal axes, :rc:`formatter.timerotation` for time x axes.
|
|
117
|
+
xgrid, ygrid, grid : bool, default: :rc:`grid`
|
|
118
|
+
Whether to draw major gridlines on the x and y axis.
|
|
119
|
+
Use the keyword `grid` to toggle both.
|
|
120
|
+
xgridminor, ygridminor, gridminor : bool, default: :rc:`gridminor`
|
|
121
|
+
Whether to draw minor gridlines for the x and y axis.
|
|
122
|
+
Use the keyword `gridminor` to toggle both.
|
|
123
|
+
xtickminor, ytickminor, tickminor : bool, default: :rc:`tick.minor`
|
|
124
|
+
Whether to draw minor ticks on the x and y axes.
|
|
125
|
+
Use the keyword `tickminor` to toggle both.
|
|
126
|
+
xticks, yticks : optional
|
|
127
|
+
Aliases for `xlocator`, `ylocator`.
|
|
128
|
+
xlocator, ylocator : locator-spec, optional
|
|
129
|
+
Used to determine the x and y axis tick mark positions. Passed
|
|
130
|
+
to the `~ultraplot.constructor.Locator` constructor. Can be float,
|
|
131
|
+
list of float, string, or `matplotlib.ticker.Locator` instance.
|
|
132
|
+
Use ``[]``, ``'null'``, or ``'none'`` for no ticks.
|
|
133
|
+
xlocator_kw, ylocator_kw : dict-like, optional
|
|
134
|
+
Keyword arguments passed to the `matplotlib.ticker.Locator` class.
|
|
135
|
+
xminorticks, yminorticks : optional
|
|
136
|
+
Aliases for `xminorlocator`, `yminorlocator`.
|
|
137
|
+
xminorlocator, yminorlocator : optional
|
|
138
|
+
As for `xlocator`, `ylocator`, but for the minor ticks.
|
|
139
|
+
xminorlocator_kw, yminorlocator_kw
|
|
140
|
+
As for `xlocator_kw`, `ylocator_kw`, but for the minor locator.
|
|
141
|
+
xticklabels, yticklabels : optional
|
|
142
|
+
Aliases for `xformatter`, `yformatter`.
|
|
143
|
+
xformatter, yformatter : formatter-spec, optional
|
|
144
|
+
Used to determine the x and y axis tick label string format.
|
|
145
|
+
Passed to the `~ultraplot.constructor.Formatter` constructor.
|
|
146
|
+
Can be string, list of strings, or `matplotlib.ticker.Formatter` instance.
|
|
147
|
+
Use ``[]``, ``'null'``, or ``'none'`` for no labels.
|
|
148
|
+
xformatter_kw, yformatter_kw : dict-like, optional
|
|
149
|
+
Keyword arguments passed to the `matplotlib.ticker.Formatter` class.
|
|
150
|
+
xcolor, ycolor, color : color-spec, default: :rc:`meta.color`
|
|
151
|
+
Color for the x and y axis spines, ticks, tick labels, and axis labels.
|
|
152
|
+
Use the keyword `color` to set both at once.
|
|
153
|
+
xgridcolor, ygridcolor, gridcolor : color-spec, default: :rc:`grid.color`
|
|
154
|
+
Color for the x and y axis major and minor gridlines.
|
|
155
|
+
Use the keyword `gridcolor` to set both at once.
|
|
156
|
+
xlinewidth, ylinewidth, linewidth : color-spec, default: :rc:`meta.width`
|
|
157
|
+
Line width for the x and y axis spines and major ticks. Propagates to `tickwidth`
|
|
158
|
+
unless specified otherwise. Use the keyword `linewidth` to set both at once.
|
|
159
|
+
xtickcolor, ytickcolor, tickcolor : color-spec, default: :rc:`tick.color`
|
|
160
|
+
Color for the x and y axis ticks. Defaults are `xcolor`, `ycolor`, and `color`
|
|
161
|
+
if they were passed. Use the keyword `tickcolor` to set both at once.
|
|
162
|
+
xticklen, yticklen, ticklen : unit-spec, default: :rc:`tick.len`
|
|
163
|
+
Major tick lengths for the x and y axis.
|
|
164
|
+
%(units.pt)s
|
|
165
|
+
Use the keyword `ticklen` to set both at once.
|
|
166
|
+
xticklenratio, yticklenratio, ticklenratio : float, default: :rc:`tick.lenratio`
|
|
167
|
+
Relative scaling of `xticklen` and `yticklen` used to determine minor
|
|
168
|
+
tick lengths. Use the keyword `ticklenratio` to set both at once.
|
|
169
|
+
xtickwidth, ytickwidth, tickwidth, : unit-spec, default: :rc:`tick.width`
|
|
170
|
+
Major tick widths for the x ans y axis. Default is `linewidth` if it was passed.
|
|
171
|
+
%(units.pt)s
|
|
172
|
+
Use the keyword `tickwidth` to set both at once.
|
|
173
|
+
xtickwidthratio, ytickwidthratio, tickwidthratio : float, default: :rc:`tick.widthratio`
|
|
174
|
+
Relative scaling of `xtickwidth` and `ytickwidth` used to determine
|
|
175
|
+
minor tick widths. Use the keyword `tickwidthratio` to set both at once.
|
|
176
|
+
xticklabelpad, yticklabelpad, ticklabelpad : unit-spec, default: :rc:`tick.labelpad`
|
|
177
|
+
The padding between the x and y axis ticks and tick labels. Use the
|
|
178
|
+
keyword `ticklabelpad` to set both at once.
|
|
179
|
+
%(units.pt)s
|
|
180
|
+
xticklabelcolor, yticklabelcolor, ticklabelcolor \
|
|
181
|
+
: color-spec, default: :rc:`tick.labelcolor`
|
|
182
|
+
Color for the x and y tick labels. Defaults are `xcolor`, `ycolor`, and `color`
|
|
183
|
+
if they were passed. Use the keyword `ticklabelcolor` to set both at once.
|
|
184
|
+
xticklabelsize, yticklabelsize, ticklabelsize \
|
|
185
|
+
: unit-spec or str, default: :rc:`tick.labelsize`
|
|
186
|
+
Font size for the x and y tick labels.
|
|
187
|
+
%(units.pt)s
|
|
188
|
+
Use the keyword `ticklabelsize` to set both at once.
|
|
189
|
+
xticklabelweight, yticklabelweight, ticklabelweight \
|
|
190
|
+
: str, default: :rc:`tick.labelweight`
|
|
191
|
+
Font weight for the x and y tick labels.
|
|
192
|
+
Use the keyword `ticklabelweight` to set both at once.
|
|
193
|
+
xlabelpad, ylabelpad : unit-spec, default: :rc:`label.pad`
|
|
194
|
+
The padding between the x and y axis bounding box and the x and y axis labels.
|
|
195
|
+
%(units.pt)s
|
|
196
|
+
xlabelcolor, ylabelcolor, labelcolor : color-spec, default: :rc:`label.color`
|
|
197
|
+
Color for the x and y axis labels. Defaults are `xcolor`, `ycolor`, and `color`
|
|
198
|
+
if they were passed. Use the keyword `labelcolor` to set both at once.
|
|
199
|
+
xlabelsize, ylabelsize, labelsize : unit-spec or str, default: :rc:`label.size`
|
|
200
|
+
Font size for the x and y axis labels.
|
|
201
|
+
%(units.pt)s
|
|
202
|
+
Use the keyword `labelsize` to set both at once.
|
|
203
|
+
xlabelweight, ylabelweight, labelweight : str, default: :rc:`label.weight`
|
|
204
|
+
Font weight for the x and y axis labels.
|
|
205
|
+
Use the keyword `labelweight` to set both at once.
|
|
206
|
+
fixticks : bool, default: False
|
|
207
|
+
Whether to transform the tick locators to a `~matplotlib.ticker.FixedLocator`.
|
|
208
|
+
If your axis ticks are doing weird things (for example, ticks are drawn
|
|
209
|
+
outside of the axis spine) you can try setting this to ``True``.
|
|
210
|
+
"""
|
|
211
|
+
docstring._snippet_manager["cartesian.format"] = _format_docstring
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
# Shared docstring
|
|
215
|
+
_shared_x_keys = {
|
|
216
|
+
"x": "x",
|
|
217
|
+
"x1": "bottom",
|
|
218
|
+
"x2": "top",
|
|
219
|
+
"y": "y",
|
|
220
|
+
"y1": "left",
|
|
221
|
+
"y2": "right",
|
|
222
|
+
}
|
|
223
|
+
_shared_y_keys = {
|
|
224
|
+
"x": "y",
|
|
225
|
+
"x1": "left",
|
|
226
|
+
"x2": "right",
|
|
227
|
+
"y": "x",
|
|
228
|
+
"y1": "bottom",
|
|
229
|
+
"y2": "top",
|
|
230
|
+
}
|
|
231
|
+
_shared_docstring = """
|
|
232
|
+
%(descrip)s
|
|
233
|
+
Parameters
|
|
234
|
+
----------
|
|
235
|
+
%(extra)s**kwargs
|
|
236
|
+
Passed to `~ultraplot.axes.CartesianAxes`. Supports all valid
|
|
237
|
+
`~ultraplot.axes.CartesianAxes.format` keywords. You can optionally
|
|
238
|
+
omit the {x} from keywords beginning with ``{x}`` -- for example
|
|
239
|
+
``ax.alt{x}(lim=(0, 10))`` is equivalent to ``ax.alt{x}({x}lim=(0, 10))``.
|
|
240
|
+
You can also change the default side for the axis spine, axis tick marks,
|
|
241
|
+
axis tick labels, and/or axis labels by passing ``loc`` keywords. For example,
|
|
242
|
+
``ax.alt{x}(loc='{x1}')`` changes the default side from {x2} to {x1}.
|
|
243
|
+
|
|
244
|
+
Returns
|
|
245
|
+
-------
|
|
246
|
+
ultraplot.axes.CartesianAxes
|
|
247
|
+
The resulting axes.
|
|
248
|
+
|
|
249
|
+
Note
|
|
250
|
+
----
|
|
251
|
+
This enforces the following default settings:
|
|
252
|
+
|
|
253
|
+
* Places the old {x} axis on the {x1} and the new {x}
|
|
254
|
+
axis on the {x2}.
|
|
255
|
+
* Makes the old {x2} spine invisible and the new {x1}, {y1},
|
|
256
|
+
and {y2} spines invisible.
|
|
257
|
+
* Adjusts the {x} axis tick, tick label, and axis label positions
|
|
258
|
+
according to the visible spine positions.
|
|
259
|
+
* Syncs the old and new {y} axis limits and scales, and makes the
|
|
260
|
+
new {y} axis labels invisible.
|
|
261
|
+
"""
|
|
262
|
+
|
|
263
|
+
# Alt docstrings
|
|
264
|
+
# NOTE: Used by SubplotGrid.altx
|
|
265
|
+
_alt_descrip = """
|
|
266
|
+
Add an axes locked to the same location with a
|
|
267
|
+
distinct {x} axis.
|
|
268
|
+
This is an alias and arguably more intuitive name for
|
|
269
|
+
`~ultraplot.axes.CartesianAxes.twin{y}`, which generates
|
|
270
|
+
two {x} axes with a shared ("twin") {y} axes.
|
|
271
|
+
"""
|
|
272
|
+
_alt_docstring = _shared_docstring % {"descrip": _alt_descrip, "extra": ""}
|
|
273
|
+
docstring._snippet_manager["axes.altx"] = _alt_docstring.format(**_shared_x_keys)
|
|
274
|
+
docstring._snippet_manager["axes.alty"] = _alt_docstring.format(**_shared_y_keys)
|
|
275
|
+
|
|
276
|
+
# Twin docstrings
|
|
277
|
+
# NOTE: Used by SubplotGrid.twinx
|
|
278
|
+
_twin_descrip = """
|
|
279
|
+
Add an axes locked to the same location with a
|
|
280
|
+
distinct {x} axis.
|
|
281
|
+
This builds upon `matplotlib.axes.Axes.twin{y}`.
|
|
282
|
+
"""
|
|
283
|
+
_twin_docstring = _shared_docstring % {"descrip": _twin_descrip, "extra": ""}
|
|
284
|
+
docstring._snippet_manager["axes.twinx"] = _twin_docstring.format(**_shared_y_keys)
|
|
285
|
+
docstring._snippet_manager["axes.twiny"] = _twin_docstring.format(**_shared_x_keys)
|
|
286
|
+
|
|
287
|
+
# Dual docstrings
|
|
288
|
+
# NOTE: Used by SubplotGrid.dualx
|
|
289
|
+
_dual_descrip = """
|
|
290
|
+
Add an axes locked to the same location whose {x} axis denotes
|
|
291
|
+
equivalent coordinates in alternate units.
|
|
292
|
+
This is an alternative to `matplotlib.axes.Axes.secondary_{x}axis` with
|
|
293
|
+
additional convenience features.
|
|
294
|
+
"""
|
|
295
|
+
_dual_extra = """
|
|
296
|
+
funcscale : callable, 2-tuple of callables, or scale-spec
|
|
297
|
+
The scale used to transform units from the parent axis to the secondary
|
|
298
|
+
axis. This can be a `~ultraplot.scale.FuncScale` itself or a function,
|
|
299
|
+
(function, function) tuple, or an axis scale specification interpreted
|
|
300
|
+
by the `~ultraplot.constructor.Scale` constructor function, any of which
|
|
301
|
+
will be used to build a `~ultraplot.scale.FuncScale` and applied
|
|
302
|
+
to the dual axis (see `~ultraplot.scale.FuncScale` for details).
|
|
303
|
+
"""
|
|
304
|
+
_dual_docstring = _shared_docstring % {
|
|
305
|
+
"descrip": _dual_descrip,
|
|
306
|
+
"extra": _dual_extra.lstrip(),
|
|
307
|
+
} # noqa: E501
|
|
308
|
+
docstring._snippet_manager["axes.dualx"] = _dual_docstring.format(**_shared_x_keys)
|
|
309
|
+
docstring._snippet_manager["axes.dualy"] = _dual_docstring.format(**_shared_y_keys)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
class CartesianAxes(shared._SharedAxes, plot.PlotAxes):
|
|
313
|
+
"""
|
|
314
|
+
Axes subclass for plotting in ordinary Cartesian coordinates. Adds the
|
|
315
|
+
`~CartesianAxes.format` method and overrides several existing methods.
|
|
316
|
+
|
|
317
|
+
Important
|
|
318
|
+
---------
|
|
319
|
+
This is the default axes subclass. It can be specified explicitly by passing
|
|
320
|
+
``proj='cart'``, ``proj='cartesian'``, ``proj='rect'``, or ``proj='rectilinear'``
|
|
321
|
+
to axes-creation commands like `~ultraplot.figure.Figure.add_axes`,
|
|
322
|
+
`~ultraplot.figure.Figure.add_subplot`, and `~ultraplot.figure.Figure.subplots`.
|
|
323
|
+
"""
|
|
324
|
+
|
|
325
|
+
_name = "cartesian"
|
|
326
|
+
_name_aliases = ("cart", "rect", "rectilinar") # include matplotlib name
|
|
327
|
+
|
|
328
|
+
@docstring._snippet_manager
|
|
329
|
+
def __init__(self, *args, **kwargs):
|
|
330
|
+
"""
|
|
331
|
+
Parameters
|
|
332
|
+
----------
|
|
333
|
+
*args
|
|
334
|
+
Passed to `matplotlib.axes.Axes`.
|
|
335
|
+
%(cartesian.format)s
|
|
336
|
+
|
|
337
|
+
Other parameters
|
|
338
|
+
----------------
|
|
339
|
+
%(axes.format)s
|
|
340
|
+
%(rc.init)s
|
|
341
|
+
|
|
342
|
+
See also
|
|
343
|
+
--------
|
|
344
|
+
CartesianAxes.format
|
|
345
|
+
ultraplot.axes.Axes
|
|
346
|
+
ultraplot.axes.PlotAxes
|
|
347
|
+
ultraplot.figure.Figure.subplot
|
|
348
|
+
ultraplot.figure.Figure.add_subplot
|
|
349
|
+
"""
|
|
350
|
+
# Initialize axes
|
|
351
|
+
self._xaxis_current_rotation = "horizontal" # current rotation
|
|
352
|
+
self._yaxis_current_rotation = "horizontal"
|
|
353
|
+
self._xaxis_isdefault_rotation = True # whether to auto rotate the axis
|
|
354
|
+
self._yaxis_isdefault_rotation = True
|
|
355
|
+
super().__init__(*args, **kwargs)
|
|
356
|
+
|
|
357
|
+
# Apply default formatter
|
|
358
|
+
if self.xaxis.isDefault_majfmt:
|
|
359
|
+
self.xaxis.set_major_formatter(pticker.AutoFormatter())
|
|
360
|
+
self.xaxis.isDefault_majfmt = True
|
|
361
|
+
if self.yaxis.isDefault_majfmt:
|
|
362
|
+
self.yaxis.set_major_formatter(pticker.AutoFormatter())
|
|
363
|
+
self.yaxis.isDefault_majfmt = True
|
|
364
|
+
|
|
365
|
+
# Dual axes utilities
|
|
366
|
+
self._dualx_funcscale = None # for scaling units on dual axes
|
|
367
|
+
self._dualx_prevstate = None # prevent excess _dualy_scale calls
|
|
368
|
+
self._dualy_funcscale = None
|
|
369
|
+
self._dualy_prevstate = None
|
|
370
|
+
|
|
371
|
+
def _apply_axis_sharing(self):
|
|
372
|
+
"""
|
|
373
|
+
Enforce the "shared" axis labels and axis tick labels. If this is not
|
|
374
|
+
called at drawtime, "shared" labels can be inadvertantly turned off.
|
|
375
|
+
"""
|
|
376
|
+
# X axis
|
|
377
|
+
# NOTE: Critical to apply labels to *shared* axes attributes rather
|
|
378
|
+
# than testing extents or we end up sharing labels with twin axes.
|
|
379
|
+
# NOTE: Similar to how _align_super_labels() calls _apply_title_above() this
|
|
380
|
+
# is called inside _align_axis_labels() so we align the correct text.
|
|
381
|
+
# NOTE: The "panel sharing group" refers to axes and panels *above* the
|
|
382
|
+
# bottommost or to the *right* of the leftmost panel. But the sharing level
|
|
383
|
+
# used for the leftmost and bottommost is the *figure* sharing level.
|
|
384
|
+
axis = self.xaxis
|
|
385
|
+
if self._sharex is not None and axis.get_visible():
|
|
386
|
+
level = 3 if self._panel_sharex_group else self.figure._sharex
|
|
387
|
+
if level > 0:
|
|
388
|
+
labels._transfer_label(axis.label, self._sharex.xaxis.label)
|
|
389
|
+
axis.label.set_visible(False)
|
|
390
|
+
if level > 2:
|
|
391
|
+
# WARNING: Cannot set NullFormatter because shared axes share the
|
|
392
|
+
# same Ticker(). Instead use approach copied from mpl subplots().
|
|
393
|
+
axis.set_tick_params(which="both", labelbottom=False, labeltop=False)
|
|
394
|
+
# Y axis
|
|
395
|
+
axis = self.yaxis
|
|
396
|
+
if self._sharey is not None and axis.get_visible():
|
|
397
|
+
level = 3 if self._panel_sharey_group else self.figure._sharey
|
|
398
|
+
if level > 0:
|
|
399
|
+
labels._transfer_label(axis.label, self._sharey.yaxis.label)
|
|
400
|
+
axis.label.set_visible(False)
|
|
401
|
+
if level > 2:
|
|
402
|
+
axis.set_tick_params(which="both", labelleft=False, labelright=False)
|
|
403
|
+
axis.set_minor_formatter(mticker.NullFormatter())
|
|
404
|
+
|
|
405
|
+
def _add_alt(self, sx, **kwargs):
|
|
406
|
+
"""
|
|
407
|
+
Add an alternate axes.
|
|
408
|
+
"""
|
|
409
|
+
# Parse keyword arguments. Optionally omit redundant leading 'x' and 'y'
|
|
410
|
+
# WARNING: We add axes as children for tight layout algorithm convenience and
|
|
411
|
+
# to support eventual paradigm of arbitrarily many duplicates with spines
|
|
412
|
+
# arranged in an edge stack. However this means all artists drawn there take
|
|
413
|
+
# on zorder of their axes when drawn inside the "parent" (see Axes.draw()).
|
|
414
|
+
# To restore matplotlib behavior, which draws "child" artists on top simply
|
|
415
|
+
# because the axes was created after the "parent" one, use the inset_axes
|
|
416
|
+
# zorder of 4 and make the background transparent.
|
|
417
|
+
sy = "y" if sx == "x" else "x"
|
|
418
|
+
sig = self._format_signatures[CartesianAxes]
|
|
419
|
+
keys = tuple(key[1:] for key in sig.parameters if key[0] == sx)
|
|
420
|
+
kwargs = {
|
|
421
|
+
(sx + key if key in keys else key): val for key, val in kwargs.items()
|
|
422
|
+
} # noqa: E501
|
|
423
|
+
if f"{sy}spineloc" not in kwargs: # acccount for aliases
|
|
424
|
+
kwargs.setdefault(f"{sy}loc", "neither")
|
|
425
|
+
if f"{sx}spineloc" not in kwargs: # account for aliases
|
|
426
|
+
kwargs.setdefault(f"{sx}loc", "top" if sx == "x" else "right")
|
|
427
|
+
kwargs.setdefault(f"autoscale{sy}_on", getattr(self, f"get_autoscale{sy}_on")())
|
|
428
|
+
kwargs.setdefault(f"share{sy}", self)
|
|
429
|
+
|
|
430
|
+
# Initialize child axes
|
|
431
|
+
kwargs.setdefault("grid", False) # note xgrid=True would override this
|
|
432
|
+
kwargs.setdefault("zorder", 4) # increased default zorder
|
|
433
|
+
kwargs.setdefault("number", None)
|
|
434
|
+
kwargs.setdefault("autoshare", False)
|
|
435
|
+
if "sharex" in kwargs and "sharey" in kwargs:
|
|
436
|
+
raise ValueError("Twinned axes may share only one axis.")
|
|
437
|
+
locator = self._make_inset_locator([0, 0, 1, 1], self.transAxes)
|
|
438
|
+
ax = CartesianAxes(self.figure, locator(self, None).bounds, **kwargs)
|
|
439
|
+
ax.set_axes_locator(locator)
|
|
440
|
+
ax.set_adjustable("datalim")
|
|
441
|
+
self.add_child_axes(ax) # to facilitate tight layout
|
|
442
|
+
self.set_adjustable("datalim")
|
|
443
|
+
self._twinned_axes.join(self, ax)
|
|
444
|
+
|
|
445
|
+
# Format parent and child axes
|
|
446
|
+
self.format(**{f"{sx}loc": OPPOSITE_SIDE.get(kwargs[f"{sx}loc"], None)})
|
|
447
|
+
setattr(ax, f"_alt{sx}_parent", self)
|
|
448
|
+
getattr(ax, f"{sy}axis").set_visible(False)
|
|
449
|
+
getattr(ax, "patch").set_visible(False)
|
|
450
|
+
return ax
|
|
451
|
+
|
|
452
|
+
def _dual_scale(self, s, funcscale=None):
|
|
453
|
+
"""
|
|
454
|
+
Lock the child "dual" axis limits to the parent.
|
|
455
|
+
"""
|
|
456
|
+
# NOTE: We bypass autoscale_view because we set limits manually, and bypass
|
|
457
|
+
# child.stale = True because that is done in call to set_xlim() below.
|
|
458
|
+
# NOTE: We set the scale using private API to bypass application of
|
|
459
|
+
# set_default_locators_and_formatters: only_if_default=True is critical
|
|
460
|
+
# to prevent overriding user settings!
|
|
461
|
+
# NOTE: Dual axis only needs to be constrained if the parent axis scale
|
|
462
|
+
# and limits have changed, and limits are always applied before we reach
|
|
463
|
+
# the child.draw() because always called after parent.draw()
|
|
464
|
+
child = self
|
|
465
|
+
parent = getattr(self, f"_alt{s}_parent")
|
|
466
|
+
if funcscale is not None:
|
|
467
|
+
setattr(self, f"_dual{s}_funcscale", funcscale)
|
|
468
|
+
else:
|
|
469
|
+
funcscale = getattr(self, f"_dual{s}_funcscale")
|
|
470
|
+
if parent is None or funcscale is None:
|
|
471
|
+
return
|
|
472
|
+
olim = getattr(parent, f"get_{s}lim")()
|
|
473
|
+
scale = getattr(parent, f"{s}axis")._scale
|
|
474
|
+
if (scale, *olim) == getattr(child, f"_dual{s}_prevstate"):
|
|
475
|
+
return
|
|
476
|
+
funcscale = pscale.FuncScale(funcscale, invert=True, parent_scale=scale)
|
|
477
|
+
caxis = getattr(child, f"{s}axis")
|
|
478
|
+
caxis._scale = funcscale
|
|
479
|
+
child._update_transScale()
|
|
480
|
+
funcscale.set_default_locators_and_formatters(caxis, only_if_default=True)
|
|
481
|
+
nlim = list(map(funcscale.functions[1], np.array(olim)))
|
|
482
|
+
if np.sign(np.diff(olim)) != np.sign(np.diff(nlim)):
|
|
483
|
+
nlim = nlim[::-1] # if function flips limits, so will set_xlim!
|
|
484
|
+
getattr(child, f"set_{s}lim")(nlim, emit=False)
|
|
485
|
+
setattr(child, f"_dual{s}_prevstate", (scale, *olim))
|
|
486
|
+
|
|
487
|
+
def _fix_ticks(self, s, fixticks=False):
|
|
488
|
+
"""
|
|
489
|
+
Ensure there are no out-of-bounds ticks. Mostly a brute-force version of
|
|
490
|
+
`~matplotlib.axis.Axis.set_smart_bounds` (which I couldn't get to work).
|
|
491
|
+
"""
|
|
492
|
+
# NOTE: Previously triggered this every time FixedFormatter was found
|
|
493
|
+
# on axis but 1) that seems heavy-handed + strange and 2) internal
|
|
494
|
+
# application of FixedFormatter by boxplot resulted in subsequent format()
|
|
495
|
+
# successfully calling this and messing up the ticks for some reason.
|
|
496
|
+
# So avoid using this when possible, and try to make behavior consistent
|
|
497
|
+
# by cacheing the locators before we use them for ticks.
|
|
498
|
+
axis = getattr(self, f"{s}axis")
|
|
499
|
+
sides = ("bottom", "top") if s == "x" else ("left", "right")
|
|
500
|
+
l0, l1 = getattr(self, f"get_{s}lim")()
|
|
501
|
+
bounds = tuple(self.spines[side].get_bounds() or (None, None) for side in sides)
|
|
502
|
+
skipticks = lambda ticks: [ # noqa: E731
|
|
503
|
+
x
|
|
504
|
+
for x in ticks
|
|
505
|
+
if not any(
|
|
506
|
+
x < _not_none(b0, l0) or x > _not_none(b1, l1) for (b0, b1) in bounds
|
|
507
|
+
) # noqa: E501
|
|
508
|
+
]
|
|
509
|
+
if fixticks or any(x is not None for b in bounds for x in b):
|
|
510
|
+
# Major locator
|
|
511
|
+
locator = getattr(axis, "_major_locator_cached", None)
|
|
512
|
+
if locator is None:
|
|
513
|
+
locator = axis._major_locator_cached = axis.get_major_locator()
|
|
514
|
+
locator = constructor.Locator(skipticks(locator()))
|
|
515
|
+
axis.set_major_locator(locator)
|
|
516
|
+
# Minor locator
|
|
517
|
+
locator = getattr(axis, "_minor_locator_cached", None)
|
|
518
|
+
if locator is None:
|
|
519
|
+
locator = axis._minor_locator_cached = axis.get_minor_locator()
|
|
520
|
+
locator = constructor.Locator(skipticks(locator()))
|
|
521
|
+
axis.set_minor_locator(locator)
|
|
522
|
+
|
|
523
|
+
def _get_spine_side(self, s, loc):
|
|
524
|
+
"""
|
|
525
|
+
Get the spine side implied by the input location or position. This
|
|
526
|
+
propagates to tick mark, tick label, and axis label positions.
|
|
527
|
+
"""
|
|
528
|
+
# NOTE: Could defer error to CartesianAxes.format but instead use our
|
|
529
|
+
# own error message with info on coordinate position options.
|
|
530
|
+
sides = ("bottom", "top") if s == "x" else ("left", "right")
|
|
531
|
+
centers = ("zero", "center")
|
|
532
|
+
options = (*(s[0] for s in sides), *sides, "both", "neither", "none")
|
|
533
|
+
if np.iterable(loc) and len(loc) == 2 and loc[0] in ("axes", "data", "outward"):
|
|
534
|
+
lim = getattr(self, f"get_{s}lim")()
|
|
535
|
+
if loc[0] == "outward": # ambiguous so just choose first side
|
|
536
|
+
side = sides[0]
|
|
537
|
+
elif loc[0] == "axes":
|
|
538
|
+
side = sides[int(loc[1] > 0.5)]
|
|
539
|
+
else:
|
|
540
|
+
side = sides[int(loc[1] > lim[0] + 0.5 * (lim[1] - lim[0]))]
|
|
541
|
+
elif loc in centers: # ambiguous so just choose the first side
|
|
542
|
+
side = sides[0]
|
|
543
|
+
elif loc is None or loc in options:
|
|
544
|
+
side = loc
|
|
545
|
+
else:
|
|
546
|
+
raise ValueError(
|
|
547
|
+
f"Invalid {s} spine location {loc!r}. Options are: "
|
|
548
|
+
+ ", ".join(map(repr, (*options, *centers)))
|
|
549
|
+
+ " or a coordinate position ('axes', coord), "
|
|
550
|
+
+ " ('data', coord), or ('outward', coord)."
|
|
551
|
+
)
|
|
552
|
+
return side
|
|
553
|
+
|
|
554
|
+
def _is_panel_group_member(self, other):
|
|
555
|
+
"""
|
|
556
|
+
Return whether the axes belong in a panel sharing stack..
|
|
557
|
+
"""
|
|
558
|
+
return (
|
|
559
|
+
self._panel_parent is other # other is child panel
|
|
560
|
+
or other._panel_parent is self # other is main subplot
|
|
561
|
+
or other._panel_parent
|
|
562
|
+
and self._panel_parent # ...
|
|
563
|
+
and other._panel_parent is self._panel_parent # other is sibling panel
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
def _sharex_limits(self, sharex):
|
|
567
|
+
"""
|
|
568
|
+
Safely share limits and tickers without resetting things.
|
|
569
|
+
"""
|
|
570
|
+
# Copy non-default limits and scales. Either this axes or the input
|
|
571
|
+
# axes could be a newly-created subplot while the other is a subplot
|
|
572
|
+
# with possibly-modified user settings we are careful to preserve.
|
|
573
|
+
for ax1, ax2 in ((self, sharex), (sharex, self)):
|
|
574
|
+
if ax1.get_xscale() == "linear" and ax2.get_xscale() != "linear":
|
|
575
|
+
ax1.set_xscale(ax2.get_xscale()) # non-default scale
|
|
576
|
+
if ax1.get_autoscalex_on() and not ax2.get_autoscalex_on():
|
|
577
|
+
ax1.set_xlim(ax2.get_xlim()) # non-default limits
|
|
578
|
+
# Copy non-default locators and formatters
|
|
579
|
+
self.get_shared_x_axes().joined(self, sharex) # share limit/scale changes
|
|
580
|
+
if sharex.xaxis.isDefault_majloc and not self.xaxis.isDefault_majloc:
|
|
581
|
+
sharex.xaxis.set_major_locator(self.xaxis.get_major_locator())
|
|
582
|
+
if sharex.xaxis.isDefault_minloc and not self.xaxis.isDefault_minloc:
|
|
583
|
+
sharex.xaxis.set_minor_locator(self.xaxis.get_minor_locator())
|
|
584
|
+
if sharex.xaxis.isDefault_majfmt and not self.xaxis.isDefault_majfmt:
|
|
585
|
+
sharex.xaxis.set_major_formatter(self.xaxis.get_major_formatter())
|
|
586
|
+
if sharex.xaxis.isDefault_minfmt and not self.xaxis.isDefault_minfmt:
|
|
587
|
+
sharex.xaxis.set_minor_formatter(self.xaxis.get_minor_formatter())
|
|
588
|
+
self.xaxis.major = sharex.xaxis.major
|
|
589
|
+
self.xaxis.minor = sharex.xaxis.minor
|
|
590
|
+
|
|
591
|
+
def _sharey_limits(self, sharey):
|
|
592
|
+
"""
|
|
593
|
+
Safely share limits and tickers without resetting things.
|
|
594
|
+
"""
|
|
595
|
+
# NOTE: See _sharex_limits for notes
|
|
596
|
+
for ax1, ax2 in ((self, sharey), (sharey, self)):
|
|
597
|
+
if ax1.get_yscale() == "linear" and ax2.get_yscale() != "linear":
|
|
598
|
+
ax1.set_yscale(ax2.get_yscale())
|
|
599
|
+
if ax1.get_autoscaley_on() and not ax2.get_autoscaley_on():
|
|
600
|
+
ax1.set_ylim(ax2.get_ylim())
|
|
601
|
+
self.get_shared_y_axes().joined(self, sharey) # share limit/scale changes
|
|
602
|
+
if sharey.yaxis.isDefault_majloc and not self.yaxis.isDefault_majloc:
|
|
603
|
+
sharey.yaxis.set_major_locator(self.yaxis.get_major_locator())
|
|
604
|
+
if sharey.yaxis.isDefault_minloc and not self.yaxis.isDefault_minloc:
|
|
605
|
+
sharey.yaxis.set_minor_locator(self.yaxis.get_minor_locator())
|
|
606
|
+
if sharey.yaxis.isDefault_majfmt and not self.yaxis.isDefault_majfmt:
|
|
607
|
+
sharey.yaxis.set_major_formatter(self.yaxis.get_major_formatter())
|
|
608
|
+
if sharey.yaxis.isDefault_minfmt and not self.yaxis.isDefault_minfmt:
|
|
609
|
+
sharey.yaxis.set_minor_formatter(self.yaxis.get_minor_formatter())
|
|
610
|
+
self.yaxis.major = sharey.yaxis.major
|
|
611
|
+
self.yaxis.minor = sharey.yaxis.minor
|
|
612
|
+
|
|
613
|
+
def _sharex_setup(self, sharex, *, labels=True, limits=True):
|
|
614
|
+
"""
|
|
615
|
+
Configure shared axes accounting. Input is the 'parent' axes from which this
|
|
616
|
+
one will draw its properties. Use keyword args to override settings.
|
|
617
|
+
"""
|
|
618
|
+
# Share panels across *different* subplots
|
|
619
|
+
super()._sharex_setup(sharex)
|
|
620
|
+
# Get the axis sharing level
|
|
621
|
+
level = (
|
|
622
|
+
3
|
|
623
|
+
if self._panel_sharex_group and self._is_panel_group_member(sharex)
|
|
624
|
+
else self.figure._sharex
|
|
625
|
+
)
|
|
626
|
+
if level not in range(5): # must be internal error
|
|
627
|
+
raise ValueError(f"Invalid sharing level sharex={level!r}.")
|
|
628
|
+
if sharex in (None, self) or not isinstance(sharex, CartesianAxes):
|
|
629
|
+
return
|
|
630
|
+
# Share future axis label changes. Implemented in _apply_axis_sharing().
|
|
631
|
+
# Matplotlib only uses these attributes in __init__() and cla() to share
|
|
632
|
+
# tickers -- all other builtin sharing features derives from shared x axes
|
|
633
|
+
if level > 0 and labels:
|
|
634
|
+
self._sharex = sharex
|
|
635
|
+
# Share future axis tickers, limits, and scales
|
|
636
|
+
# NOTE: Only difference between levels 2 and 3 is level 3 hides tick
|
|
637
|
+
# labels. But this is done after the fact -- tickers are still shared.
|
|
638
|
+
if level > 1 and limits:
|
|
639
|
+
self._sharex_limits(sharex)
|
|
640
|
+
|
|
641
|
+
def _sharey_setup(self, sharey, *, labels=True, limits=True):
|
|
642
|
+
"""
|
|
643
|
+
Configure shared axes accounting for panels. The input is the
|
|
644
|
+
'parent' axes, from which this one will draw its properties.
|
|
645
|
+
"""
|
|
646
|
+
# NOTE: See _sharex_setup for notes
|
|
647
|
+
super()._sharey_setup(sharey)
|
|
648
|
+
level = (
|
|
649
|
+
3
|
|
650
|
+
if self._panel_sharey_group and self._is_panel_group_member(sharey)
|
|
651
|
+
else self.figure._sharey
|
|
652
|
+
)
|
|
653
|
+
if level not in range(5): # must be internal error
|
|
654
|
+
raise ValueError(f"Invalid sharing level sharey={level!r}.")
|
|
655
|
+
if sharey in (None, self) or not isinstance(sharey, CartesianAxes):
|
|
656
|
+
return
|
|
657
|
+
if level > 0 and labels:
|
|
658
|
+
self._sharey = sharey
|
|
659
|
+
if level > 1 and limits:
|
|
660
|
+
self._sharey_limits(sharey)
|
|
661
|
+
|
|
662
|
+
def _update_formatter(
|
|
663
|
+
self,
|
|
664
|
+
s,
|
|
665
|
+
formatter=None,
|
|
666
|
+
*,
|
|
667
|
+
formatter_kw=None,
|
|
668
|
+
tickrange=None,
|
|
669
|
+
wraprange=None,
|
|
670
|
+
):
|
|
671
|
+
"""
|
|
672
|
+
Update the axis formatter. Passes `formatter` through `Formatter` with kwargs.
|
|
673
|
+
"""
|
|
674
|
+
# Test if this is date axes
|
|
675
|
+
# See: https://matplotlib.org/api/units_api.html
|
|
676
|
+
# And: https://matplotlib.org/api/dates_api.html
|
|
677
|
+
axis = getattr(self, f"{s}axis")
|
|
678
|
+
date = isinstance(axis.converter, DATE_CONVERTERS)
|
|
679
|
+
|
|
680
|
+
# Major formatter
|
|
681
|
+
# NOTE: The default axis formatter accepts lots of keywords. So unlike
|
|
682
|
+
# everywhere else that uses constructor functions we also allow only
|
|
683
|
+
# formatter_kw input without formatter and use 'auto' as the default.
|
|
684
|
+
formatter_kw = formatter_kw or {}
|
|
685
|
+
formatter_kw = formatter_kw.copy()
|
|
686
|
+
if (
|
|
687
|
+
formatter is not None
|
|
688
|
+
or tickrange is not None
|
|
689
|
+
or wraprange is not None
|
|
690
|
+
or formatter_kw
|
|
691
|
+
): # noqa: E501
|
|
692
|
+
# Tick range
|
|
693
|
+
formatter = _not_none(formatter, "auto")
|
|
694
|
+
if tickrange is not None or wraprange is not None:
|
|
695
|
+
if formatter != "auto":
|
|
696
|
+
warnings._warn_ultraplot(
|
|
697
|
+
"The tickrange and autorange features require "
|
|
698
|
+
"ultraplot.AutoFormatter formatter. Overriding the input."
|
|
699
|
+
)
|
|
700
|
+
if tickrange is not None:
|
|
701
|
+
formatter_kw.setdefault("tickrange", tickrange)
|
|
702
|
+
if wraprange is not None:
|
|
703
|
+
formatter_kw.setdefault("wraprange", wraprange)
|
|
704
|
+
|
|
705
|
+
# Set the formatter
|
|
706
|
+
# Note some formatters require 'locator' as keyword arg
|
|
707
|
+
if formatter in ("date", "concise"):
|
|
708
|
+
locator = axis.get_major_locator()
|
|
709
|
+
formatter_kw.setdefault("locator", locator)
|
|
710
|
+
formatter = constructor.Formatter(formatter, date=date, **formatter_kw)
|
|
711
|
+
axis.set_major_formatter(formatter)
|
|
712
|
+
|
|
713
|
+
def _update_labels(self, s, *args, **kwargs):
|
|
714
|
+
"""
|
|
715
|
+
Apply axis labels to the relevant shared axis. If spanning labels are toggled
|
|
716
|
+
this keeps the labels synced for all subplots in the same row or column. Label
|
|
717
|
+
positions will be adjusted at draw-time with figure._align_axislabels.
|
|
718
|
+
"""
|
|
719
|
+
# NOTE: Critical to test whether arguments are None or else this
|
|
720
|
+
# will set isDefault_label to False every time format() is called.
|
|
721
|
+
# NOTE: This always updates the *current* labels and sharing is handled
|
|
722
|
+
# later so that labels set with set_xlabel() and set_ylabel() are shared too.
|
|
723
|
+
# See notes in _align_axis_labels() and _apply_axis_sharing().
|
|
724
|
+
kwargs = rc._get_label_props(**kwargs)
|
|
725
|
+
no_args = all(a is None for a in args)
|
|
726
|
+
no_kwargs = all(v is None for v in kwargs.values())
|
|
727
|
+
if no_args and no_kwargs:
|
|
728
|
+
return # also returns if args and kwargs are empty
|
|
729
|
+
setter = getattr(self, f"set_{s}label")
|
|
730
|
+
getter = getattr(self, f"get_{s}label")
|
|
731
|
+
if no_args: # otherwise label text is reset!
|
|
732
|
+
args = (getter(),)
|
|
733
|
+
setter(*args, **kwargs)
|
|
734
|
+
|
|
735
|
+
def _update_locators(
|
|
736
|
+
self,
|
|
737
|
+
s,
|
|
738
|
+
locator=None,
|
|
739
|
+
minorlocator=None,
|
|
740
|
+
*,
|
|
741
|
+
tickminor=None,
|
|
742
|
+
locator_kw=None,
|
|
743
|
+
minorlocator_kw=None,
|
|
744
|
+
):
|
|
745
|
+
"""
|
|
746
|
+
Update the locators. Requires `Locator` instances.
|
|
747
|
+
"""
|
|
748
|
+
# Apply input major locator
|
|
749
|
+
axis = getattr(self, f"{s}axis")
|
|
750
|
+
locator_kw = locator_kw or {}
|
|
751
|
+
if locator is not None:
|
|
752
|
+
locator = constructor.Locator(locator, **locator_kw)
|
|
753
|
+
axis.set_major_locator(locator)
|
|
754
|
+
if isinstance(locator, (mticker.IndexLocator, pticker.IndexLocator)):
|
|
755
|
+
tickminor = _not_none(tickminor, False) # disable 'index' minor ticks
|
|
756
|
+
|
|
757
|
+
# Apply input or default minor locator
|
|
758
|
+
# NOTE: Parts of API (dualxy) rely on minor tick toggling preserving the
|
|
759
|
+
# isDefault_minloc setting. In future should override mpl minorticks_on()
|
|
760
|
+
# NOTE: Unlike matplotlib when "turning on" minor ticks we *always* use the
|
|
761
|
+
# scale default, thanks to scale classes refactoring with _ScaleBase.
|
|
762
|
+
isdefault = minorlocator is None
|
|
763
|
+
minorlocator_kw = minorlocator_kw or {}
|
|
764
|
+
if not isdefault:
|
|
765
|
+
minorlocator = constructor.Locator(minorlocator, **minorlocator_kw)
|
|
766
|
+
elif tickminor:
|
|
767
|
+
minorlocator = getattr(axis._scale, "_default_minor_locator", None)
|
|
768
|
+
minorlocator = copy.copy(minorlocator)
|
|
769
|
+
minorlocator = constructor.Locator(minorlocator or "minor")
|
|
770
|
+
if minorlocator is not None:
|
|
771
|
+
axis.set_minor_locator(minorlocator)
|
|
772
|
+
axis.isDefault_minloc = isdefault
|
|
773
|
+
|
|
774
|
+
# Disable minor ticks
|
|
775
|
+
# NOTE: Generally if you *enable* minor ticks on a dual axis, want to
|
|
776
|
+
# allow FuncScale updates to change the minor tick locators. If you
|
|
777
|
+
# *disable* minor ticks, do not want FuncScale applications to turn them
|
|
778
|
+
# on. So we allow below to set isDefault_minloc to False.
|
|
779
|
+
if tickminor is not None and not tickminor:
|
|
780
|
+
axis.set_minor_locator(constructor.Locator("null"))
|
|
781
|
+
|
|
782
|
+
def _update_limits(self, s, *, min_=None, max_=None, lim=None, reverse=None):
|
|
783
|
+
"""
|
|
784
|
+
Update the axis limits.
|
|
785
|
+
"""
|
|
786
|
+
# Set limits for just one side or both at once
|
|
787
|
+
lim = self._min_max_lim(s, min_, max_, lim)
|
|
788
|
+
if any(_ is not None for _ in lim):
|
|
789
|
+
getattr(self, f"set_{s}lim")(lim)
|
|
790
|
+
|
|
791
|
+
# Reverse direction
|
|
792
|
+
# NOTE: 3.1+ has axis.set_inverted(), below is from source code
|
|
793
|
+
if reverse is not None:
|
|
794
|
+
axis = getattr(self, f"{s}axis")
|
|
795
|
+
lo, hi = axis.get_view_interval()
|
|
796
|
+
if reverse:
|
|
797
|
+
lim = (max(lo, hi), min(lo, hi))
|
|
798
|
+
else:
|
|
799
|
+
lim = (min(lo, hi), max(lo, hi))
|
|
800
|
+
axis.set_view_interval(*lim, ignore=True)
|
|
801
|
+
|
|
802
|
+
def _update_rotation(self, s, *, rotation=None):
|
|
803
|
+
"""
|
|
804
|
+
Rotate the tick labels. Rotate 90 degrees by default for datetime *x* axes.
|
|
805
|
+
"""
|
|
806
|
+
# Apply rotation for datetime axes.
|
|
807
|
+
# NOTE: Rotation is done *before* horizontal/vertical alignment. Cannot
|
|
808
|
+
# change alignment with set_tick_params so we must apply to text objects.
|
|
809
|
+
# Note fig.autofmt_date calls subplots_adjust, so we cannot use it.
|
|
810
|
+
current = f"_{s}axis_current_rotation"
|
|
811
|
+
default = f"_{s}axis_isdefault_rotation"
|
|
812
|
+
axis = getattr(self, f"{s}axis")
|
|
813
|
+
if rotation is not None:
|
|
814
|
+
setattr(self, default, False)
|
|
815
|
+
elif not getattr(self, default):
|
|
816
|
+
return # do not rotate
|
|
817
|
+
elif s == "x" and isinstance(axis.converter, DATE_CONVERTERS):
|
|
818
|
+
rotation = rc["formatter.timerotation"]
|
|
819
|
+
else:
|
|
820
|
+
rotation = "horizontal"
|
|
821
|
+
|
|
822
|
+
# Apply tick label rotation if necessary
|
|
823
|
+
if rotation != getattr(self, current):
|
|
824
|
+
rotation = {"horizontal": 0, "vertical": 90}.get(rotation, rotation)
|
|
825
|
+
kw = {"rotation": rotation}
|
|
826
|
+
if rotation not in (0, 90, -90):
|
|
827
|
+
kw["ha"] = "right" if rotation > 0 else "left"
|
|
828
|
+
for label in axis.get_ticklabels():
|
|
829
|
+
label.update(kw)
|
|
830
|
+
setattr(self, current, rotation)
|
|
831
|
+
|
|
832
|
+
def _update_spines(self, s, *, loc=None, bounds=None):
|
|
833
|
+
"""
|
|
834
|
+
Update the spine settings.
|
|
835
|
+
"""
|
|
836
|
+
# Change default spine location from 'both' to the first
|
|
837
|
+
# relevant side if the user passes 'bounds'.
|
|
838
|
+
sides = ("bottom", "top") if s == "x" else ("left", "right")
|
|
839
|
+
opts = (*(s[0] for s in sides), *sides) # see _get_spine_side()
|
|
840
|
+
side = self._get_spine_side(s, loc) # side for set_position()
|
|
841
|
+
if bounds is not None and all(self.spines[s].get_visible() for s in sides):
|
|
842
|
+
loc = _not_none(loc, sides[0])
|
|
843
|
+
for key in sides:
|
|
844
|
+
# Simple spine location that just toggles the side(s). Do not bother
|
|
845
|
+
# with the _get_spine_side stuff.
|
|
846
|
+
spine = self.spines[key]
|
|
847
|
+
if loc is None:
|
|
848
|
+
pass
|
|
849
|
+
elif loc == "neither" or loc == "none":
|
|
850
|
+
spine.set_visible(False)
|
|
851
|
+
elif loc == "both":
|
|
852
|
+
spine.set_visible(True)
|
|
853
|
+
elif loc in opts:
|
|
854
|
+
spine.set_visible(key[0] == loc[0])
|
|
855
|
+
# Special spine location, usually 'zero', 'center', or tuple with
|
|
856
|
+
# (units, location) where 'units' can be 'axes', 'data', or 'outward'.
|
|
857
|
+
elif key != side:
|
|
858
|
+
spine.set_visible(False) # special position is for other spine
|
|
859
|
+
else:
|
|
860
|
+
spine.set_visible(True) # special position uses this spine
|
|
861
|
+
spine.set_position(loc)
|
|
862
|
+
# Apply spine bounds
|
|
863
|
+
if bounds is not None:
|
|
864
|
+
spine.set_bounds(*bounds)
|
|
865
|
+
|
|
866
|
+
def _update_locs(
|
|
867
|
+
self, s, *, tickloc=None, ticklabelloc=None, labelloc=None, offsetloc=None
|
|
868
|
+
):
|
|
869
|
+
"""
|
|
870
|
+
Update the tick, tick label, and axis label locations.
|
|
871
|
+
"""
|
|
872
|
+
|
|
873
|
+
# Helper function and initial stuff
|
|
874
|
+
def _validate_loc(loc, opts, descrip):
|
|
875
|
+
try:
|
|
876
|
+
return opts[loc]
|
|
877
|
+
except KeyError:
|
|
878
|
+
raise ValueError(
|
|
879
|
+
f"Invalid {descrip} location {loc!r}. Options are "
|
|
880
|
+
+ ", ".join(map(repr, sides + tuple(opts)))
|
|
881
|
+
+ "."
|
|
882
|
+
)
|
|
883
|
+
|
|
884
|
+
sides = ("bottom", "top") if s == "x" else ("left", "right")
|
|
885
|
+
sides_active = tuple(side for side in sides if self.spines[side].get_visible())
|
|
886
|
+
label_opts = {s[:i]: s for s in sides for i in (1, None)}
|
|
887
|
+
tick_opts = {"both": sides, "neither": (), "none": (), None: None}
|
|
888
|
+
tick_opts.update({k: (v,) for k, v in label_opts.items()})
|
|
889
|
+
|
|
890
|
+
# Apply the tick mark and tick label locations
|
|
891
|
+
kw = {}
|
|
892
|
+
kw.update({side: False for side in sides if side not in sides_active})
|
|
893
|
+
kw.update({"label" + side: False for side in sides if side not in sides_active})
|
|
894
|
+
if ticklabelloc is not None:
|
|
895
|
+
ticklabelloc = _validate_loc(ticklabelloc, tick_opts, "tick label")
|
|
896
|
+
kw.update({"label" + side: side in ticklabelloc for side in sides})
|
|
897
|
+
if tickloc is not None: # possibly overrides ticklabelloc
|
|
898
|
+
tickloc = _validate_loc(tickloc, tick_opts, "tick mark")
|
|
899
|
+
kw.update({side: side in tickloc for side in sides})
|
|
900
|
+
kw.update({"label" + side: False for side in sides if side not in tickloc})
|
|
901
|
+
self.tick_params(axis=s, which="both", **kw)
|
|
902
|
+
|
|
903
|
+
# Apply the axis label and offset label locations
|
|
904
|
+
# Uses ugly mpl 3.3+ tick_top() tick_bottom() kludge for offset location
|
|
905
|
+
# See: https://matplotlib.org/3.3.1/users/whats_new.html
|
|
906
|
+
axis = getattr(self, f"{s}axis")
|
|
907
|
+
options = tuple(
|
|
908
|
+
_ for _ in sides if tickloc and _ in tickloc and _ in sides_active
|
|
909
|
+
) # noqa: E501
|
|
910
|
+
if tickloc is not None and len(options) == 1:
|
|
911
|
+
labelloc = _not_none(labelloc, options[0])
|
|
912
|
+
offsetloc = _not_none(offsetloc, options[0])
|
|
913
|
+
if labelloc is not None:
|
|
914
|
+
labelloc = _validate_loc(labelloc, label_opts, "axis label")
|
|
915
|
+
axis.set_label_position(labelloc)
|
|
916
|
+
if offsetloc is not None:
|
|
917
|
+
offsetloc = _not_none(offsetloc, options[0])
|
|
918
|
+
if hasattr(axis, "set_offset_position"): # y axis (and future x axis?)
|
|
919
|
+
axis.set_offset_position(offsetloc)
|
|
920
|
+
elif s == "x" and _version_mpl >= "3.3": # ugly x axis kludge
|
|
921
|
+
axis._tick_position = offsetloc
|
|
922
|
+
axis.offsetText.set_verticalalignment(OPPOSITE_SIDE[offsetloc])
|
|
923
|
+
|
|
924
|
+
@docstring._snippet_manager
|
|
925
|
+
def format(
|
|
926
|
+
self,
|
|
927
|
+
*,
|
|
928
|
+
aspect=None,
|
|
929
|
+
xloc=None,
|
|
930
|
+
yloc=None,
|
|
931
|
+
xspineloc=None,
|
|
932
|
+
yspineloc=None,
|
|
933
|
+
xoffsetloc=None,
|
|
934
|
+
yoffsetloc=None,
|
|
935
|
+
xwraprange=None,
|
|
936
|
+
ywraprange=None,
|
|
937
|
+
xreverse=None,
|
|
938
|
+
yreverse=None,
|
|
939
|
+
xlim=None,
|
|
940
|
+
ylim=None,
|
|
941
|
+
xmin=None,
|
|
942
|
+
ymin=None,
|
|
943
|
+
xmax=None,
|
|
944
|
+
ymax=None,
|
|
945
|
+
xscale=None,
|
|
946
|
+
yscale=None,
|
|
947
|
+
xbounds=None,
|
|
948
|
+
ybounds=None,
|
|
949
|
+
xmargin=None,
|
|
950
|
+
ymargin=None,
|
|
951
|
+
xrotation=None,
|
|
952
|
+
yrotation=None,
|
|
953
|
+
xformatter=None,
|
|
954
|
+
yformatter=None,
|
|
955
|
+
xticklabels=None,
|
|
956
|
+
yticklabels=None,
|
|
957
|
+
xticks=None,
|
|
958
|
+
yticks=None,
|
|
959
|
+
xlocator=None,
|
|
960
|
+
ylocator=None,
|
|
961
|
+
xminorticks=None,
|
|
962
|
+
yminorticks=None,
|
|
963
|
+
xminorlocator=None,
|
|
964
|
+
yminorlocator=None,
|
|
965
|
+
xcolor=None,
|
|
966
|
+
ycolor=None,
|
|
967
|
+
xlinewidth=None,
|
|
968
|
+
ylinewidth=None,
|
|
969
|
+
xtickloc=None,
|
|
970
|
+
ytickloc=None,
|
|
971
|
+
fixticks=False,
|
|
972
|
+
xtickdir=None,
|
|
973
|
+
ytickdir=None,
|
|
974
|
+
xtickminor=None,
|
|
975
|
+
ytickminor=None,
|
|
976
|
+
xtickrange=None,
|
|
977
|
+
ytickrange=None,
|
|
978
|
+
xtickcolor=None,
|
|
979
|
+
ytickcolor=None,
|
|
980
|
+
xticklen=None,
|
|
981
|
+
yticklen=None,
|
|
982
|
+
xticklenratio=None,
|
|
983
|
+
yticklenratio=None,
|
|
984
|
+
xtickwidth=None,
|
|
985
|
+
ytickwidth=None,
|
|
986
|
+
xtickwidthratio=None,
|
|
987
|
+
ytickwidthratio=None,
|
|
988
|
+
xticklabelloc=None,
|
|
989
|
+
yticklabelloc=None,
|
|
990
|
+
xticklabeldir=None,
|
|
991
|
+
yticklabeldir=None,
|
|
992
|
+
xticklabelpad=None,
|
|
993
|
+
yticklabelpad=None,
|
|
994
|
+
xticklabelcolor=None,
|
|
995
|
+
yticklabelcolor=None,
|
|
996
|
+
xticklabelsize=None,
|
|
997
|
+
yticklabelsize=None,
|
|
998
|
+
xticklabelweight=None,
|
|
999
|
+
yticklabelweight=None,
|
|
1000
|
+
xlabel=None,
|
|
1001
|
+
ylabel=None,
|
|
1002
|
+
xlabelloc=None,
|
|
1003
|
+
ylabelloc=None,
|
|
1004
|
+
xlabelpad=None,
|
|
1005
|
+
ylabelpad=None,
|
|
1006
|
+
xlabelcolor=None,
|
|
1007
|
+
ylabelcolor=None,
|
|
1008
|
+
xlabelsize=None,
|
|
1009
|
+
ylabelsize=None,
|
|
1010
|
+
xlabelweight=None,
|
|
1011
|
+
ylabelweight=None,
|
|
1012
|
+
xgrid=None,
|
|
1013
|
+
ygrid=None,
|
|
1014
|
+
xgridminor=None,
|
|
1015
|
+
ygridminor=None,
|
|
1016
|
+
xgridcolor=None,
|
|
1017
|
+
ygridcolor=None,
|
|
1018
|
+
xlabel_kw=None,
|
|
1019
|
+
ylabel_kw=None,
|
|
1020
|
+
xscale_kw=None,
|
|
1021
|
+
yscale_kw=None,
|
|
1022
|
+
xlocator_kw=None,
|
|
1023
|
+
ylocator_kw=None,
|
|
1024
|
+
xformatter_kw=None,
|
|
1025
|
+
yformatter_kw=None,
|
|
1026
|
+
xminorlocator_kw=None,
|
|
1027
|
+
yminorlocator_kw=None,
|
|
1028
|
+
**kwargs,
|
|
1029
|
+
):
|
|
1030
|
+
"""
|
|
1031
|
+
Modify axes limits, axis scales, axis labels, spine locations,
|
|
1032
|
+
tick locations, tick labels, and more.
|
|
1033
|
+
|
|
1034
|
+
Parameters
|
|
1035
|
+
----------
|
|
1036
|
+
%(cartesian.format)s
|
|
1037
|
+
|
|
1038
|
+
Other parameters
|
|
1039
|
+
----------------
|
|
1040
|
+
%(axes.format)s
|
|
1041
|
+
%(figure.format)s
|
|
1042
|
+
%(rc.format)s
|
|
1043
|
+
|
|
1044
|
+
See also
|
|
1045
|
+
--------
|
|
1046
|
+
ultraplot.axes.Axes.format
|
|
1047
|
+
ultraplot.figure.Figure.format
|
|
1048
|
+
ultraplot.config.Configurator.context
|
|
1049
|
+
|
|
1050
|
+
Note
|
|
1051
|
+
----
|
|
1052
|
+
If you plot something with a `datetime64 \
|
|
1053
|
+
<https://docs.scipy.org/doc/numpy/reference/arrays.datetime.html>`__,
|
|
1054
|
+
`pandas.Timestamp`, `pandas.DatetimeIndex`, `datetime.date`, `datetime.time`,
|
|
1055
|
+
or `datetime.datetime` array as the x or y axis coordinate, the axis ticks
|
|
1056
|
+
and tick labels will be automatically formatted as dates.
|
|
1057
|
+
"""
|
|
1058
|
+
rc_kw, rc_mode = _pop_rc(kwargs)
|
|
1059
|
+
with rc.context(rc_kw, mode=rc_mode):
|
|
1060
|
+
# No mutable default args
|
|
1061
|
+
xlabel_kw = xlabel_kw or {}
|
|
1062
|
+
ylabel_kw = ylabel_kw or {}
|
|
1063
|
+
xscale_kw = xscale_kw or {}
|
|
1064
|
+
yscale_kw = yscale_kw or {}
|
|
1065
|
+
xlocator_kw = xlocator_kw or {}
|
|
1066
|
+
ylocator_kw = ylocator_kw or {}
|
|
1067
|
+
xformatter_kw = xformatter_kw or {}
|
|
1068
|
+
yformatter_kw = yformatter_kw or {}
|
|
1069
|
+
xminorlocator_kw = xminorlocator_kw or {}
|
|
1070
|
+
yminorlocator_kw = yminorlocator_kw or {}
|
|
1071
|
+
|
|
1072
|
+
# Color keyword arguments. Inherit from 'color' when necessary
|
|
1073
|
+
color = kwargs.pop("color", None)
|
|
1074
|
+
xcolor = _not_none(xcolor, color)
|
|
1075
|
+
ycolor = _not_none(ycolor, color)
|
|
1076
|
+
if "tick.color" not in rc_kw:
|
|
1077
|
+
xtickcolor = _not_none(xtickcolor, xcolor)
|
|
1078
|
+
ytickcolor = _not_none(ytickcolor, ycolor)
|
|
1079
|
+
if "tick.labelcolor" not in rc_kw:
|
|
1080
|
+
xticklabelcolor = _not_none(xticklabelcolor, xcolor)
|
|
1081
|
+
yticklabelcolor = _not_none(yticklabelcolor, ycolor)
|
|
1082
|
+
if "label.color" not in rc_kw:
|
|
1083
|
+
xlabelcolor = _not_none(xlabelcolor, xcolor)
|
|
1084
|
+
ylabelcolor = _not_none(ylabelcolor, ycolor)
|
|
1085
|
+
|
|
1086
|
+
# Flexible keyword args, declare defaults
|
|
1087
|
+
# NOTE: 'xtickdir' and 'ytickdir' read from 'tickdir' arguments here
|
|
1088
|
+
xmargin = _not_none(xmargin, rc.find("axes.xmargin", context=True))
|
|
1089
|
+
ymargin = _not_none(ymargin, rc.find("axes.ymargin", context=True))
|
|
1090
|
+
xtickdir = _not_none(xtickdir, rc.find("xtick.direction", context=True))
|
|
1091
|
+
ytickdir = _not_none(ytickdir, rc.find("ytick.direction", context=True))
|
|
1092
|
+
xlocator = _not_none(xlocator=xlocator, xticks=xticks)
|
|
1093
|
+
ylocator = _not_none(ylocator=ylocator, yticks=yticks)
|
|
1094
|
+
xminorlocator = _not_none(
|
|
1095
|
+
xminorlocator=xminorlocator, xminorticks=xminorticks
|
|
1096
|
+
) # noqa: E501
|
|
1097
|
+
yminorlocator = _not_none(
|
|
1098
|
+
yminorlocator=yminorlocator, yminorticks=yminorticks
|
|
1099
|
+
) # noqa: E501
|
|
1100
|
+
xformatter = _not_none(xformatter=xformatter, xticklabels=xticklabels)
|
|
1101
|
+
yformatter = _not_none(yformatter=yformatter, yticklabels=yticklabels)
|
|
1102
|
+
xtickminor_default = ytickminor_default = None
|
|
1103
|
+
if (
|
|
1104
|
+
isinstance(xformatter, mticker.FixedFormatter)
|
|
1105
|
+
or np.iterable(xformatter)
|
|
1106
|
+
and not isinstance(xformatter, str)
|
|
1107
|
+
): # noqa: E501
|
|
1108
|
+
xtickminor_default = False
|
|
1109
|
+
if (
|
|
1110
|
+
isinstance(yformatter, mticker.FixedFormatter)
|
|
1111
|
+
or np.iterable(yformatter)
|
|
1112
|
+
and not isinstance(yformatter, str)
|
|
1113
|
+
): # noqa: E501
|
|
1114
|
+
ytickminor_default = False
|
|
1115
|
+
xtickminor = _not_none(
|
|
1116
|
+
xtickminor,
|
|
1117
|
+
xtickminor_default,
|
|
1118
|
+
rc.find("xtick.minor.visible", context=True),
|
|
1119
|
+
) # noqa: E501
|
|
1120
|
+
ytickminor = _not_none(
|
|
1121
|
+
ytickminor,
|
|
1122
|
+
ytickminor_default,
|
|
1123
|
+
rc.find("ytick.minor.visible", context=True),
|
|
1124
|
+
) # noqa: E501
|
|
1125
|
+
ticklabeldir = kwargs.pop("ticklabeldir", None)
|
|
1126
|
+
xticklabeldir = _not_none(xticklabeldir, ticklabeldir)
|
|
1127
|
+
yticklabeldir = _not_none(yticklabeldir, ticklabeldir)
|
|
1128
|
+
xtickdir = _not_none(xtickdir, xticklabeldir)
|
|
1129
|
+
ytickdir = _not_none(ytickdir, yticklabeldir)
|
|
1130
|
+
|
|
1131
|
+
# Sensible defaults for spine, tick, tick label, and label locs
|
|
1132
|
+
# NOTE: Allow tick labels to be present without ticks! User may
|
|
1133
|
+
# want this sometimes! Same goes for spines!
|
|
1134
|
+
xspineloc = _not_none(xloc=xloc, xspineloc=xspineloc)
|
|
1135
|
+
yspineloc = _not_none(yloc=yloc, yspineloc=yspineloc)
|
|
1136
|
+
xside = self._get_spine_side("x", xspineloc)
|
|
1137
|
+
yside = self._get_spine_side("y", yspineloc)
|
|
1138
|
+
if xside is not None and xside not in ("zero", "center", "both"):
|
|
1139
|
+
xtickloc = _not_none(xtickloc, xside)
|
|
1140
|
+
if yside is not None and yside not in ("zero", "center", "both"):
|
|
1141
|
+
ytickloc = _not_none(ytickloc, yside)
|
|
1142
|
+
if xtickloc != "both": # then infer others
|
|
1143
|
+
xticklabelloc = _not_none(xticklabelloc, xtickloc)
|
|
1144
|
+
if xticklabelloc in ("bottom", "top"):
|
|
1145
|
+
xlabelloc = _not_none(xlabelloc, xticklabelloc)
|
|
1146
|
+
xoffsetloc = _not_none(xoffsetloc, yticklabelloc)
|
|
1147
|
+
if ytickloc != "both": # then infer others
|
|
1148
|
+
yticklabelloc = _not_none(yticklabelloc, ytickloc)
|
|
1149
|
+
if yticklabelloc in ("left", "right"):
|
|
1150
|
+
ylabelloc = _not_none(ylabelloc, yticklabelloc)
|
|
1151
|
+
yoffsetloc = _not_none(yoffsetloc, yticklabelloc)
|
|
1152
|
+
xtickloc = _not_none(xtickloc, rc._get_loc_string("x", "xtick"))
|
|
1153
|
+
ytickloc = _not_none(ytickloc, rc._get_loc_string("y", "ytick"))
|
|
1154
|
+
xspineloc = _not_none(xspineloc, rc._get_loc_string("x", "axes.spines"))
|
|
1155
|
+
yspineloc = _not_none(yspineloc, rc._get_loc_string("y", "axes.spines"))
|
|
1156
|
+
|
|
1157
|
+
# Loop over axes
|
|
1158
|
+
for (
|
|
1159
|
+
s,
|
|
1160
|
+
min_,
|
|
1161
|
+
max_,
|
|
1162
|
+
lim,
|
|
1163
|
+
reverse,
|
|
1164
|
+
margin,
|
|
1165
|
+
bounds,
|
|
1166
|
+
tickrange,
|
|
1167
|
+
wraprange,
|
|
1168
|
+
scale,
|
|
1169
|
+
scale_kw,
|
|
1170
|
+
spineloc,
|
|
1171
|
+
tickloc,
|
|
1172
|
+
ticklabelloc,
|
|
1173
|
+
labelloc,
|
|
1174
|
+
offsetloc,
|
|
1175
|
+
grid,
|
|
1176
|
+
gridminor,
|
|
1177
|
+
locator,
|
|
1178
|
+
locator_kw,
|
|
1179
|
+
minorlocator,
|
|
1180
|
+
minorlocator_kw,
|
|
1181
|
+
formatter,
|
|
1182
|
+
formatter_kw,
|
|
1183
|
+
label,
|
|
1184
|
+
label_kw,
|
|
1185
|
+
color,
|
|
1186
|
+
gridcolor,
|
|
1187
|
+
linewidth,
|
|
1188
|
+
rotation,
|
|
1189
|
+
tickminor,
|
|
1190
|
+
tickdir,
|
|
1191
|
+
tickcolor,
|
|
1192
|
+
ticklen,
|
|
1193
|
+
ticklenratio,
|
|
1194
|
+
tickwidth,
|
|
1195
|
+
tickwidthratio,
|
|
1196
|
+
ticklabeldir,
|
|
1197
|
+
ticklabelpad,
|
|
1198
|
+
ticklabelcolor,
|
|
1199
|
+
ticklabelsize,
|
|
1200
|
+
ticklabelweight,
|
|
1201
|
+
labelpad,
|
|
1202
|
+
labelcolor,
|
|
1203
|
+
labelsize,
|
|
1204
|
+
labelweight,
|
|
1205
|
+
) in zip(
|
|
1206
|
+
("x", "y"),
|
|
1207
|
+
(xmin, ymin),
|
|
1208
|
+
(xmax, ymax),
|
|
1209
|
+
(xlim, ylim),
|
|
1210
|
+
(xreverse, yreverse),
|
|
1211
|
+
(xmargin, ymargin),
|
|
1212
|
+
(xbounds, ybounds),
|
|
1213
|
+
(xtickrange, ytickrange),
|
|
1214
|
+
(xwraprange, ywraprange),
|
|
1215
|
+
(xscale, yscale),
|
|
1216
|
+
(xscale_kw, yscale_kw),
|
|
1217
|
+
(xspineloc, yspineloc),
|
|
1218
|
+
(xtickloc, ytickloc),
|
|
1219
|
+
(xticklabelloc, yticklabelloc),
|
|
1220
|
+
(xlabelloc, ylabelloc),
|
|
1221
|
+
(xoffsetloc, yoffsetloc),
|
|
1222
|
+
(xgrid, ygrid),
|
|
1223
|
+
(xgridminor, ygridminor),
|
|
1224
|
+
(xlocator, ylocator),
|
|
1225
|
+
(xlocator_kw, ylocator_kw),
|
|
1226
|
+
(xminorlocator, yminorlocator),
|
|
1227
|
+
(xminorlocator_kw, yminorlocator_kw),
|
|
1228
|
+
(xformatter, yformatter),
|
|
1229
|
+
(xformatter_kw, yformatter_kw),
|
|
1230
|
+
(xlabel, ylabel),
|
|
1231
|
+
(xlabel_kw, ylabel_kw),
|
|
1232
|
+
(xcolor, ycolor),
|
|
1233
|
+
(xgridcolor, ygridcolor),
|
|
1234
|
+
(xlinewidth, ylinewidth),
|
|
1235
|
+
(xrotation, yrotation),
|
|
1236
|
+
(xtickminor, ytickminor),
|
|
1237
|
+
(xtickdir, ytickdir),
|
|
1238
|
+
(xtickcolor, ytickcolor),
|
|
1239
|
+
(xticklen, yticklen),
|
|
1240
|
+
(xticklenratio, yticklenratio),
|
|
1241
|
+
(xtickwidth, ytickwidth),
|
|
1242
|
+
(xtickwidthratio, ytickwidthratio),
|
|
1243
|
+
(xticklabeldir, yticklabeldir),
|
|
1244
|
+
(xticklabelpad, yticklabelpad),
|
|
1245
|
+
(xticklabelcolor, yticklabelcolor),
|
|
1246
|
+
(xticklabelsize, yticklabelsize),
|
|
1247
|
+
(xticklabelweight, yticklabelweight),
|
|
1248
|
+
(xlabelpad, ylabelpad),
|
|
1249
|
+
(xlabelcolor, ylabelcolor),
|
|
1250
|
+
(xlabelsize, ylabelsize),
|
|
1251
|
+
(xlabelweight, ylabelweight),
|
|
1252
|
+
):
|
|
1253
|
+
# Axis scale
|
|
1254
|
+
# WARNING: This relies on monkey patch of mscale.scale_factory
|
|
1255
|
+
# that allows it to accept a custom scale class!
|
|
1256
|
+
# WARNING: Changing axis scale also changes default locators
|
|
1257
|
+
# and formatters, and restricts possible range of axis limits,
|
|
1258
|
+
# so critical to do it first.
|
|
1259
|
+
if scale is not None:
|
|
1260
|
+
scale = constructor.Scale(scale, **scale_kw)
|
|
1261
|
+
getattr(self, f"set_{s}scale")(scale)
|
|
1262
|
+
|
|
1263
|
+
# Axis limits
|
|
1264
|
+
self._update_limits(s, min_=min_, max_=max_, lim=lim, reverse=reverse)
|
|
1265
|
+
if margin is not None:
|
|
1266
|
+
self.margins(**{s: margin})
|
|
1267
|
+
|
|
1268
|
+
# Axis spine settings
|
|
1269
|
+
# NOTE: This sets spine-specific color and linewidth settings. For
|
|
1270
|
+
# non-specific settings _update_background is called in Axes.format()
|
|
1271
|
+
self._update_spines(s, loc=spineloc, bounds=bounds)
|
|
1272
|
+
self._update_background(
|
|
1273
|
+
s,
|
|
1274
|
+
edgecolor=color,
|
|
1275
|
+
linewidth=linewidth,
|
|
1276
|
+
tickwidth=tickwidth,
|
|
1277
|
+
tickwidthratio=tickwidthratio,
|
|
1278
|
+
)
|
|
1279
|
+
|
|
1280
|
+
# Axis tick settings
|
|
1281
|
+
self._update_locs(
|
|
1282
|
+
s,
|
|
1283
|
+
tickloc=tickloc,
|
|
1284
|
+
ticklabelloc=ticklabelloc,
|
|
1285
|
+
labelloc=labelloc,
|
|
1286
|
+
offsetloc=offsetloc,
|
|
1287
|
+
)
|
|
1288
|
+
self._update_rotation(s, rotation=rotation)
|
|
1289
|
+
self._update_ticks(
|
|
1290
|
+
s,
|
|
1291
|
+
grid=grid,
|
|
1292
|
+
gridminor=gridminor,
|
|
1293
|
+
ticklen=ticklen,
|
|
1294
|
+
ticklenratio=ticklenratio,
|
|
1295
|
+
tickdir=tickdir,
|
|
1296
|
+
labeldir=ticklabeldir,
|
|
1297
|
+
labelpad=ticklabelpad,
|
|
1298
|
+
tickcolor=tickcolor,
|
|
1299
|
+
gridcolor=gridcolor,
|
|
1300
|
+
labelcolor=ticklabelcolor,
|
|
1301
|
+
labelsize=ticklabelsize,
|
|
1302
|
+
labelweight=ticklabelweight,
|
|
1303
|
+
)
|
|
1304
|
+
|
|
1305
|
+
# Axis label settings
|
|
1306
|
+
# NOTE: This must come after set_label_position, or any ha and va
|
|
1307
|
+
# overrides in label_kw are overwritten.
|
|
1308
|
+
kw = dict(
|
|
1309
|
+
labelpad=labelpad,
|
|
1310
|
+
color=labelcolor,
|
|
1311
|
+
size=labelsize,
|
|
1312
|
+
weight=labelweight,
|
|
1313
|
+
**label_kw,
|
|
1314
|
+
)
|
|
1315
|
+
self._update_labels(s, label, **kw)
|
|
1316
|
+
|
|
1317
|
+
# Axis locator
|
|
1318
|
+
if minorlocator is True or minorlocator is False: # must test identity
|
|
1319
|
+
warnings._warn_ultraplot(
|
|
1320
|
+
f"You passed {s}minorticks={minorlocator}, but this argument "
|
|
1321
|
+
"is used to specify the tick locations. If you just want to "
|
|
1322
|
+
f"toggle minor ticks, please use {s}tickminor={minorlocator}."
|
|
1323
|
+
)
|
|
1324
|
+
minorlocator = None
|
|
1325
|
+
self._update_locators(
|
|
1326
|
+
s,
|
|
1327
|
+
locator,
|
|
1328
|
+
minorlocator,
|
|
1329
|
+
tickminor=tickminor,
|
|
1330
|
+
locator_kw=locator_kw,
|
|
1331
|
+
minorlocator_kw=minorlocator_kw,
|
|
1332
|
+
)
|
|
1333
|
+
|
|
1334
|
+
# Axis formatter
|
|
1335
|
+
self._update_formatter(
|
|
1336
|
+
s,
|
|
1337
|
+
formatter,
|
|
1338
|
+
formatter_kw=formatter_kw,
|
|
1339
|
+
tickrange=tickrange,
|
|
1340
|
+
wraprange=wraprange,
|
|
1341
|
+
)
|
|
1342
|
+
|
|
1343
|
+
# Ensure ticks are within axis bounds
|
|
1344
|
+
self._fix_ticks(s, fixticks=fixticks)
|
|
1345
|
+
|
|
1346
|
+
# Parent format method
|
|
1347
|
+
if aspect is not None:
|
|
1348
|
+
self.set_aspect(aspect)
|
|
1349
|
+
super().format(rc_kw=rc_kw, rc_mode=rc_mode, **kwargs)
|
|
1350
|
+
|
|
1351
|
+
@docstring._snippet_manager
|
|
1352
|
+
def altx(self, **kwargs):
|
|
1353
|
+
"""
|
|
1354
|
+
%(axes.altx)s
|
|
1355
|
+
"""
|
|
1356
|
+
return self._add_alt("x", **kwargs)
|
|
1357
|
+
|
|
1358
|
+
@docstring._snippet_manager
|
|
1359
|
+
def alty(self, **kwargs):
|
|
1360
|
+
"""
|
|
1361
|
+
%(axes.alty)s
|
|
1362
|
+
"""
|
|
1363
|
+
return self._add_alt("y", **kwargs)
|
|
1364
|
+
|
|
1365
|
+
@docstring._snippet_manager
|
|
1366
|
+
def dualx(self, funcscale, **kwargs):
|
|
1367
|
+
"""
|
|
1368
|
+
%(axes.dualx)s
|
|
1369
|
+
"""
|
|
1370
|
+
# NOTE: Matplotlib 3.1 has a 'secondary axis' feature. For the time
|
|
1371
|
+
# being, our version is more robust (see FuncScale) and simpler, since
|
|
1372
|
+
# we do not create an entirely separate _SecondaryAxis class.
|
|
1373
|
+
ax = self._add_alt("x", **kwargs)
|
|
1374
|
+
ax._dual_scale("x", funcscale)
|
|
1375
|
+
return ax
|
|
1376
|
+
|
|
1377
|
+
@docstring._snippet_manager
|
|
1378
|
+
def dualy(self, funcscale, **kwargs):
|
|
1379
|
+
"""
|
|
1380
|
+
%(axes.dualy)s
|
|
1381
|
+
"""
|
|
1382
|
+
ax = self._add_alt("y", **kwargs)
|
|
1383
|
+
ax._dual_scale("y", funcscale)
|
|
1384
|
+
return ax
|
|
1385
|
+
|
|
1386
|
+
@docstring._snippet_manager
|
|
1387
|
+
def twinx(self, **kwargs):
|
|
1388
|
+
"""
|
|
1389
|
+
%(axes.twinx)s
|
|
1390
|
+
"""
|
|
1391
|
+
return self._add_alt("y", **kwargs)
|
|
1392
|
+
|
|
1393
|
+
@docstring._snippet_manager
|
|
1394
|
+
def twiny(self, **kwargs):
|
|
1395
|
+
"""
|
|
1396
|
+
%(axes.twiny)s
|
|
1397
|
+
"""
|
|
1398
|
+
return self._add_alt("x", **kwargs)
|
|
1399
|
+
|
|
1400
|
+
def draw(self, renderer=None, *args, **kwargs):
|
|
1401
|
+
# Perform extra post-processing steps
|
|
1402
|
+
# NOTE: In *principle* axis sharing application step goes here. But should
|
|
1403
|
+
# already be complete because auto_layout() (called by figure pre-processor)
|
|
1404
|
+
# has to run it before aligning labels. So this is harmless no-op.
|
|
1405
|
+
self._dual_scale("x")
|
|
1406
|
+
self._dual_scale("y")
|
|
1407
|
+
self._apply_axis_sharing()
|
|
1408
|
+
self._update_rotation("x")
|
|
1409
|
+
super().draw(renderer, *args, **kwargs)
|
|
1410
|
+
|
|
1411
|
+
def get_tightbbox(self, renderer, *args, **kwargs):
|
|
1412
|
+
# Perform extra post-processing steps
|
|
1413
|
+
self._dual_scale("x")
|
|
1414
|
+
self._dual_scale("y")
|
|
1415
|
+
self._apply_axis_sharing()
|
|
1416
|
+
self._update_rotation("x")
|
|
1417
|
+
return super().get_tightbbox(renderer, *args, **kwargs)
|
|
1418
|
+
|
|
1419
|
+
|
|
1420
|
+
# Apply signature obfuscation after storing previous signature
|
|
1421
|
+
# NOTE: This is needed for __init__, altx, and alty
|
|
1422
|
+
CartesianAxes._format_signatures[CartesianAxes] = inspect.signature(
|
|
1423
|
+
CartesianAxes.format
|
|
1424
|
+
) # noqa: E501
|
|
1425
|
+
CartesianAxes.format = docstring._obfuscate_kwargs(CartesianAxes.format)
|