如何添加第二个(圆形)直方图从csv文件中读取?

我是 python 新手,拼凑了一些从 .csv 文件的第一个索引(包含弧度值)读取的代码,并绘制了直方图和圆形直方图。我想添加从第二个索引读取的第二个(圆形)直方图。谁能告诉我如何做到这一点?


完整代码:


import numpy as np

import matplotlib.pyplot as plt

import csv


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

        reader=csv.reader(f)

        angles=[] # Initialise empty list

        next(reader) # Skip header line

        for row in reader:

                angle = float(row[0]) 

                angles.append(angle)


bins_number = 18  # 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.show()


# Create circular 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=10.0, align='edge', color='red')

for bar in bars:

    bar.set_alpha(0.5)

plt.show()

rostral.csv 值示例:


1.214109733,2.678066227

1.214109733,2.378408071

1.214109733,2.378408071

1.290159115,2.314906

1.193219453,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

-1.7325846,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.208196994,2.314906

1.248951138,2.314906

0.945157766,2.314906

-1.343997479,2.314906

-1.561624822,2.314906

-1.903895159,2.314906


HUX布斯
浏览 249回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python