Scaling both the axes equally

By default, matplotlib will use a different scale for both the axes of a figure. In this recipe, we are going to see how to use the same scale for the two axes of a figure.

How to do it...

To accomplish this, we will need to play with the pyplot API and the Axes object, as shown in the following code:

import numpy as np
import matplotlib.pyplot as plt
T = np.linspace(0, 2 * np.pi, 1024)

plt.plot(2. * np.cos(T), np.sin(T), c = 'k', lw = 3.)
plt.axes().set_aspect('equal')

plt.show()

The preceding script draws an ellipse with its real aspect ratio, as follows:

How to do it...

How it works...

In this example, we display an ellipse where the ...

Get matplotlib Plotting Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.