Set the aspect ratio in Matplotlib plot

You can set the aspect ratio of 1:1 in Matplotlib.pyplot.

import numpy
from matplotlib import pyplot

x = numpy.arange(-2, 5, 0.1)
y = x * x - 1

ax = pyplot.gca()
ax.set_aspect(1)

pyplot.plot(x, y)

pyplot.savefig('aspect.jpg')

Without aspect settings

import numpy
from matplotlib import pyplot

x = numpy.arange(-2, 5, 0.1)
y = x * x - 1

pyplot.plot(x, y)

pyplot.savefig('plot.jpg')

Comments

Powered by Markdown