用origin软件生成柱状图的时候怎么设置bins
时间: 2024-05-24 12:11:30 浏览: 14
在使用Origin软件生成柱状图时,可以按照以下步骤设置bins:
1. 导入数据并选择列,然后单击“Plot”选项卡上的“Column”按钮,选择“Bar”图类型。
2. 在弹出的“Bar”对话框中,选择“Bins”选项卡。
3. 在“Bins”选项卡中,您可以选择“Number of Bins”选项,然后输入您想要使用的条形的数量。
4. 您还可以选择其他选项,例如“Bin Width”选项,以设置柱形的宽度。
5. 单击“OK”按钮应用您的更改并生成柱状图。
注意:在设置bins时,要根据数据的范围和分布情况选择合适的数量和宽度,以便正确地显示数据。
相关问题
origin画柱状图如何调整bins
在使用`origin`绘制柱状图时,可以通过`bins`参数来调整柱状图的柱子数量。`bins`参数的默认值为10,即将数据分成10个区间,每个区间对应一个柱子。
例如,以下代码绘制了一个由随机数生成的柱状图,其中`bins=5`表示将数据分成5个区间,每个区间对应一个柱子:
```python
import numpy as np
import matplotlib.pyplot as plt
data = np.random.normal(size=1000)
plt.hist(data, bins=5)
plt.show()
```
在调整`bins`参数时,需要根据数据的范围和分布情况来确定合适的值。较少的`bins`会导致某些数据被合并在一起,难以观察数据分布的细节;而较多的`bins`会使得柱状图过于密集,难以观察整体趋势。因此,需要根据具体情况进行调整。
用matplotlib为程序写一个柱状图
要为程序添加柱状图,首先需要导入matplotlib库,并在程序中添加相关代码来绘制图表。以下是修改后的程序,添加了绘制豆瓣电影Top250评分分布的柱状图的代码:
```python
import random
import urllib.request
from bs4 import BeautifulSoup
import codecs
from time import sleep
import matplotlib.pyplot as plt
def main(url, headers):
# 发送HTTP请求
page = urllib.request.Request(url, headers=headers)
page = urllib.request.urlopen(page)
contents = page.read()
# 用BeautifulSoup解析网页
soup = BeautifulSoup(contents, "html.parser")
infofile.write("")
print('爬取豆瓣电影250: \n')
ratings = [] # 评分列表
for tag in soup.find_all(attrs={"class": "item"}):
# 评分和评论数
info = tag.find(attrs={"class": "star"}).get_text()
info = info.replace('\n', ' ')
info = info.lstrip()
print('[评分评论]', info)
# 提取评分
rating = float(info.split(" ")[0])
ratings.append(rating)
# 其他信息...
# 绘制柱状图
plt.hist(ratings, bins=10, range=(0, 10), edgecolor='black')
plt.xlabel('Rating')
plt.ylabel('Count')
plt.title('Distribution of Ratings in Top 250 Movies')
plt.show()
if __name__ == '__main__':
# 存储文件
infofile = codecs.open("03-movie-bs4.txt", 'a', 'utf-8')
# 消息头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'}
# 翻页
i = 0
while i < 10:
print('页码', (i + 1))
num = i * 25 # 每次显示25部 URL序号按25叠加
url = 'https://movie.douban.com/top250?start=' + str(num) + '&filter='
main(url, headers)
sleep(5 + random.random())
infofile.write("\r\n\r\n")
i = i + 1
infofile.close()
```
上述代码中,在每次遍历电影信息时,将评分提取出来并添加到一个列表中。然后,使用`plt.hist()`函数绘制柱状图,设置了分箱数为10,范围为0到10。最后,调用`plt.show()`显示柱状图。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)