I am trying to reposition and stretch a curvilinear coordinate axis created with floating_axes.FloatingSubplot
after the axis has been created. In an older version of matplotlib, I was able to do this successfully with code the following code:
horiz = [Size.Scaled(1.0)]
vert = [Size.Scaled(1.0)]
ax1_div = Divider(fig,[0.0, 0.0, 1.0, 0.45],horiz,vert,aspect=False) # Curvilinear Coordinates
ax1_loc = ax1_div.new_locator(nx=0,ny=0) # Curvilinear Coordinates
ax1.set_axes_locator(ax1_loc) # Curvilinear Coordinates
In the image below, I want to be able to stretch the curvilinear coordinate system so that its x-axis is aligned with the rectangular coordinate system. Older versions of matplotlib did this, but in matplotlib version 3.3.4 I can only get the axis to translate, but not stretch.
Does anyone know how to do this? ax.set_position()
does not work here. My problem is similar to this question which received no answers.
Here is my code that generated the figure:
#!/usr/bin/env python3
from matplotlib import pyplot as plt
from matplotlib.transforms import Affine2D, Transform
import mpl_toolkits.axisartist.floating_axes as floating_axes
from matplotlib.projections import polar
from mpl_toolkits.axisartist.grid_finder import FixedLocator, DictFormatter
import mpl_toolkits.axes_grid1.axes_size as Size
from mpl_toolkits.axes_grid1 import Divider
fig = plt.figure()
# Generate first axis using normal methods.
ax0 = fig.add_subplot(111)
ax0.set_xticks([0,500,1000,1500,2000])
# Generate a curvilear axis for the second axis.
angle_ticks = [(0, '0'), (0.079, '500'), (0.157, '1000'), (0.235, '1500'), (0.314, '2000')]
grid_locator1 = FixedLocator([v for v, s in angle_ticks])
tick_formatter1 = DictFormatter(dict(angle_ticks))
alt_ticks = [(6371.0, '0'), (6671.0, '300'), (6971.0, '600'), (7271.0, '900'), (7571.0, '1200')]
grid_locator2 = FixedLocator([v for v, s in alt_ticks])
tick_formatter2 = DictFormatter(dict(alt_ticks))
tr_rotate = Affine2D().rotate(1.414)
tr_shift = Affine2D().translate(0, 6371)
tr = polar.PolarTransform() + tr_rotate
grid_helper = \
floating_axes.GridHelperCurveLinear(tr, extremes=(0, 0.314, 6371, 7871),
grid_locator1=grid_locator1,
grid_locator2=grid_locator2,
tick_formatter1=tick_formatter1,
tick_formatter2=tick_formatter2,)
ax1 = floating_axes.FloatingSubplot(fig, 111, grid_helper=grid_helper)
ax1.invert_xaxis()
fig.add_subplot(ax1, transform=tr)
horiz = [Size.Scaled(1.0)]
vert = [Size.Scaled(1.0)]
ax0_div = Divider(fig,[0.0, 0.5, 1.0, 0.45],horiz,vert,aspect=False) # Rectangular Coordinates
ax1_div = Divider(fig,[0.0, 0.0, 1.0, 0.45],horiz,vert,aspect=False) # Curvilinear Coordinates
ax0_loc = ax0_div.new_locator(nx=0,ny=0) # Rectangular Coordinates
ax1_loc = ax1_div.new_locator(nx=0,ny=0) # Curvilinear Coordinates
ax0.set_axes_locator(ax0_loc) # Rectangular Coordinates
ax1.set_axes_locator(ax1_loc) # Curvilinear Coordinates
fig.savefig('bug_report.png',bbox_inches='tight')