Controlling the output resolution
By default, when using the output to a bitmap picture, matplotlib chooses the size and the resolution of the output for us. Depending on what the bitmap picture will be used for, we might want to choose the resolution ourselves. For instance, if a picture is to be part of a large poster, we might prefer a high resolution, or, if we want to generate a thumbnail, then the resolution would be very low. In this recipe, we will learn how to control the output resolution.
How to do it...
The pyplot.savefig()
function provides an optional parameter to control the output resolution, as shown in the following script:
import numpy as np from matplotlib import pyplot as plt X = np.linspace(-10, 10, 1024) Y = np.sinc(X) plt.plot(X, Y) plt.savefig('sinc.png', dpi = 300)
The preceding script draws a curve and outputs the result to a file. Instead of the usual 800 x 600 pixels output, it will be 2400 x 1800 pixels.
How it works...
The pyplot.savefig()
function has an optional...