2016-09-09 4 views
0

나는 x 축의 모든 눈금이 다른 색상을 갖는 matplotlib (python 3.5)로 scatter-plot을 만들려고합니다. 이것이 어떻게 가능한지?Matplotlib : 다른 색상의 모든 진드기

예를 들어 x-ticks가 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'라고합시다.

from matplotlib import pyplot as plt 
plt.figure(figsize=(16, 11)) 
x = [1, 2, 3, 4, 5, 6, 7] 
y = [10, 12, 9, 10, 8, 11, 10] 
plt.scatter(x, y) 
plt.xticks(x, ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']) 
plt.show() 

이미

my_colors = ['c', 'b', 'r', 'r', 'g', 'k', 'b'] 
plt.xticks(x, ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'], color=my_colors) 
을 시도 : 은 지금은 여기에

내 코드의 매우 간단한 버전입니다 ... '화'요법, 블루로, '모'는 녹색되고 싶어요

하지만 작동하지 않습니다.

답변

2

.set_color()을 사용하여 틱 레이블 (plt.gca().get_xticklabels() 사용)을 반복하고 만든 후에 색상을 설정할 수 있습니다. 예를 들어 :

from matplotlib import pyplot as plt 
plt.figure(figsize=(16, 11)) 
x = [1, 2, 3, 4, 5, 6, 7] 
y = [10, 12, 9, 10, 8, 11, 10] 
plt.scatter(x, y) 
plt.xticks(x, ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']) 

my_colors = ['c', 'b', 'r', 'r', 'g', 'k', 'b'] 

for ticklabel, tickcolor in zip(plt.gca().get_xticklabels(), my_colors): 
    ticklabel.set_color(tickcolor) 

plt.show() 

enter image description here

+0

감사합니다! 완벽하게 작동합니다. –