首页 > 解决方案 > 有没有办法将两个 yAxis 对齐

问题描述

问题是 y_h = 1 未与 y = 0.3 正确对齐,依此类推,我该如何解决?下面我留下了我面临的问题和代码的图片。

yaxis 未对齐

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()

标签: matplotlibtkinterplot

解决方案


推荐阅读