Size of matplotlib surface is too small

Viewed 114

I'm trying to save an image of a surface, but the size is too small. I wrote a simple code explaining the issue

import numpy as np

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.figure
from matplotlib import cm

#Meshgrid + Gaussian

x = np.arange(0,10,.1)
y = np.arange(0,10,.1)
X,Y = np.meshgrid(x,y)
u = np.exp(-(X-5)**2/2-(Y-5)**2/2)/(2*np.pi)

#Surface + size setting

fig = plt.figure(figsize=(25.6,19.2))
ax = fig.add_subplot(111,projection='3d')
surf = ax.plot_surface(X,Y,u,linewidth=0,cmap=cm.inferno)

#Removing axes and saving

plt.axis('off')
plt.grid('off')
plt.savefig('A.png',format='png',dpi='figure')

I tried several methods and what worked best is figsize, that's why I'm using it in the sample code; anyway what happens is that it reaches a maximum zoom on a certain width/height ratio and cannot go over it no matter how much I change the values. The best I could get is the output of the code, in the following image

But it's not enough, I want it bigger such as in this edit

enter image description here

I tried several methods, basing on official documentantion and the answers to similar questions I found here. Here a list of commands I tried and didn't work properly, or at all

#plt.gca().set_aspect('auto')

#plt.imshow(surf,aspect='auto')

#plt.rcParams["figure.figsize"] = (15,10)

#ax = fig.add_subplot(111,projection='3d',aspect='auto')

#w, h = matplotlib.figure.figaspect(.5)
#fig = plt.figure(figsize=(w,h))

Thanks for any help.

0 Answers
Related