Computer >> Computer tutorials >  >> Programming >> Python

Plotting at full resolution with matplotlib.pyplot, imshow() and savefig()


To plot at full resolution with matplotlib.pyplot, imshow() and savefig(), we can keep the dpi value from 600 to 1200.

Steps

  • Set the figure size and adjust the padding between and around the subplots.
  • Set random values in a given shape.
  • Display the data as an image, i.e., on a 2D regular raster
  • Save the figure with 1200 dpi.
  • To display the figure, use show() method.

Example

from matplotlib import pyplot as plt
import numpy as np

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

data = np.random.rand(5, 5)

plt.imshow(data, cmap="plasma")
plt.savefig("myimage.eps", dpi=1200)

plt.show()

Output

Plotting at full resolution with matplotlib.pyplot, imshow() and savefig()