Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting aspect ratio of 3D plot

People also ask

How do I make matplotlib Square?

axis() Method to Generate Square PlotIf we pass "square" as an argument to matplotlib. pyplot. axis() , it creates a square plot where the ranges for both axes occupy are equal to the length in plot. The range of axes in this solution are selected automatically.

How do I tell what version of matplotlib I have?

Once you've successfully installed matplotlib, you can use the following command to display the matplotlib version in your environment: pip show matplotlib Name: matplotlib Version: 3.1.


Add following code before savefig:

ax.auto_scale_xyz([0, 500], [0, 500], [0, 0.15])

enter image description here

If you want no square axis:

edit the get_proj function inside site-packages\mpl_toolkits\mplot3d\axes3d.py:

xmin, xmax = np.divide(self.get_xlim3d(), self.pbaspect[0])
ymin, ymax = np.divide(self.get_ylim3d(), self.pbaspect[1])
zmin, zmax = np.divide(self.get_zlim3d(), self.pbaspect[2])

then add one line to set pbaspect:

ax = fig.gca(projection = '3d')
ax.pbaspect = [2.0, 0.6, 0.25]

enter image description here


The answer to this question works perfectly for me. And you do not need to set up any ratio, it does everything automatically.


An issue has been opened over at github: https://github.com/matplotlib/matplotlib/issues/8593

The above solutions don't seem to work any more. One has to edit the get_proj function inside site-packages\mpl_toolkits\mplot3d\axes3d.py in the following way now:

        try:
            self.localPbAspect = self.pbaspect
        except AttributeError:
            self.localPbAspect = [1,1,1]

        xmin, xmax = ( lim / self.localPbAspect[0] for lim in self.get_xlim3d() )
        ymin, ymax = ( lim / self.localPbAspect[1] for lim in self.get_ylim3d() )
        zmin, zmax = ( lim / self.localPbAspect[2] for lim in self.get_zlim3d() )