2017-04-01 301 views
0

我想在python中更改y轴刻度。我使用的代码在python中更改y轴的刻度

import pylab as plt 
y1 = [0,1,2,...10] 
y2 = [90,40,65,12,....] 
labels = [0.30,0.29,0.28,....] 
plt.plot(y1) 
plt.plot(y2,'r') 
plt.yticks(y1, labels) 
plt.yticks(y2, labels) 
plt.show() 

但是,所有y轴的标签出现在彼此

+0

你试图把两个地块上的数字相同?像''标签'对Y1'和'标签'对'Y2'? –

+0

是的。两张图在同一张图上 –

+0

我的回答有用吗? –

回答

1

从这个example大量举债的顶部一个地方,下面的代码演示了一种可能的方式有一个两个地块数字。

import pylab as plt 

fig, ax1 = plt.subplots() 
y1 = [0,1,2,3,4,5,6,7,8,9,10] 

labels = [0.30,0.29,0.28,0.27,0.26,0.25,0.24,0.23,0.22,0.21,0.20] 
ax1.plot(labels, y1, 'b-') 

ax1.set_xlabel('labels') 
# Make the y-axis label, ticks and tick labels match the line color. 
ax1.set_ylabel('y1', color='b', rotation="horizontal") 
ax1.tick_params('y', colors='b') 

ax2 = ax1.twinx() 
y2 = [90,40,65,12,23,43,54,13,42,53,63] 
ax2.plot(labels, y2, 'r-') 
ax2.set_ylabel('y2', color='r', rotation="horizontal") 
ax2.tick_params('y', colors='r') 

fig.tight_layout() 
plt.show()