2014-01-20 161 views
1

轴上的某些标签可能具有不同的颜色吗?matplotlib图表轴上的每个标签有不同的颜色?

import matplotlib.pyplot as plt 

fig = plt.figure() 
ax1 = fig.add_subplot(111) 
ax1.set_yticks([0,1,2]) 
ax1.set_yticklabels(['red','red', 'blue'], color='blue') 
#What I would like to do 
ax1.set_yticklabels(['red','red', 'blue'], colors=['red','red','blue']) <-- doesn't work 

plt.show() 

有没有办法实现我想要的?

incompletely colored axis labels

回答

4

您可以存取权限使用此方法一Tick对象的所有属性:

import matplotlib.pyplot as plt 

fig = plt.figure() 
ax1 = fig.add_subplot(111) 
ax1.set_yticks([0,1,2]) 
ax1.set_yticklabels(['red','red', 'blue'], color='blue') 
colors=['red','red','blue'] 
for color,tick in zip(colors,ax1.yaxis.get_major_ticks()): 
    tick.label1.set_color(color) #set the color property 

plt.show() 
相关问题