python的matplotlib中marker_使用Python的自定义标记(matplotlib)

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.

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.

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值