python - 如何在 python 中使用相同的轴在同一个图形上绘制多个信号
问题描述
我在同一图中手动表示了 22 个信号
plt.plot(components + [0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55])
plt.yticks([0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55], ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21'])
plt.xlim([0, 15000])
plt.show()
但是当我尝试自动执行时。我没有成功。
for i in range(0, 21):
plt.plot(components[:, i])
请问有没有人可以帮助我
解决方案
我建议你看看这里的例子https://matplotlib.org/faq/howto_faq.html?highlight=multiple%20plots#multiple-y-axis-scales
源代码是:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
t = np.arange(0.01, 10.0, 0.01)
s1 = np.exp(t)
ax1.plot(t, s1, 'b-')
ax1.set_xlabel('time (s)')
ax1.set_ylabel('exp')
ax2 = ax1.twinx()
s2 = np.sin(2*np.pi*t)
ax2.plot(t, s2, 'r.')
ax2.set_ylabel('sin')
plt.show()
您可以看到他们使用单独ax2
的,但最终结果是将其放在一个图表上。.twinx()
您可以通过或选择在绘图之间保持相同的 x 比例或相同的 y 比例.twiny()
。
推荐阅读
- netsuite - 无法使用 setCurrentSublistValue 更改子列表字段
- javascript - 如何将 vue-i18n 的 $t 函数注入 cy 对象(cypress 全局对象)
- reactjs - 如何获取下拉 React 的特定 ID?
- r - 多个人和多层次的变化点分析
- powershell - 在 PowerShell 中检查 Cosmos DB 帐户的状态
- react-native - React Native 图像裁剪选择器找不到合适的图像 URL 加载器 (null)
- paypal - 多个产品的 PayPal v2 入职错误
- python - Python中CSV文件的编码错误
- html - 我无法为浏览器加载@font-face
- flutter - 调用 api 时在 null 上调用了方法“[]”