[Matplotlib-users] set_aspect('equal') for log-log plots

David J Pine djpine at gmail.com
Tue May 8 09:18:04 EDT 2018

I would like to make a log-log plot where the x and y axes have the same scale.  That is, if a decade is one inch physically on the x axis, I want it to be one inch physically on the y axis.  How do I do this?  I tried set_aspect(‘equal’) but it doesn’t work for logarithmic axes.  This makes sense for semi-log plots but it doesn’t make sense for log-log plots, where it should work (logically).  Is there some other straightforward way to do it?  By the way, it would be nice if it worked when there are shared axes, as in the example below.

import matplotlib.pyplot as plt
import numpy as np

xline = np.array([10, 1500])
yline = np.array([0.1, 15.])

ymin, ymax = 0.0001, 10.
fig, ax = plt.subplots(figsize=(5, 8))

lines = np.array([2., 0.4, 0.08, 0.016, 0.0022])
for m in lines:
    ax.loglog(xline, m*yline, dashes=(5, 2))
ax.set_ylim(ymin, ymax)

scale = 1.0e6
axR = ax.twinx()
axR.set_ylim(ymin*scale, ymax*scale)
axR.loglog([], [])

ax.set_aspect('equal', share=True)  # doesn't do anything


More information about the Matplotlib-users mailing list