我没有收到任何错误,但直方图没有意义。酒吧根本不居中。这是:
] 1
前段时间我也在做类似的事情,但直方图几乎是正确的。从那以后情况变得更糟。这是:
] 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 开始;所以他们被切断了。您可以通过设置 bar
的 bottom
参数让条形图从图形的中间开始。
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()
关于python - 极坐标直方图 - 没有错误,但没有意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56975596/