python极坐标图定义角度范围_如何使matplotlib极坐标图中的角度在顶部为0°时顺时针旋转?...

我发现了——matplotlib允许您创建自定义投影。我创建了一个继承自PolarAxes。import numpy as N

import matplotlib.pyplot as P

from matplotlib.projections import PolarAxes, register_projection

from matplotlib.transforms import Affine2D, Bbox, IdentityTransform

class 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 = N.zeros(tr.shape, N.float_)

t = tr[:, 0:1]

r = tr[:, 1:2]

x = xy[:, 0:1]

y = xy[:, 1:2]

x[:] = r * N.sin(t)

y[:] = r * N.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 = N.sqrt(x*x + y*y)

theta = N.arctan2(y, x)

return N.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(N.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 = N.arange(0, 360, 10, dtype=float) * N.pi / 180.0

arbitrary_data = (N.abs(N.sin(angle)) + 0.1 *

(N.random.random_sample(size=angle.shape) - 0.5))

P.clf()

P.subplot(1, 1, 1, projection='northpolar')

P.plot(angle, arbitrary_data)

P.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值