【发布时间】:2017-02-05 10:16:30
【问题描述】:
我使用ax.axes('equal') 使X 和Y 上的轴间距相等,并设置xlim 和ylim。这过度约束了问题,实际限制不是我在ax.set_xlim() 或ax.set_ylim() 中设置的。使用 ax.get_xlim() 只会返回我提供的内容。如何获得绘图的实际可见限制?
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_changed',ylim_ch)更改ylim的通知,但它仍然返回给set_ylim的值,而不是显示的值。见stackoverflow.com/questions/31490436/…
标签: python python-2.7 matplotlib plot