March 2014
Beginner to intermediate
222 pages
4h 7m
English
When preparing figures for a journal publication or a website, one might need a figure that has one specific aspect ratio. In this recipe, we are going to see how to control the aspect ratio of a figure.
The pyplot API provides a simple way to set up a custom aspect ratio, as follows:
import numpy as np import matplotlib.pyplot as plt X = np.linspace(-6, 6, 1024) Y1, Y2 = np.sinc(X), np.cos(X) plt.figure(figsize=(10.24, 2.56)) plt.plot(X, Y1, c='k', lw = 3.) plt.plot(X, Y2, c='.75', lw = 3.) plt.show()
The aspect ratio of the following figure is much different from what we would get by default:

Read now
Unlock full access