I am using ax.axes('equal')
to make the axis spacing equal on X and Y, and also setting xlim
and ylim
. This over-constrains the problem and the actual limits are not what I set in ax.set_xlim()
or ax.set_ylim()
. Using ax.get_xlim()
just returns what I provided. How can I get the actual visible limits of the plot?
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
What commands will let me draw the green box around the actual edges of the figure?
Related: Force xlim
, ylim
, and axes('equal')
at the same time by letting margins auto-adjust