2016-12-15 1 views
0

matplotlib로 만든 마커에서 여러 색상을 사용하고 싶습니다. 두 가지 색상을 사용하는 것이 어려웠습니다 (this example). this documentation의 몇 가지 추가 정보가 있습니다. 그러나 2 가지 색상 이상의 마커를 만들 수 있는지 궁금합니다. 나는 하나의 마커가 실제로 3 가지 다른 색을 얻길 원하는 상황에 처해있다. (맵상의 한 점은 세 가지 다른 관찰을 가리킨다.)matplotlib 마커에서 여러 색상 채우기

+0

http://matplotlib.org/examples/api/scatter_piecharts.html – tom

+0

@ 톰도 정상 플롯 (plt.plot (..))와 함께 작동하는 것이 무엇입니까? –

+0

@tom 또는 다른 마커 –

답변

1

당신은 여기에 표시된하기 matplotlib 예에 따라이 작업을 수행 할 수 있습니다

matplotlib.org/examples/api/scatter_piecharts.html

나는 약간 ax.plot 대신 ax.scatter 사용하는 예제를 변경 한 아래.

는 기본적으로이 모든 마커, 대신 scatters kwarg를 사용하여 크기가 동일해야 함을 의미합니다, 당신은 plotms (또는 markersize) kwarg 사용합니다.

또한 facecolor 대신 markerfacecolor을 정의해야합니다.

그 밖의 모든 변경 사항은 원래 예제와 동일하게 유지됩니다.

""" 
This example makes custom 'pie charts' as the markers for a scatter plot 

Thanks to Manuel Metz for the example 
""" 
import math 
import numpy as np 
import matplotlib.pyplot as plt 

# first define the ratios 
r1 = 0.2  # 20% 
r2 = r1 + 0.4 # 40% 

# define some sizes of the plot marker 
markersize = 20 # I changed this line 

# calculate the points of the first pie marker 
# 
# these are just the origin (0,0) + 
# some points on a circle cos,sin 
x = [0] + np.cos(np.linspace(0, 2*math.pi*r1, 10)).tolist() 
y = [0] + np.sin(np.linspace(0, 2*math.pi*r1, 10)).tolist() 

xy1 = list(zip(x, y)) 
s1 = max(max(x), max(y)) 

# ... 
x = [0] + np.cos(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist() 
y = [0] + np.sin(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist() 
xy2 = list(zip(x, y)) 
s2 = max(max(x), max(y)) 

x = [0] + np.cos(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist() 
y = [0] + np.sin(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist() 
xy3 = list(zip(x, y)) 
s3 = max(max(x), max(y)) 

fig, ax = plt.subplots() 

# Here's where I made changes 
ax.plot(np.arange(3), np.arange(3), marker=(xy1, 0), 
      ms=markersize, markerfacecolor='blue') # I changed this line 
ax.plot(np.arange(3), np.arange(3), marker=(xy2, 0), 
      ms=markersize, markerfacecolor='green') # I changed this line 
ax.plot(np.arange(3), np.arange(3), marker=(xy3, 0), 
      ms=markersize, markerfacecolor='red') # I changed this line 


plt.margins(0.05) 

plt.show() 

enter image description here