旋转现有的matplotlib标记?

时间:2018-04-04 20:48:16

标签: python matplotlib

我知道这个答案,Is it possible to control matplotlib marker orientation?和标记文档,但是可以采用现有的matplotlib标记符号(非正规多边形)并旋转它吗?

具体来说,我想将细菱形符号(“d”)旋转90度,使其长轴为水平。

3 个答案:

答案 0 :(得分:1)

标记"d"是钻石的偏斜版本"D"。您可以创建这样的钻石标记并将其向另一个方向倾斜。

对于任意角度,您可以改为旋转标记。

import matplotlib.pyplot as plt
from matplotlib.markers import MarkerStyle

fig, ax = plt.subplots()

plt.scatter([1,2,3],[1,2,3], s=225, marker="d")

m = MarkerStyle("D")
m._transform.scale(1.0, 0.6)

plt.scatter([1,2,3],[2,3,4], s=225, marker=m, color="crimson")

m = MarkerStyle("d")
m._transform.rotate_deg(60)

plt.scatter([1,2,3],[3,4,5], s=225, marker=m, color="limegreen")

plt.margins(0.5)
plt.show()

enter image description here

答案 1 :(得分:0)

如果为钻石制作一个markerstyle类,然后通过旋转自己修改其转换属性,可以这样做,无论出于何种原因,matplotlib都没有为某些标记公开这些类属性。我在下面列举了一个例子。

import matplotlib as mpl
import matplotlib.pyplot as plt

# make a markerstyle class and modify the transform property by 90 degrees
t = mpl.markers.MarkerStyle(marker='d')
t._transform = t.get_transform().rotate_deg(90)
plt.scatter((0,1), (0,1), marker=t, s=100)

enter image description here

答案 2 :(得分:-1)

旋转角度以360度为单位:

x = [0,10,20,30,40,50,60,70,80,90]
for i in x:

    plt.plot(i, i, marker=(2, 0, -i), c='k',markersize=30, linestyle='None')
plt.margins(0.15); plt.grid();plt.show()

enter image description here