首页 > 解决方案 > matplotlib 极坐标散点图:如何将单位更改为度数?

问题描述

在 matplotlib 极坐标散点图中,如何将theta轴的单位从角度更改为任意指定的单位?

https://matplotlib.org/gallery/pie_and_polar_charts/polar_scatter.html开始(所有示例都以度为单位),

import numpy as np
import matplotlib.pyplot as plt

# Fixing random state for reproducibility
np.random.seed(19680801)

# Compute areas and colors
N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2
colors = theta

fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)
plt.show()

theta 轴始终以度为单位。如果我想要一个给定的函数在几天之内degrees=days2degrees(days)怎么办?我应该利用

ax.set_thetalim()
ax.set_thetamin()
ax.set_thetamax()

ETC。?这些似乎需要以为单位的输入。

标签: pythonmatplotlib

解决方案


不确定这是否能回答您的问题:

只需添加类似

t = ax.get_xticks()
# your function
days = t/(2 * np.pi)  * 365
ax.set_xticklabels(days, fontsize=12)

推荐阅读