在matplotlib中反转极坐标图上的径向刻度

2024-09-27 07:19:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我在DebianBuster上使用了Python2.7.14和matplotlib2.1.1。我想用一个反向的径向轴创建一个极坐标图。我在径向轴上的值大多为负值,我希望在较高的半径绘制较低的值,因为它们表示更好的结果,反之亦然。另外,我想将坐标原点设置为定义的值。然而,matplotlib似乎通过定义第二个参数经历第一个参数的限制而引起问题。对于这个问题here和{a2},存在一些解决方案(可能有点过时)。但是有没有一种更优雅的方法来反转轴呢?我的代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

import matplotlib.pyplot as plt
import numpy as np

angle = [-90.,-45.,-30.,-20.,-13.,-9.,-6.,-4.,-2.,-1.,0.,1.,2.,4.,6.,9.,13.,20.,30.,45.,90.]
tresh = [-16.1,-16.,-13.8,-12.4,-10.7,-9.4,-8.,-6.7,-6.,-6.5,-6.4,-6.7,-6.5,-7.4,-7.6,-10.1,-12.4,-14.3,-15.5,-16.9,-17.4]

arc = np.deg2rad(angle)

fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
ax.plot(arc,tresh)

ax.set_thetamin(-90)
ax.set_thetamax(90)
ax.set_theta_zero_location('N', offset=0)
ax.set_theta_direction(-1)

#ax.set_rorigin(-2)#This origin I want to set optionally.
ax.set_ylim(-18,-5)

#plt.show()
fig.savefig('test.png')

下图解释了我想做的事。 enter image description here

谢谢你的帮助。在


Tags: import参数定义matplotlibasnpfigplt

热门问题