|
| 1 | +""" |
| 2 | +A floating axes for curvelinear grid. |
| 3 | +. |
| 4 | +""" |
| 5 | + |
| 6 | + |
| 7 | +def curvelinear_test2(fig): |
| 8 | + """ |
| 9 | + polar projection, but in a rectangular box. |
| 10 | + """ |
| 11 | + import numpy as np |
| 12 | + import mpl_toolkits.axes_grid.angle_helper as angle_helper |
| 13 | + from matplotlib.projections import PolarAxes |
| 14 | + from matplotlib.transforms import Affine2D |
| 15 | + |
| 16 | + from mpl_toolkits.axes_grid.parasite_axes import SubplotHost |
| 17 | + |
| 18 | + from mpl_toolkits.axes_grid.grid_helper_curvelinear import GridHelperCurveLinear |
| 19 | + |
| 20 | + # see demo_curvelinear_grid.py for details |
| 21 | + tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform() |
| 22 | + |
| 23 | + extreme_finder = angle_helper.ExtremeFinderCycle(20, 20, |
| 24 | + lon_cycle = 360, |
| 25 | + lat_cycle = None, |
| 26 | + lon_minmax = None, |
| 27 | + lat_minmax = (0, np.inf), |
| 28 | + ) |
| 29 | + |
| 30 | + grid_locator1 = angle_helper.LocatorDMS(12) |
| 31 | + |
| 32 | + tick_formatter1 = angle_helper.FormatterDMS() |
| 33 | + |
| 34 | + grid_helper = GridHelperCurveLinear(tr, |
| 35 | + extreme_finder=extreme_finder, |
| 36 | + grid_locator1=grid_locator1, |
| 37 | + tick_formatter1=tick_formatter1 |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | + ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) |
| 42 | + |
| 43 | + # make ticklabels of right and top axis visible. |
| 44 | + for axis in ax1.axis.values(): |
| 45 | + axis.toggle(all=False) |
| 46 | + |
| 47 | + fig.add_subplot(ax1) |
| 48 | + |
| 49 | + # Now creates floating axis |
| 50 | + |
| 51 | + grid_helper = ax1.get_grid_helper() |
| 52 | + # floating axis whose first coordinate (theta) is fixed at 60 |
| 53 | + ax1.axis["lat"] = axis = grid_helper.new_floating_axis(0, 60, axes=ax1) |
| 54 | + axis.label.set_text(r"$\theta = 60^{\circ}$") |
| 55 | + axis.label.set_visible(True) |
| 56 | + |
| 57 | + # floating axis whose second coordinate (r) is fixed at 6 |
| 58 | + ax1.axis["lon"] = axis = grid_helper.new_floating_axis(1, 6, axes=ax1) |
| 59 | + axis.label.set_text(r"$r = 6$") |
| 60 | + |
| 61 | + ax1.set_aspect(1.) |
| 62 | + ax1.set_xlim(-5, 12) |
| 63 | + ax1.set_ylim(-5, 10) |
| 64 | + |
| 65 | + ax1.grid(True) |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + import matplotlib.pyplot as plt |
| 69 | + fig = plt.figure(1, figsize=(5, 5)) |
| 70 | + fig.clf() |
| 71 | + |
| 72 | + curvelinear_test2(fig) |
| 73 | + |
| 74 | + plt.draw() |
| 75 | + plt.show() |
| 76 | + |
| 77 | + |
0 commit comments