2013-01-14 13 views
20

तो वहाँ इस गाइड है: http://matplotlib.org/examples/pylab_examples/scatter_symbol.html enter image description herematplotlib कस्टम मार्कर/प्रतीक

# 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

तो पता चला कि यह था:

अद्यतन

क्या मैं इस विशेष मार्कर प्रकार के बारे में की तरह है कि यह सरल matplotlib वाक्य रचना के साथ समायोजित करने के लिए आसान है बस मैथटेक्स्ट प्रतीकों का उपयोग करना और 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

मैं 'दिल से भरा' ढूंढने की कोशिश कर रहा था क्योंकि \ heartuit सिर्फ एक रूपरेखा है। एक यूनिकोड मार्कर का उपयोग करने के लिए मेरे लिए काम किया: 'marker = ur '$ \ u2665 $'' – patricksurry

+0

'\ mathrm' या '\ rm' mathtext कमांड का उपयोग करके सामान्य अक्षर/शब्दों पर इटालिक्स को हटाने में रुचि रखने वालों के लिए। जैसे एक एम के लिए 'मार्कर = आर' $ \ mathrm {एम} $ '' – Andy