【问题标题】:Polar histogram - no errors but makes no sense极坐标直方图 - 没有错误但没有意义
【发布时间】:2019-07-10 17:12:40
【问题描述】:

我没有得到任何错误,但直方图没有意义。条形图根本不居中。这里是:

]1

前段时间我在做类似的事情,但直方图几乎是正确的。从那以后情况变得更糟了。这里是:
]2

我尝试过使用 ''width''、''bottom'' 和 ''align'' 但没有解决任何问题。

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 处相遇并且看起来像条形,而不是这个。不管这是什么。

【问题讨论】:

    标签: python matplotlib histogram python-3.6 polar-coordinates


    【解决方案1】:

    图表不从 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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多