how to fix axes position by using set_position method in python matplotlib?

…衆ロ難τιáo~ 提交于 2019-12-05 01:29:48

Try setting the position by specifying the parameters as a Bbox object:

>>> ax2.set_position(matplotlib.transforms.Bbox(array([[0.125,0.63],[0.25,0.25]])))
>>> ax2.get_position()
Bbox(array([[ 0.125,  0.63 ],
       [ 0.25 ,  0.25 ]]))
>>> draw()
>>> ax2.get_position()
Bbox(array([[ 0.125,  0.63 ],
       [ 0.25 ,  0.25 ]]))

With this you can see the settings are round-tripping like you would expect.

In addition, you could instead look at the results as a tuple like so:

>>> a.set_position([0.125,0.63,0.25,0.25])
>>> a.get_position().bounds
(0.125, 0.63, 0.25, 0.25)

It just depends if you want to look at the location/position as a bounding box: x0,y0 by x1,y1, or instead by a location and size: x,y,width,height.

Currently you are telling it to set a x,y,width,height, then it's telling you the x0,y0,x1,y1.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!