我有一个dataframe,里面有三列,一列是日期,两列是数值,我想把他们以直方图的形式画在同一张图上
时间: 2024-02-19 18:03:07 浏览: 153
好的,您可以使用Python中的Matplotlib库来绘制这个直方图。您可以按照以下步骤进行操作:
1. 导入所需的库:
```python
import pandas as pd
import matplotlib.pyplot as plt
```
2. 读取您的数据集:
```python
df = pd.read_csv('your_file.csv')
```
3. 创建一个新的Figure对象和Axes对象:
```python
fig, ax = plt.subplots(figsize=(10, 6))
```
4. 使用Axes对象绘制直方图:
```python
ax.hist(df['column1'], bins=20, alpha=0.5, label='column1')
ax.hist(df['column2'], bins=20, alpha=0.5, label='column2')
ax.hist(df['column3'], bins=20, alpha=0.5, label='column3')
```
5. 添加必要的标签和标题:
```python
ax.set_xlabel('Value')
ax.set_ylabel('Frequency')
ax.set_title('Histogram of Three Columns')
ax.legend()
```
6. 显示图形:
```python
plt.show()
```
这样,您就可以在同一张图上绘制三个列的直方图了。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)