Подтвердить что ты не робот

Пользовательский маркер/символ Matplotlib

Итак, есть это руководство: http://matplotlib.org/examples/pylab_examples/scatter_symbol.html enter image description here

# 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()

Но что, если вы похожи на меня и не хотите использовать маркер для общения...

Как вы создаете свой собственный маркер _________?

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

4b9b3361

Ответ 1

Итак, выяснилось, что он просто использовал символы математического текста и не ссылался на какой-либо специальный векторный маркер, хранящийся в модуле 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 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

Ответ 2

Я запускаю 41-й скрипт в блокноте jupyter, который показывает:

TypeError                                
 Traceback (most recent call last)
<ipython-input-4-a8519e2b712a> in <module>
     24 
     25 for i, mi in enumerate(markers):
---> 26     plt.plot(x[i], y[i], "b", alpha=0.5, marker=getRandomMarker(), markersize=randint(16,26,1))
     27     plt.plot(x[i], y[i]+50, "m", alpha=0.5, marker=getMarker(i), markersize=randint(16,26,1))
     28     # Let see if their "center" is located where we expect them to be...

<ipython-input-4-a8519e2b712a> in getRandomMarker()
     17 
     18 def getRandomMarker():
---> 19     return "$"+markers[randint(0,len(markers),1)]+"$"
     20 
     21 def getMarker(i):

TypeError: в скалярный индекс могут быть преобразованы только целочисленные скалярные массивы

Тем не менее, эти сценарии работают очень хорошо в sublime-text3, можете ли вы сказать мне, почему в Notebook есть такие ошибки?