I would like to plot a series of curves in the same Axes each having a constant y
offset from eachother. Because the data I have needs to be displayed in log
scale, simply adding a y
offset to each curve (as done here) does not give the desired output.
I have tried using matplotlib.transforms
to achieve the same, i.e. artificially shifting the curve in Figure
coordinates. This achieves the desired result, but requires adjusting the Axes
y
limits so that the shifted curves are visible. Here is an example to illustrate this, though such data would not require log
scale to be visible:
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(1,1)
for i in range(1,19):
x, y = np.arange(200), np.random.rand(200)
dy = 0.5*i
shifted = mpl.transforms.offset_copy(ax.transData, y=dy, fig=fig, units='inches')
ax.set_xlim(0, 200)
ax.set_ylim(0.1, 1e20)
ax.set_yscale('log')
ax.plot(x, y, transform=shifted, c=mpl.cm.plasma(i/18), lw=2)
The problem is that to make all the shifted curves visible, I would need to adjust the ylim
to a very high number, which compresses all the curves so that the features visible because of the log
scale cannot be seen anymore.
Since the displayed y
axis values are meaningless to me, is there any way to artificially extend the Axes
limits to display all the curves, without having to make the Figure
very large? Apparently this can be done with seaborn, but if possible I would like to stick to matplotlib
.
EDIT:
This is the kind of data I need to plot (an X-ray diffraction pattern varying with temperature):