I'm trying to get something like this:
with this code
x = np.arange(l, r, s)
y = np.arange(b, t, s)
X, Y = np.meshgrid(x, y)
Z = f(X,Y)
plt.axis('equal')
plt.pcolormesh(X, Y, Z)
plt.savefig("image.png",dpi=300)
But I get this:
How could I remove the white regions? I really appreciate any kind of help.
CodePudding user response:
i would use the pyplot subplots to define the figures size and therefor aspect like this
import numpy as np
from matplotlib import pyplot as plt
def f(x,y):
return x y
x = np.arange(1, 10, .1)
y = np.arange(1, 10, .1)
X, Y = np.meshgrid(x, y)
Z = f(X,Y)
f, ax = plt.subplots(figsize=(4, 4))
plt.pcolormesh(X, Y, Z)
plt.show()
output
CodePudding user response:
Anwered here You can remove the margins at the edges of the plot.
plt.margins(x=0)