2013-01-14 4 views
20

그래서이 가이드가 : http://matplotlib.org/examples/pylab_examples/scatter_symbol.html enter image description here하기 matplotlib 사용자 정의 마커/기호

# http://matplotlib.org/examples/pylab_examples/scatter_symbol.html 
from matplotlib import pyplot as plt 
import numpy as np 
import matplotlib 

x = np.arange(0.0, 50.0, 2.0) 
y = x ** 1.3 + np.random.rand(*x.shape) * 30.0 
s = np.random.rand(*x.shape) * 800 + 500 

plt.scatter(x, y, s, c="g", alpha=0.5, marker=r'$\clubsuit$', 
      label="Luck") 
plt.xlabel("Leprechauns") 
plt.ylabel("Gold") 
plt.legend(loc=2) 
plt.show() 

그러나 당신은 나를 좋아하고 ... clubsuit 마커를 사용하지 않으려면

방법 자신의 표식을 _________ (으)로 만드시겠습니까?

from matplotlib import pyplot as plt 
import numpy as np 
import matplotlib 

x = np.arange(0.0, 50.0, 2.0) 
y = x ** 1.3 + np.random.rand(*x.shape) * 30.0 
s = np.random.rand(*x.shape) * 800 + 500 

plt.plot(x, y, "ro", alpha=0.5, marker=r'$\clubsuit$', markersize=22) 
plt.xlabel("Leprechauns") 
plt.ylabel("Gold") 
plt.show() 

enter image description here

+2

당신은 [이]를 살펴 있었다 (http://stackoverflow.com/q/2318288/1025391)? – moooeeeep

+0

예, 실제로 있습니다. 그러나 그것은 나를 위해 잘되지 않았다. Matplotlib 예제 코드에 대해 내가 좋아하는 것은 'c = "g"'로, 음영에 대한 색상 조정으로 해석합니다 (테스트 할 시점에 파이썬 셸이 없음). – Norfeldt

답변

37

그래서 것을 발견 :

UPDATE는

내가이 특별한 마커 유형에 대해 좋아하는 것은 간단하기 matplotlib 구문을 조정하기 쉬운 것입니다 그냥 mathtext 기호를 사용하고 matplotlib 모듈에 저장된 특수 벡터 기반 마커를 참조하지 마십시오.

from matplotlib import pyplot as plt 
import numpy as np 
from numpy.random import randint 
import matplotlib 

x = np.arange(0.0, 100.0, 2.0) 
y = x ** 1.3 + np.random.rand(*x.shape) * 30.0 
s = np.random.rand(*x.shape) * 800 + 500 

markers = ['\\alpha', '\\beta', '\gamma', '\sigma','\infty', \ 
      '\spadesuit', '\heartsuit', '\diamondsuit', '\clubsuit', \ 
      '\\bigodot', '\\bigotimes', '\\bigoplus', '\imath', '\\bowtie', \ 
      '\\bigtriangleup', '\\bigtriangledown', '\oslash' \ 
      '\ast', '\\times', '\circ', '\\bullet', '\star', '+', \ 
      '\Theta', '\Xi', '\Phi', \ 
      '\$', '\#', '\%', '\S'] 

def getRandomMarker(): 
    return "$"+markers[randint(0,len(markers),1)]+"$" 

def getMarker(i): 
    # Use modulus in order not to have the index exceeding the lenght of the list (markers) 
    return "$"+markers[i % len(markers)]+"$" 

for i, mi in enumerate(markers): 
    plt.plot(x[i], y[i], "b", alpha=0.5, marker=getRandomMarker(), markersize=randint(16,26,1)) 
    plt.plot(x[i], y[i]+50, "m", alpha=0.5, marker=getMarker(i), markersize=randint(16,26,1)) 
    # Let's see if their "center" is located where we expect them to be... 
    plt.plot(x[i], y[i]+100, "y", alpha=0.5, marker=getMarker(i), markersize=24) 
    plt.plot(x[i], y[i]+100, "k+", markersize=12, markeredgewidth=2) 

plt.xlabel("x-axis") 
plt.ylabel("y-axis") 
plt.xlim(-5, plt.xlim()[1]+5) 
plt.ylim(0, plt.ylim()[1]*1.1) 
plt.gcf().set_size_inches(12,6) 
plt.show() 

Check Image

+7

\ heartsuit는 단순한 윤곽선이므로 '채워진 마음'을 찾으려고했습니다. 유니 코드 마커를 사용하면 다음과 같이 작동합니다 :'marker = ur '$ \ u2665 $'' – patricksurry

+0

일반 문자/단어에서 이탤릭체를 제거하고자하는 사람들은'\ mathrm' 또는'\ rm' mathtext 명령을 사용합니다. 예 : M.에 대해 'marker = r'$ \ mathrm {M} $ '' – Andy