带有极轴的条形图

问题描述 投票:4回答:2

我想让我的情节类似于此-

enter image description here

目前,我能得到的是:

enter image description here

我无法执行以下操作:

  1. 在内圈中获取时间标签
  2. 将刻度线放入圆圈内。这个问题-How to create minor ticks for polar plot matplotlib,有一个我尝试过的想法,但它与情节的其他部分搞混了。
  3. 时间标签仅在步长为3时才能正常工作。对于其他步骤,它与小节不对齐。

下面是产生该图的可复制代码

arr = np.random.randint(0, 24, size = 50000)
df = pd.DataFrame({"COL": arr}).COL.value_counts().sort_index()

N = 24
bottom = 1000
theta, width = np.linspace(0.0, 2 * np.pi, N, endpoint=False, retstep=True)

plt.figure(figsize = (10, 6))
ax = plt.subplot(111, polar=True)

bars = ax.bar(
    theta, df,
    width=width-0.03,
    bottom=bottom,
    color="#f39c12", edgecolor="black"
)
bars = ax.bar(
    theta, [3000]*24,
    width=width-0.03,
    bottom=bottom,
    color="#f39c12", alpha=0.2
)

ax.set_theta_zero_location("N")
ax.set_theta_direction(-1)
ax.grid(False)
ax.spines['polar'].set_visible(False)
ax.set_rticks([])

ticks = [f"{i}:00" for i in range(0, 24, 3)]
ax.set_xticklabels(ticks)

_ = ax
python python-3.x matplotlib polar-coordinates
2个回答
1
投票

我只画了两行和一个圆圈来制作“时钟图标”


0
投票

此外,如果您想在圆圈内添加数字,请执行以下操作:

© www.soinside.com 2019 - 2024. All rights reserved.