柱状图如何修改坐标python_Matplotlib极坐标柱状图已移位

我正在使用Matplotlib创建一个极性柱状图。直方图的正确数据(弧度)如下:

线形为[0,0.78)弧度(即0至45度)[0.78,…)(45至90度)等

但是,使用极坐标图绘制时,箱子现在以0为中心,而不是从0开始。但是直方图计数是一样的。在

如果真的是(-22.5度,22.5度),那么直方图分布就会不同。因此,极坐标图轴标签似乎不正确-也就是说,0度标签实际上应该是22.5度(或者0度标签应该顺时针移动22.5度)。在

有没有人知道如何做到这一点?在

相关代码:

直方图bins = np.linspace(-np.pi, np.pi, bins_number + 1)

n, _, _ = plt.hist(angles, bins) # Create histogram

plt.show()

注意,angles是以弧度表示的角度列表

极性

^{pr2}$

完整代码import numpy as np

import matplotlib.pyplot as plt

import csv

with open('circ2.csv', 'r') as f:

reader=csv.reader(f)

angles=[] # Initialise empty list

next(reader) # Skip header line

for row in reader:

angle = float(row[1]) # Angle is in the second column of the row

angles.append(angle)

bins_number = 8 # the [-180, 180) interval will be subdivided into this

bins = np.linspace(-np.pi, np.pi, bins_number + 1)

n, _, _ = plt.hist(angles, bins) # Create histogram

plt.clf()

width = 2 * np.pi / bins_number

ax = plt.subplot(1, 1, 1, projection='polar')

bars = ax.bar(bins[:bins_number], n, width=width, bottom=0.0)

for bar in bars:

bar.set_alpha(0.5)

plt.show()

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值