使用Python的自定义标记(matplotlib) [英] Custom markers using Python (matplotlib)
问题描述
我想知道如何生成此图中显示的黑色线条的标记. (来源:NCEP&NOAA) 它是标准天气地图中风暴或飓风的标记.
I would like to know how I can generate the marker for the black colored line shown in this picture. (Source: NCEP & NOAA) It's the marker for a storm or hurricane in standard weather maps.
我可能可以生成标记符号的图像文件.但是,我不知道如何告诉matplotlib将图像用作标记.
I can probably generate an image file of the marker symbol. But, I am not aware of how I can tell matplotlib to use the image as a marker.
推荐答案
标记看起来像6
.在这种情况下,可以使用6
作为标记,如下所示:
The marker looks like a 6
. If this is the case, you can use a 6
as a marker as follows:
import matplotlib.pyplot as plt
x = [1,2,3,4]
y = [2,3,1,4]
plt.scatter(x,y, s= 100,marker="$6$")
plt.show()
如果这不是一个选项,则可以使用路径定义自定义标记.为此,需要知道路径的坐标.我在下面发明了一些值,也许它们已经适合这里的需求.
If this is not an option, you may define your custom marker using a path. To this end, the coordinates of the path need to be known. I have invented some values below, maybe they already suit the needs here.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.path as mpath
def get_hurricane():
u = np.array([ [2.444,7.553],
[0.513,7.046],
[-1.243,5.433],
[-2.353,2.975],
[-2.578,0.092],
[-2.075,-1.795],
[-0.336,-2.870],
[2.609,-2.016] ])
u[:,0] -= 0.098
codes = [1] + [2]*(len(u)-2) + [2]
u = np.append(u, -u[::-1], axis=0)
codes += codes
return mpath.Path(3*u, codes, closed=False)
hurricane = get_hurricane()
plt.scatter([1,1,2],[1.4,2.3,2.8], s=350, marker=hurricane,
edgecolors="crimson", facecolors='none', linewidth=2)
plt.scatter([0,1,2],[1,3,1], s=150, marker=hurricane,
edgecolors="k", facecolors='none')
plt.scatter([0,1.8,3],[0,2,4], s=150, marker="o",
edgecolors="k", facecolors='none')
plt.show()
这篇关于使用Python的自定义标记(matplotlib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!