Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fit Matplotlib 3D subplot to figsize

I have a minimum example of my code as follows:

import matplotlib.pyplot as plt


fig = plt.figure(1, figsize=(16, 9))
ax = fig.add_subplot(projection='3d',elev=-150, azim=110)
 
plt.tight_layout()
plt.show()

If run my .py script i get following plot with a lot of white spaces on the left and right. Is it possible to fit the subplot to the defined figsize? In a previous python version there were no whitespaces, but since i use python 3.9.4 together with matplotlib 3.5.2 the subplot has white spaces on the left and right. Hope someone can help me with this issue.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

using set_box_aspect(), you can set aspect ratio for Matplotlib 3d box, look from this link

so in your case, add this line after you define ax (before plt)

ax.set_box_aspect((20, 16, 9))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading