fileRead = pd.read_excel("major.xlsx") # 分段计数统 plt.rcParams['font.family'] = 'SimHei' # java data1 = fileRead.loc[:, "Java程序设计基础"] plt.subplot(2, 2, 1) # 绘制直方图 plt.xlabel("score") plt.ylabel("count") plt.title("java成绩分布直方图", fontproperties='SimHei') plt.xlim(0, 100) plt.ylim(0,30) plt.hist(data1,bins=[0, 10, 20,30,40,50,60, 70, 80, 90, 100],density=0,histtype="stepfilled") plt.text(4.5, 7.8, "Java", fontsize=8)为什么我的直方图刻度不能是以10为间隔
时间: 2024-04-26 07:20:53 浏览: 26
您的直方图刻度不能以10为间隔,是因为您在定义bins时,将区间设置为了[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],而不是[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]。因此,您可以修改bins为[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],就可以实现以10为间隔的刻度了。
相关问题
fileRead = pd.read_excel("major.xlsx") # 分段计数统计 bins = [0,50,60, 70, 80, 90, 100] plt.rcParams['font.family'] = 'SimHei' # java data1 = fileRead.loc[:, "Java程序设计基础"] plt.subplot(2, 2, 1) # 绘制直方图 plt.xlabel("score") plt.ylabel("count") plt.title("java成绩分布直方图", fontproperties='SimHei') plt.xlim(0, 100) plt.ylim(0,30) plt.hist(data1,bins=[0, 10, 20,30,40,50,60, 70, 80, 90, 100],density=0,histtype="stepfilled") plt.text(4.5, 7.8, "Java", fontsize=8)为什么我的直方图刻度不能是以10为间隔
您的直方图刻度不能以10为间隔,是因为您在定义bins时,将区间设置为了[0,50,60,70,80,90,100],而不是[0,10,20,30,40,50,60,70,80,90,100]。因此,您可以修改bins为[0,10,20,30,40,50,60,70,80,90,100],就可以实现以10为间隔的刻度了。
import urllib3 import pandas as pd import os def download_content(url): http = urllib3.PoolManager() response = http.request("GET", url) response_data = response.data html_content = response_data.decode() return html_content def save_excel(): html_content = download_content("http://fx.cmbchina.com/Hq/") cmb_table_list = pd.read_html(html_content) cmb_table_list[1].to_excel("Bit&Yanan.xlsx") def main(): save_excel() if name == 'main': main() os.startfile("Bit&Yanan.xlsx") import pandas as pd import matplotlib.pyplot as plt import numpy as np plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号 rapx = (114.4936096 - 112.6832583)/50 rapy = (23.87839806 - 22.49308313)/50 minx = 112.6832583+rapx2 maxx = 114.4936096+rapx2 miny = 22.49308313 maxy = 23.87839806 data = pd.read_excel("Bit&Yanan.xlsx") print(data.head()),继续完成用matpllotlib绘制图
表的任务,可以先对数据进行处理,然后绘制想要的图形。以下是一个简单的例子:
```python
# 数据处理
filtered_data = data[(data['货币名称'] == '美元') & (data['中行折算价'] != '-')]
usd_data = filtered_data[['发布日期', '中行折算价']]
usd_data['发布日期'] = pd.to_datetime(usd_data['发布日期'], format='%Y-%m-%d')
usd_data['中行折算价'] = usd_data['中行折算价'].astype(float)
# 绘图
fig, ax = plt.subplots(figsize=(10, 6))
ax.plot(usd_data['发布日期'], usd_data['中行折算价'])
ax.set_xlabel('日期')
ax.set_ylabel('汇率')
ax.set_title('中国银行美元汇率走势')
plt.show()
```
这段代码将中国银行网站上的美元汇率数据下载下来,并使用 pandas 进行处理。最后使用 matplotlib 绘制出美元汇率走势图。你可以根据自己的需求修改代码,实现不同的图形效果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)