How to share x axes of two subplots after they have been created

The usual way to share axes is to create the shared properties at creation. Either fig=plt.figure() ax1 = plt.subplot(211) ax2 = plt.subplot(212, sharex = ax1) or fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True) Sharing the axes after they have been created should therefore not be necessary. However if for any reason, you need to share axes … Read more

How to remove relative shift in matplotlib axis

plot([1000, 1001, 1002], [1, 2, 3]) gca().get_xaxis().get_major_formatter().set_useOffset(False) draw() This grabs the current axes, gets the x-axis axis object and then the major formatter object and sets useOffset to false (doc). In newer versions (1.4+) of matplotlib the default behavior can be changed via the axes.formatter.useoffset rcparam.

Secondary axis with twinx(): how to add to legend?

You can easily add a second legend by adding the line: ax2.legend(loc=0) You’ll get this: But if you want all labels on one legend then you should do something like this: import numpy as np import matplotlib.pyplot as plt from matplotlib import rc rc(‘mathtext’, default=”regular”) time = np.arange(10) temp = np.random.random(10)*30 Swdown = np.random.random(10)*100-10 Rn … Read more