你可以在我的情节中为三角形的尖端着色吗?

时间:2017-12-17 19:13:03

标签: python matplotlib plot colors symbols

我正在特定地点绘制英国的风速和风向。我想知道的是,是否有办法为三角形的前端着色以使风的方向更明显?

我的绘图代码是:

payload_user={'maddison.newman@example.com': {'lat': '51.45', 'lon': '-2.59'},'mandy.larson@example.com': {'lat': '52.06', 'lon': '-2.82'}}
m.plot(y=float(payload_user[email_user]['lat']),x=float(payload_user[email_user]['lon']),marker=(3,0,wind_direction_deg),color = col, markersize=7 )
                    plt.title("Wind speed and Direction in the UK for specific users")
                    plt.xlabel('Longitude')
                    plt.ylabel("Latitude")

英国地图的风速和方向:

Map of the UK with windspeed and direction

1 个答案:

答案 0 :(得分:0)

我不知道以何种方式使标记的部分颜色与标记的其他部分不同。然而,为了显示方向,我可以想象使用非等边但等腰三角形是有道理的。

enter image description here

实现这种三角形的一种方法是使用marker=verts表示法,其中verts是多边形的顶点,用作标记。

import numpy as np
import matplotlib.pyplot as plt

def get_arrow(angle):
    a = np.deg2rad(angle)
    ar = np.array([[-.25,-.5],[.25,-.5],[0,.5],[-.25,-.5]]).T
    rot = np.array([[np.cos(a),np.sin(a)],[-np.sin(a),np.cos(a)]])
    return np.dot(rot,ar).T

for i, angle in enumerate([0,45,60,-36]):
    plt.plot(i/10.,0.6,marker=get_arrow(angle), ms=30)

plt.show()

enter image description here