0

I have the following code:

from matplotlib import pyplot as plt

a = [-2,4,-6,8,9,-5,3,4,-6,7,8,9,4]
b = [3,6,8,6,5,3,-1]

plt.figure()
plt.hist(a)
plt.figure()
plt.hist(b)

which gives me two histograms. Histogram a has larger x and y scales than b. I would like extract these scales and reuse them for b. If I do it per hand it looks like this:

plt.xlim(-6,10)
plt.ylim(0,4)
plt.hist(b)
plt.show()

But I think there must be an automatic way to do it, something like:

ax_scale = plt.get_x_scale(a)
ay_scale = plt.get_y_scale(a)
plt.figure()
plt.set_x_scale(ax_scale)
plt.set_yscale(ay_scale)
plt.hist(b)

I couldn't find such comands, but maybe I was just searching for the wrong words...

user4050567
  • 87
  • 10
  • Do you want to set the _limits_ (the minimum and maximum values on the axis) or the _scale_ (linear or log) – tacaswell Feb 18 '15 at 16:38
  • Schorsch: indeed, it is a duplicate of matplotlib get ylim values. The answer solved my problem. tcaswell: I wanted to have the limits. Thank you! – user4050567 Feb 18 '15 at 17:49

0 Answers0