我想使用ax.axis('equal')
强制 X 和 Y 上的间距均匀,但我还想指定 X 和 Y 轴的特定范围。如果边距也固定的话,问题就过约束了,结果如图1左侧所示。相反,如果允许边距自动增加以弥补闲置,则 xlim
和ylim
可以保持我设置的状态,同时仍然令人满意axis('equal')
。我所追求的示例如图 1 右侧所示。 如何让绘图边距“ float ”?
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
最佳答案
关于python - 如何在使用 ax.axis ('equal' 时强制执行 xlim 和 ylim )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39775709/