栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使matplotlib极坐标图中的角度顺时针旋转,顶部为0°?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使matplotlib极坐标图中的角度顺时针旋转,顶部为0°?

我发现了-matplotlib允许您创建自定义投影。我创建了一个继承自的代码

PolarAxes

import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.projections import PolarAxes, register_projectionfrom matplotlib.transforms import Affine2D, Bbox, IdentityTransformclass NorthPolarAxes(PolarAxes):    '''    A variant of PolarAxes where theta starts pointing north and goes    clockwise.    '''    name = 'northpolar'    class NorthPolarTransform(PolarAxes.PolarTransform):        def transform(self, tr): xy   = np.zeros(tr.shape, np.float_) t    = tr[:, 0:1] r    = tr[:, 1:2] x    = xy[:, 0:1] y    = xy[:, 1:2] x[:] = r * np.sin(t) y[:] = r * np.cos(t) return xy        transform_non_affine = transform        def inverted(self): return NorthPolarAxes.InvertedNorthPolarTransform()    class InvertedNorthPolarTransform(PolarAxes.InvertedPolarTransform):        def transform(self, xy): x = xy[:, 0:1] y = xy[:, 1:] r = np.sqrt(x*x + y*y) theta = np.arctan2(y, x) return np.concatenate((theta, r), 1)        def inverted(self): return NorthPolarAxes.NorthPolarTransform()        def _set_lim_and_transforms(self): PolarAxes._set_lim_and_transforms(self) self.transProjection = self.NorthPolarTransform() self.transData = (self.transScale + self.transProjection + (self.transProjectionAffine + self.transAxes)) self._xaxis_transform = (self.transProjection + self.PolarAffine(IdentityTransform(), Bbox.unit()) + self.transAxes) self._xaxis_text1_transform = (self._theta_label1_position + self._xaxis_transform) self._yaxis_transform = (Affine2D().scale(np.pi * 2.0, 1.0) + self.transData) self._yaxis_text1_transform = (self._r_label1_position + Affine2D().scale(1.0 / 360.0, 1.0) + self._yaxis_transform)register_projection(NorthPolarAxes)angle = np.arange(0, 360, 10, dtype=float) * np.pi / 180.0arbitrary_data = (np.abs(np.sin(angle)) + 0.1 *     (np.random.random_sample(size=angle.shape) - 0.5))plt.clf()plt.subplot(1, 1, 1, projection='northpolar')plt.plot(angle, arbitrary_data)plt.show()



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/596618.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号