def curvelinear_test4(fig): """ polar projection, but in a rectangular box. """ global ax1, axis import numpy as np import angle_helper from matplotlib.projections import PolarAxes tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform() grid_locator1 = angle_helper.LocatorDMS(5) tick_formatter1 = angle_helper.FormatterDMS() from grid_finder import FixedLocator grid_locator2 = FixedLocator([2, 4, 6, 8, 10]) grid_helper = GridHelperCurveLinear( tr, extremes=(120, 30, 10, 0), grid_locator1=grid_locator1, grid_locator2=grid_locator2, tick_formatter1=tick_formatter1, tick_formatter2=None, ) ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper) #ax1.axis["top"].set_visible(False) #ax1.axis["bottom"].major_ticklabels.set_axis_direction("top") fig.add_subplot(ax1) #ax1.grid(True) ax1.axis["left"].label.set_text("Test 1") ax1.axis["right"].label.set_text("Test 2") for an in ["top"]: ax1.axis[an].set_visible(False) #grid_helper2 = ax1.get_grid_helper() ax1.axis["z"] = axis = grid_helper.new_floating_axis( 1, 70, axes=ax1, axis_direction="bottom") axis.toggle(all=True, label=True) axis.label.set_axis_direction("top") axis.label.set_text("z = ?") axis.label.set_visible(True) axis.line.set_color("0.5") #axis.label.set_visible(True) ax2 = ax1.get_aux_axes(tr) xx, yy = [67, 90, 75, 30], [2, 5, 8, 4] ax2.scatter(xx, yy) l, = ax2.plot(xx, yy, "k-") l.set_clip_path(ax1.patch)
def curvelinear_test3(fig): """ polar projection, but in a rectangular box. """ global ax1, axis import numpy as np import angle_helper from matplotlib.projections import PolarAxes # PolarAxes.PolarTransform takes radian. However, we want our coordinate # system in degree tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform() # polar projection, which involves cycle, and also has limits in # its coordinates, needs a special method to find the extremes # (min, max of the coordinate within the view). grid_locator1 = angle_helper.LocatorDMS(15) # Find a grid values appropriate for the coordinate (degree, # minute, second). tick_formatter1 = angle_helper.FormatterDMS() # And also uses an appropriate formatter. Note that,the # acceptable Locator and Formatter class is a bit different than # that of mpl's, and you cannot directly use mpl's Locator and # Formatter here (but may be possible in the future). from grid_finder import FixedLocator grid_locator2 = FixedLocator([2, 4, 6, 8, 10]) grid_helper = GridHelperCurveLinear( tr, extremes=(0, 360, 10, 3), grid_locator1=grid_locator1, grid_locator2=grid_locator2, tick_formatter1=tick_formatter1, tick_formatter2=None, ) ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper) #ax1.axis["top"].set_visible(False) #ax1.axis["bottom"].major_ticklabels.set_axis_direction("top") fig.add_subplot(ax1) #ax1.grid(True) r_scale = 10. tr2 = Affine2D().scale(1., 1. / r_scale) + tr grid_locator2 = FixedLocator([30, 60, 90]) grid_helper2 = GridHelperCurveLinear( tr2, extremes=(0, 360, 10. * r_scale, 3. * r_scale), grid_locator2=grid_locator2, ) ax1.axis["right"] = axis = grid_helper2.new_fixed_axis("right", axes=ax1) ax1.axis["left"].label.set_text("Test 1") ax1.axis["right"].label.set_text("Test 2") for an in ["left", "right"]: ax1.axis[an].set_visible(False) #grid_helper2 = ax1.get_grid_helper() ax1.axis["z"] = axis = grid_helper.new_floating_axis( 1, 7, axes=ax1, axis_direction="bottom") axis.toggle(all=True, label=True) #axis.label.set_axis_direction("top") axis.label.set_text("z = ?") axis.label.set_visible(True) axis.line.set_color("0.5") #axis.label.set_visible(True) ax2 = ax1.get_aux_axes(tr) xx, yy = [67, 90, 75, 30], [2, 5, 8, 4] ax2.scatter(xx, yy) l, = ax2.plot(xx, yy, "k-") l.set_clip_path(ax1.patch)
def curvelinear_test3(fig): """ polar projection, but in a rectangular box. """ global ax1, axis import numpy as np import angle_helper from matplotlib.projections import PolarAxes from matplotlib.transforms import Affine2D from mpl_toolkits.axes_grid.parasite_axes import SubplotHost # PolarAxes.PolarTransform takes radian. However, we want our coordinate # system in degree tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform() # polar projection, which involves cycle, and also has limits in # its coordinates, needs a special method to find the extremes # (min, max of the coordinate within the view). # 20, 20 : number of sampling points along x, y direction 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) # Find a grid values appropriate for the coordinate (degree, # minute, second). tick_formatter1 = angle_helper.FormatterDMS() # And also uses an appropriate formatter. Note that,the # acceptable Locator and Formatter class is a bit different than # that of mpl's, and you cannot directly use mpl's Locator and # Formatter here (but may be possible in the future). grid_helper = GridHelperCurveLinear(tr, extreme_finder=extreme_finder, grid_locator1=grid_locator1, tick_formatter1=tick_formatter1) ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) for axis in ax1.axis.itervalues(): axis.set_visible(False) fig.add_subplot(ax1) grid_helper = ax1.get_grid_helper() ax1.axis["lat1"] = axis = grid_helper.new_floating_axis( 0, 130, axes=ax1, axis_direction="left") axis.label.set_text("Test") axis.label.set_visible(True) axis.get_helper()._extremes = 0.001, 10 grid_helper = ax1.get_grid_helper() ax1.axis["lat2"] = axis = grid_helper.new_floating_axis( 0, 50, axes=ax1, axis_direction="right") axis.label.set_text("Test") axis.label.set_visible(True) axis.get_helper()._extremes = 0.001, 10 ax1.axis["lon"] = axis = grid_helper.new_floating_axis( 1, 10, axes=ax1, axis_direction="bottom") axis.label.set_text("Test 2") axis.get_helper()._extremes = 50, 130 axis.major_ticklabels.set_axis_direction("top") axis.label.set_axis_direction("top") grid_helper.grid_finder.grid_locator1.den = 5 grid_helper.grid_finder.grid_locator2._nbins = 5 # # A parasite axes with given transform # ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal") # # note that ax2.transData == tr + ax1.transData # # Anthing you draw in ax2 will match the ticks and grids of ax1. # ax1.parasites.append(ax2) # intp = cbook.simple_linear_interpolation # ax2.plot(intp(np.array([0, 30]), 50), # intp(np.array([10., 10.]), 50)) ax1.set_aspect(1.) ax1.set_xlim(-5, 12) ax1.set_ylim(-5, 10) ax1.grid(True)