Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed as not planned
Closed as not planned
Description
Bug report
Bug summary
Adding twin axes to another axis created with gridhelper GridHelperCurveLinear makes some of the ticklabels of the polar grid disappear.
Code for reproduction
Working fine:
importnumpyasnpimportmatplotlib.pyplotaspltfrommpl_toolkits.axisartistimportSubplotHostfrommpl_toolkits.axisartist.grid_helper_curvelinearimportGridHelperCurveLinearimportmpl_toolkits.axisartist.angle_helperasangle_helperfrommatplotlib.projectionsimportPolarAxesfrommatplotlib.transformsimportAffine2DclassFormatterDMS(object):'''Transforms angle ticks to damping ratios'''def__call__(self,direction,factor,values):angles_deg=values/factordamping_ratios=np.cos((180-angles_deg)*np.pi/180)ret= ["%.2f"%valforvalindamping_ratios]returnretclassModifiedExtremeFinderCycle(angle_helper.ExtremeFinderCycle):'''Changed to allow only left hand-side polar grid'''def__call__(self,transform_xy,x1,y1,x2,y2):x_,y_=np.linspace(x1,x2,self.nx),np.linspace(y1,y2,self.ny)x,y=np.meshgrid(x_,y_)lon,lat=transform_xy(np.ravel(x),np.ravel(y))withnp.errstate(invalid='ignore'):ifself.lon_cycleisnotNone:lon0=np.nanmin(lon)lon-=360.* ((lon-lon0)>360.)# Changed from 180 to 360 to be able to span only 90-270 (left hand side)ifself.lat_cycleisnotNone:lat0=np.nanmin(lat)lat-=360.* ((lat-lat0)>360.)# Changed from 180 to 360 to be able to span only 90-270 (left hand side)lon_min,lon_max=np.nanmin(lon),np.nanmax(lon)lat_min,lat_max=np.nanmin(lat),np.nanmax(lat)lon_min,lon_max,lat_min,lat_max= \self._adjust_extremes(lon_min,lon_max,lat_min,lat_max)returnlon_min,lon_max,lat_min,lat_maxdefsgrid():# From matplotlib demos:# https://matplotlib.org/gallery/axisartist/demo_curvelinear_grid.html# https://matplotlib.org/gallery/axisartist/demo_floating_axis.html# PolarAxes.PolarTransform takes radian. However, we want our coordinate# system in degreetr=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 directionsampling_points=20extreme_finder=ModifiedExtremeFinderCycle(sampling_points,sampling_points,lon_cycle=360,lat_cycle=None,lon_minmax=(90,270),lat_minmax=(0,np.inf),)grid_locator1=angle_helper.LocatorDMS(15)tick_formatter1=FormatterDMS()grid_helper=GridHelperCurveLinear(tr,extreme_finder=extreme_finder,grid_locator1=grid_locator1,tick_formatter1=tick_formatter1 )fig=plt.figure()ax=SubplotHost(fig,1,1,1,grid_helper=grid_helper)# make ticklabels of right invisible, and top axis visible.visible=Trueax.axis[:].major_ticklabels.set_visible(visible)ax.axis[:].major_ticks.set_visible(False)ax.axis[:].invert_ticklabel_direction()ax.axis["wnxneg"]=axis=ax.new_floating_axis(0,180)axis.set_ticklabel_direction("-")axis.label.set_visible(False)# let left axis shows ticklabels for 1st coordinate (angle)ax.axis["left"].get_helper().nth_coord_ticks=0ax.axis["right"].get_helper().nth_coord_ticks=0ax.axis["left"].get_helper().nth_coord_ticks=0ax.axis["bottom"].get_helper().nth_coord_ticks=0fig.add_subplot(ax)ax.grid(True,zorder=0,linestyle='dotted')returnax,figax,f=sgrid()ax.plot([-5,5],[-5,5])
Adding this however:
par2 = ax.twin() new_fixed_axis = par2.get_grid_helper().new_fixed_axis par2.axis["left"] = new_fixed_axis(loc="left", axes=par2, offset=(0, 0)) par2.axis["bottom"] = new_fixed_axis(loc="bottom", axes=par2, offset=(0, 0))
Results in lost ticklabels for the upper part:
Matplotlib version
- Operating system: Windows 10
- Matplotlib version: 2.1.2
- Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg - Python version: 3.6.4
Installed from pip.