python - 极坐标直方图 - 没有错误,但没有意义

标签 python matplotlib histogram python-3.6 polar-coordinates

我没有收到任何错误,但直方图没有意义。酒吧根本不居中。这是:

![https://i.imgur.com/CYAWqOM.png ] 1

前段时间我也在做类似的事情,但直方图几乎是正确的。从那以后情况变得更糟。这是:
![https://i.imgur.com/LEkRz27.png ] 2

我尝试过使用“宽度”、“底部”和“对齐”,但这并没有解决任何问题。

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

Theta = np.linspace(0.0, 2.0*np.pi, 12)
Dim = [2.31330, 2.32173, 2.32841, 2.32068, 2.31452, 2.30792, 2.31313, 2.31847, 2.31910, 2.31516, 2.30617, 2.30408]
width = (2*np.pi) / 13

ax1 = plt.subplot(111, polar=True)
bars = ax1.bar(Theta, Dim, color='b', width=width, bottom = 0.0, edgecolor = 'k', align = 'edge')
ax1.set_ylim(2.31000, 2.33000)
ax1.set_yticks(np.linspace(2.31000, 2.33000, 5))
ax1.set_rlabel_position(180)
ax1.set_theta_zero_location("N")
ax1.set_theta_direction(-1)

plt.show()

基本上,我只需要条形图在 0.0 处相遇并且看起来像条形图,而不是这个。不管这是什么。

最佳答案

图表不会从 0 开始,但条形图会从 0 开始;所以他们被切断了。您可以通过设置 barbottom 参数让条形图从图形的中间开始。

import matplotlib.pyplot as plt
import numpy as np

Theta = np.linspace(0.0, 2.0*np.pi, 12)
Dim = np.array([2.31330, 2.32173, 2.32841, 2.32068, 2.31452, 2.30792, 2.31313, 
                2.31847, 2.31910, 2.31516, 2.30617, 2.30408])
width = (2*np.pi) / 13
origin = 2.31

ax1 = plt.subplot(111, polar=True)

bars = ax1.bar(Theta, Dim-origin, color='b', width=width, bottom = origin, 
               edgecolor = 'k', align = 'edge')
ax1.set_ylim(origin, 2.33000)
ax1.set_yticks(np.linspace(2.31000, 2.33000, 5))
ax1.set_rlabel_position(180)
ax1.set_theta_zero_location("N")
ax1.set_theta_direction(-1)

plt.show()

enter image description here

关于python - 极坐标直方图 - 没有错误,但没有意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56975596/

相关文章:

python - 循环脚本以生成多个图像

r - 如何在ggplot2中调整 `binwidth`?

python - 使用 Blender 中嵌入的 Python 解码 URL

python - 每年 Pandas 高效分组季节

python - 从 Python 2 返回的区别——版本检查和 Python 3

Python 颜色条 : how to stop its repeating in for loop

python - 使用每月数据控制 matplotlib 中的条形宽度

python - 是否必须引用 MySQL 查询中的每个值?

python - 根据 for 循环中的位置将直方图存储在一个大数组中

r - 在ggplot中绘制具有负侧和正侧的累积直方图?