Skip to content Skip to sidebar Skip to footer

Matplotlib Savefig Image Size With Bbox_inches='tight'

I have to make a vector plot and I want to just see the vectors without the axes, titles etc so here is how I try to do it: pyplot.figure(None, figsize=(10, 16), dpi=100) pyplot.qu

Solution 1:

import matplotlib.pyplot as plt
import numpy as np

sin, cos = np.sin, np.cos

fig = plt.figure(frameon = False)
fig.set_size_inches(5, 8)
ax = plt.Axes(fig, [0., 0., 1., 1.], )
ax.set_axis_off()
fig.add_axes(ax)

x = np.linspace(-4, 4, 20)
y = np.linspace(-4, 4, 20)
X, Y = np.meshgrid(x, y)
deg = np.arctan(Y**3-3*Y-X)
plt.quiver(X, Y, cos(deg), sin(deg), pivot='tail', units='dots', color='red')
plt.savefig('/tmp/test.png', dpi=200)

yields

enter image description here

You can make the resultant image 1000x1600 pixels by setting the figure to be 5x8 inches

fig.set_size_inches(5, 8)

and saving with DPI=200:

plt.savefig('/tmp/test.png', dpi=200)

The code to remove the border was taken from here.

(The image posted above is not to scale since 1000x1600 is rather large).

Post a Comment for "Matplotlib Savefig Image Size With Bbox_inches='tight'"