From c5bc302e8b20c14ea3bf762921c580e327cb1a2d Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 31 Jul 2025 10:56:46 +0200 Subject: [PATCH] Shorten setup of axes in simple_axis_pad demo. The code follows the style in demo_axis_direction. The new version remains reasonably legible, and that setup is not really the point of the example anyways (which is about axis padding). Also remove special handling of underscore which is now unnecessary since usetex already auto-handles that. --- .../axisartist/demo_axis_direction.py | 8 +-- .../examples/axisartist/simple_axis_pad.py | 52 ++++++------------- 2 files changed, 19 insertions(+), 41 deletions(-) diff --git a/galleries/examples/axisartist/demo_axis_direction.py b/galleries/examples/axisartist/demo_axis_direction.py index 205315072ce5..6bc46fe273a0 100644 --- a/galleries/examples/axisartist/demo_axis_direction.py +++ b/galleries/examples/axisartist/demo_axis_direction.py @@ -10,8 +10,7 @@ from matplotlib.projections import PolarAxes from matplotlib.transforms import Affine2D import mpl_toolkits.axisartist as axisartist -import mpl_toolkits.axisartist.angle_helper as angle_helper -import mpl_toolkits.axisartist.grid_finder as grid_finder +from mpl_toolkits.axisartist import angle_helper, grid_finder from mpl_toolkits.axisartist.grid_helper_curvelinear import GridHelperCurveLinear @@ -19,10 +18,7 @@ def setup_axes(fig, rect): """Polar projection, but in a rectangular box.""" # see demo_curvelinear_grid.py for details grid_helper = GridHelperCurveLinear( - ( - Affine2D().scale(np.pi/180., 1.) + - PolarAxes.PolarTransform() - ), + Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform(), extreme_finder=angle_helper.ExtremeFinderCycle( 20, 20, lon_cycle=360, lat_cycle=None, diff --git a/galleries/examples/axisartist/simple_axis_pad.py b/galleries/examples/axisartist/simple_axis_pad.py index fcd58885a57a..f436ae3ab79c 100644 --- a/galleries/examples/axisartist/simple_axis_pad.py +++ b/galleries/examples/axisartist/simple_axis_pad.py @@ -11,44 +11,29 @@ from matplotlib.projections import PolarAxes from matplotlib.transforms import Affine2D import mpl_toolkits.axisartist as axisartist -import mpl_toolkits.axisartist.angle_helper as angle_helper -import mpl_toolkits.axisartist.grid_finder as grid_finder +from mpl_toolkits.axisartist import angle_helper, grid_finder from mpl_toolkits.axisartist.grid_helper_curvelinear import GridHelperCurveLinear def setup_axes(fig, rect): """Polar projection, but in a rectangular box.""" - # see demo_curvelinear_grid.py for details - tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform() - - extreme_finder = angle_helper.ExtremeFinderCycle(20, 20, - lon_cycle=360, - lat_cycle=None, - lon_minmax=None, - lat_minmax=(0, np.inf), - ) - - grid_locator1 = angle_helper.LocatorDMS(12) - grid_locator2 = grid_finder.MaxNLocator(5) - - tick_formatter1 = angle_helper.FormatterDMS() - - grid_helper = GridHelperCurveLinear(tr, - extreme_finder=extreme_finder, - grid_locator1=grid_locator1, - grid_locator2=grid_locator2, - tick_formatter1=tick_formatter1 - ) - - ax1 = fig.add_subplot( - rect, axes_class=axisartist.Axes, grid_helper=grid_helper) - ax1.axis[:].set_visible(False) - ax1.set_aspect(1.) - ax1.set_xlim(-5, 12) - ax1.set_ylim(-5, 10) - - return ax1 + grid_helper = GridHelperCurveLinear( + Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform(), + extreme_finder=angle_helper.ExtremeFinderCycle( + 20, 20, + lon_cycle=360, lat_cycle=None, + lon_minmax=None, lat_minmax=(0, np.inf), + ), + grid_locator1=angle_helper.LocatorDMS(12), + grid_locator2=grid_finder.MaxNLocator(5), + tick_formatter1=angle_helper.FormatterDMS(), + ) + ax = fig.add_subplot( + rect, axes_class=axisartist.Axes, grid_helper=grid_helper, + aspect=1, xlim=(-5, 12), ylim=(-5, 10)) + ax.axis[:].set_visible(False) + return ax def add_floating_axis1(ax1): @@ -73,9 +58,6 @@ def add_floating_axis2(ax1): def ann(ax1, d): - if plt.rcParams["text.usetex"]: - d = d.replace("_", r"\_") - ax1.annotate(d, (0.5, 1), (5, -5), xycoords="axes fraction", textcoords="offset points", va="top", ha="center") pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy