旋转 matplotlib 路径对象 [英] Rotate a matplotlib Path object

查看:40
本文介绍了旋转 matplotlib 路径对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 matplotlib

这是我想要影响的变化:

解决方案

您可以调用 transformed 方法在您的路径对象上使用 旋转变换.

 将matplotlib导入为mpl标记= getCustomMarker()marker = marker.transformed(mpl.transforms.Affine2D().rotate_deg(45))plt.scatter([0,0],[0,0],标记=标记,s = 5000)plt.show()

I'm using a matplotlib Path object to create a custom plotting marker as described here. I'd like to rotate the resulting path about its center by an arbitrary angle. Any suggestions on how to do this would be greatly appreciated.

Here's the code I'm using to create and plot the custom marker

import matplotlib.path
import matplotlib.pylab as plt

def getCustomMarker():

    verts = [( -5 , -15 ),
                ( -5 , -5 ),
                ( -15 , -5 ),
                ( -15 , 5 ),
                ( -5 , 5 ),
                ( -5 , 15 ),
                ( 5 , 15 ),
                ( 5 , 5 ),
                ( 15 , 5 ),
                ( 15 , -5 ),
                ( 5 , -5 ),
                ( 5 , -15 ),
                ( -5 , -15 )]

    verts = verts

    codes = [matplotlib.path.Path.MOVETO,
                matplotlib.path.Path.LINETO,
                matplotlib.path.Path.LINETO,
                matplotlib.path.Path.LINETO,
                matplotlib.path.Path.LINETO,
                matplotlib.path.Path.LINETO,
                matplotlib.path.Path.LINETO,
                matplotlib.path.Path.LINETO,
                matplotlib.path.Path.LINETO,
                matplotlib.path.Path.LINETO,
                matplotlib.path.Path.LINETO,
                matplotlib.path.Path.LINETO,
                matplotlib.path.Path.CLOSEPOLY]

    path = matplotlib.path.Path(verts, codes)

    return path

plt.scatter([0,0],[0,0], marker=getCustomMarker(), s=5000)
plt.show()

This is what I get:

This is the change I'd like to affect:

解决方案

You could call the transformed method on your path object with a rotational transform.

import matplotlib as mpl

marker = getCustomMarker()
marker = marker.transformed(mpl.transforms.Affine2D().rotate_deg(45))
plt.scatter([0,0],[0,0], marker=marker, s=5000)
plt.show()

这篇关于旋转 matplotlib 路径对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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