我使用ax.axes('equal')
做出关于X和Y轴间距相等,并且还设置xlim
和ylim
。这会限制这个问题,实际限制并不是我在ax.set_xlim()
或ax.set_ylim()
中设置的。使用ax.get_xlim()
只是返回我提供的。我怎样才能得到情节的实际可见限度?如何在使用ax.axis('equal')时获得实际的轴限制?
f,ax=plt.subplots(1) #open a figure
ax.axis('equal') #make the axes have equal spacing
ax.plot([0,20],[0,20]) #test data set
#change the plot axis limits
ax.set_xlim([2,18])
ax.set_ylim([5,15])
#read the plot axis limits
xlim2=array(ax.get_xlim())
ylim2=array(ax.get_ylim())
#define indices for drawing a rectangle with xlim2, ylim2
sqx=array([0,1,1,0,0])
sqy=array([0,0,1,1,0])
#plot a thick rectangle marking the xlim2, ylim2
ax.plot(xlim2[sqx],ylim2[sqy],lw=3) #this does not go all the way around the edge
什么命令会让我在图形的实际边缘周围绘制绿色框?
相关:Force xlim
, ylim
, and axes('equal')
at the same time by letting margins auto-adjust
我能得到的改''通过ax.callbacks.connect ylim'通知(“ylim_changed”,ylim_ch)',但它仍然会返回给'set_ylim'的价值,而不是显示什么。请参阅http://stackoverflow.com/questions/31490436/matplotlib-finding-out-xlim-and-ylim-after-zoom –