1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| import numpy as np
import matplotlib.pyplot as plt import matplotlib.cbook as cbook
from mpl_toolkits.axisartist import Subplot from mpl_toolkits.axisartist import SubplotHost, \ ParasiteAxesAuxTrans from mpl_toolkits.axisartist.grid_helper_curvelinear import \ GridHelperCurveLinear
def curvelinear_test1(fig): """ grid for custom transform. """
def tr(x, y): x, y = np.asarray(x), np.asarray(y) return x, y - x
def inv_tr(x, y): x, y = np.asarray(x), np.asarray(y) return x, y + x
grid_helper = GridHelperCurveLinear((tr, inv_tr))
ax1 = Subplot(fig, 1, 2, 1, grid_helper=grid_helper)
fig.add_subplot(ax1)
xx, yy = tr([3, 6], [5.0, 10.]) ax1.plot(xx, yy, linewidth=2.0)
ax1.set_aspect(1.) ax1.set_xlim(0, 10.) ax1.set_ylim(0, 10.)
ax1.axis["t"] = ax1.new_floating_axis(0, 3.) ax1.axis["t2"] = ax1.new_floating_axis(1, 7.) ax1.grid(True, zorder=0)
import mpl_toolkits.axisartist.angle_helper as angle_helper
from matplotlib.projections import PolarAxes from matplotlib.transforms import Affine2D
def curvelinear_test2(fig): """ polar projection, but in a rectangular box. """
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)
tick_formatter1 = angle_helper.FormatterDMS()
grid_helper = GridHelperCurveLinear(tr, extreme_finder=extreme_finder, grid_locator1=grid_locator1, tick_formatter1=tick_formatter1 )
ax1 = SubplotHost(fig, 1, 2, 2, grid_helper=grid_helper)
ax1.axis["right"].major_ticklabels.set_visible(True) ax1.axis["top"].major_ticklabels.set_visible(True)
ax1.axis["right"].get_helper().nth_coord_ticks = 0 ax1.axis["bottom"].get_helper().nth_coord_ticks = 1
fig.add_subplot(ax1)
ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal") ax1.parasites.append(ax2) intp = cbook.simple_linear_interpolation ax2.plot(intp(np.array([0, 30]), 50), intp(np.array([10., 10.]), 50), linewidth=2.0)
ax1.set_aspect(1.) ax1.set_xlim(-5, 12) ax1.set_ylim(-5, 10)
ax1.grid(True, zorder=0)
if 1: fig = plt.figure(1, figsize=(7, 4)) fig.clf()
curvelinear_test1(fig) curvelinear_test2(fig)
plt.show()
|