如何将两条不同范围的曲线合并为一个图? [英] How to combine two curves with different range into one plot?

查看:56
本文介绍了如何将两条不同范围的曲线合并为一个图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的两个子图放在一个图中而不改变它们的形状.它们的y范围非常不同.

I want to put my two subplots into one plot without changing their shape. They have a very different y range.

我想要得到的是下图所示的东西

What I want to get is something like the following figure

但我不知道如何得到那个数字.我试过使用双轴,但效果不佳.

But I don't know how to get that figure. I've tried using twin axes but it does not give me a very good result.

以下是一些要使用的玩具数据:

Here is some toy data to use:

t = np.linspace(0, 10, 100)
line1 = np.sin(t)
line2 = 10*np.sin(t)

推荐答案

这应该很接近了:

from matplotlib import pyplot as plt
import numpy as np
t = np.linspace(0, 10, 100)
line1 = np.sin(t)
line2 = 10 * np.sin(t)

fig, axs = plt.subplots(2, 1, sharex=True)
fig.subplots_adjust(hspace=0)
axs[0].spines['bottom'].set_visible(False)
axs[1].spines['top'].set_visible(False)
axs[0].plot(t, line1)
axs[1].plot(t, line2)
plt.show()

这篇关于如何将两条不同范围的曲线合并为一个图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆