如何旋转 matplotlib 填充样式标记? [英] How to rotate matplotlib fill-style-markers?

查看:65
本文介绍了如何旋转 matplotlib 填充样式标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

黑色是 matplotlib 标记 能够旋转.蓝色/橙色是 fill-style-markers,我还没有设法旋转以同样的方式.

In black are matplotlib markers that are able to rotate . In blue/orange are fill-style-markers, and I have not managed to rotate them in the same way.

这是生成图形的代码.在此版本中,未使用 t .

Here is the code that has generated the graphics. In this version t is not used.

import matplotlib as mpl
import matplotlib.pyplot as plt

x = [0,10,20,30,40,50,60,70,80,90]
for i in x:
    t = mpl.markers.MarkerStyle(marker='o')
    t._transform = t.get_transform().rotate_deg(-i)
    marker_style = dict(color='b',  markerfacecoloralt='orange', markeredgecolor='w', markersize=25,
                        marker='o' )    
    plt.plot(i, i, marker=(2, 0, -i), c='k',markersize=30, linestyle='None')
    plt.plot(i, i, marker=(3, 0, -i), c='k',markersize=10, linestyle='None')
    plt.plot(i, i+20,fillstyle='top', **marker_style)
plt.margins(0.15); plt.grid();plt.show()

我尝试没有成功:

marker_style = dict(....., marker=(3, 3, -i) ) 
or
marker_style = dict(....., marker=t ) 
or
plt.plot(i, i+20,fillstyle='top', marker=(3, 3, -i) 

如果您知道并告诉我如何将它们放在一起,谢谢!使用 plt.scatter() 的解决方案也可以.

Thanks if you know and tell how to put the things together ! A solution with plt.scatter() would be fine too.

推荐答案

我不知道是否可以使用标记或MarkerStyle来完成,文档仅指定如何填充除半的符号.您可以通过将 2 个半圆放在一起并相应地旋转它们来模仿这种行为.

I don't know if it can be done using markers or MarkerStyle, the documentation only specifies how to fill the symbol divided by half. You can mimic that behavior by putting together 2 half circles and rotating them accordingly.

import matplotlib.pyplot as plt
import matplotlib as mpl

plt.figure(1)

x = [0,10,20,30,40,50,60,70,80,90]

ax=plt.gca()
rot=0

for i in x:

    HalfA=mpl.patches.Wedge((i, i+20), 5,theta1=0-rot,theta2=180-rot, color='r')
    HalfB=mpl.patches.Wedge((i, i+20), 5,theta1=180-rot,theta2=360-rot, color='b')

    rot=rot+360/len(x)

    ax.add_artist(HalfA)
    ax.add_artist(HalfB)

    ax.plot(i, i, marker=(2, 0, -i), c='k',markersize=30, linestyle='None')
    ax.plot(i, i, marker=(3, 0, -i), c='k',markersize=10, linestyle='None')


ax.set_xlim((-10, 110))
ax.set_ylim((-10, 130))

这篇关于如何旋转 matplotlib 填充样式标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆