matplotlib - 有没有办法将两个 yAxis 对齐
问题描述
问题是 y_h = 1 未与 y = 0.3 正确对齐,依此类推,我该如何解决?下面我留下了我面临的问题和代码的图片。
x = 2
y = np.array([0.3, 0.11, 0.43])
y_h = np.array([1, 2, 3])
fig, host = plt.subplots(figsize=(8, 5))
fig.subplots_adjust(right=0.75)
colormap = plt.get_cmap("gist_rainbow")
colors = [colormap(i) for i in np.linspace(0, 1, y.size)]
line = host.twinx()
#plot the lines the give them colors and labels
for i in range(y.size):
p = line.plot([x - x, x], [y_h[i], y[i]], color=colors[i], label="p"+str(i))
#append the line labels to a list
'''for i in range(y.size):
pis.append('p'+str(i))'''
host.set_xlim(0, x)
host.set_ylim(0, y_h.size)
line.set_ylim(0, max(y))
host.set_xlabel("Rev_Count")
host.set_ylabel("Value")
line.set_ylabel('Value_Header')
plt.show()
解决方案
推荐阅读
- php - 检查域是否有记录 CNAME 并指向我的服务器
- c# - .NET 5、ASP .NET Core 5 应用程序 ajax 发布请求 cookie 为空
- postgresql - Talend Erreur : talend 下的数据导入问题(postgres 到 postgres)
- javascript - 在 HTML 输入中显示 JavaScript 变量的值
- google-sheets - 如何在 Xpath 中使用 NOT 用于 IMPORTXML 函数?
- dictionary - 在 Python 中从响应行中删除字符
- excel - 如何使用表单中的可下载链接在 Excel 中添加完整图像
- socket.io - 属性“服务器”是私有的,只能在“套接字”类中访问
- flutter - Flutter: Call a function when message received from websocket
- compiler-construction - 是否应该将所有可能的 Ascii 字符添加到有限自动机的转换表中