I use ax.axes('equal')to make the distance of the axis equal to X and Y, and also set xlimand ylim. This overly limits 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 have provided. How can I get the actual visible limits of the plot?
ax.axes('equal')
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
What commands will allow me to draw a green border around the actual edges of the shape?
It linked: the Force xlim, ylim, and axes('equal')at the same time, allowing the automatic margin settings
axes('equal')
, . xlim ylim, xlim ylim, .
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]) #Drawing is crucial f.canvas.draw() #<---------- I added this line #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)
, , , XY? , , , xlim ylim. ax.transAxes, x, y , :
ax.transAxes
x
y
ax.plot([0,0,1,1,0],[0,1,1,0,0], lw=3, transform=ax.transAxes)
, , xlim ylim .
transform=ax.xaxis.get_transform() transform=ax.yaxis.get_transform(), , x y, - .
transform=ax.xaxis.get_transform()
transform=ax.yaxis.get_transform()
Source: https://habr.com/ru/post/1655988/More articles:Defining short, private PHP nested functions (subfunctions) - best performance? best practice? - performanceTesting and service dependency - azure-service-fabricJava Spring Boot test: how to exclude Java configuration class from test context - javaHow to use ReduceByKey on multiple keys in Scala Spark Job - scalahow to call a function in another object when changing a variable. python - pythonRetrieving Twitter status via REST API does not always return multimedia URLs - twitterSubclass list without deep copy - pythonHow to enforce xlim and ylim when using ax.axis ('equal')? - pythonArquillian: starts the server but does not deploy - javargl: draw a cube with colored faces, vertices, and lines - rAll Articles