简体   繁体   English

Matplotlib:绘制偏移曲线,每个曲线都有相应的y轴

[英]Matplotlib: plot offset curves, each with corresponding y-axis

I'm a newbye getting his hands on Matplotlib for the first time. 我是第一次接触Matplotlib的新手。 I'd like to plot some (four) different set of data in the same plot and I need to offset them because otherwise they would overlap. 我想在同一个图中绘制一些(四个)不同的数据集,我需要抵消它们,否则它们会重叠。

This is what I need to obtain: http://s4.postimg.org/skaclr06l/example.jpg 这是我需要获得的: http//s4.postimg.org/skaclr06l/example.jpg

Now, it would be simple to add a constant to the different data sets to offset them, but I need every plot to have a corresponding ordinate axis starting from 0 as you can see from the example I posted. 现在,将一个常量添加到不同的数据集以抵消它们会很简单,但我需要每个绘图都有一个从0开始的相应纵坐标轴,如我发布的示例所示。 I found a solution which gets quite close to it on matplotlib website: 我在matplotlib网站上找到了一个非常接近它的解决方案:

# Three subplots sharing both x/y axes
f, (ax1, ax2, ax3) = plt.subplots(3, sharex=True, sharey=True)
ax1.plot(x, y)
ax1.set_title('Sharing both axes')
ax2.scatter(x, y)
ax3.scatter(x, 2 * y ** 2 - 1, color='r')
# Fine-tune figure; make subplots close to each other and hide x ticks for
# all but bottom plot.
f.subplots_adjust(hspace=0)
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)

The problem is that in this way I get separate plots, whereas I'd like them to overlap partly, as is usually done, for example, with absorption spectra (see an example here http://nte-serveur.univ-lyon1.fr/spectroscopie/raman/Image42.gif ) 问题在于,通过这种方式,我获得了单独的图,而我希望它们部分重叠,例如,通常使用吸收光谱(参见此处的示例http://nte-serveur.univ-lyon1)。 fr / spectroscopie / raman / Image42.gif

Could you help me? 你可以帮帮我吗?

habe you tries to plot each curve separately and in the end use one plt.show()? 你试图分别绘制每条曲线,最后使用一个plt.show()吗?

This will plot the curves on the same figure, but you'd have to provide an offset for the y values. 这将在同一图上绘制曲线,但您必须为y值提供偏移。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM