python - 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。?这些似乎需要以度为单位的输入。
解决方案
不确定这是否能回答您的问题:
只需添加类似
t = ax.get_xticks()
# your function
days = t/(2 * np.pi) * 365
ax.set_xticklabels(days, fontsize=12)
推荐阅读
- django - 如何使用 django google-auth 授权我的 API 请求?
- java - Docker + Springboot + postgres + JHipster = org.postgresql.util.PSQLException:连接尝试失败
- json - 如何在 JSON 中添加对象数组
- php - 将数据从 unity3d 游戏发送到 PHP 空变量
- c# - 如何检查用户是否获胜?
- swift - 如何在列表视图中更改项目的顺序?
- node.js - nodejs动态增加JSON对象属性而不会在第一次尝试时得到未定义
- xml - 这个 XML 文档做得好吗?
- groovy - Jenkins 管道:如何从 vars 目录中的 groovy 脚本访问自定义全局变量?
- c++ - 嵌入空字符的字符串