2013-01-14 14 views
20

ので、このガイドがあります: http://matplotlib.org/examples/pylab_examples/scatter_symbol.html ​​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マーカーを使用しない場合は...どのように

自分のマーカーを_________にしますか?

私はこの特別なマーカータイプについては好きで何UPDATE

は、それが簡単なmatplotlibの構文で調整することが容易だということです。

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"'です(テストする際には、書き込み時にPythonシェルを使用しないでください)。 – Norfeldt

答えて

37

だから、それがあったことが判明単に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

\心配は単なる概要であるので、私は「満たされた心」を見つけようとしていました。 'marker = ur '$ \ u2665 $'' – patricksurry

+0

普通の文字や単語のイタリック体を取り除くのに興味がある人は、 '\ mathrm'や' \ rm'を使ってmathtextコマンドを実行します。例えば。 Mのための 'marker = r '$ \ mathrm {M} $'' – Andy