plt.plot 展示DataFrame的所有数据
时间: 2023-07-20 10:32:31 浏览: 47
要在 Matplotlib 中展示 DataFrame 数据的所有数据,可以使用 `plot()` 函数对 DataFrame 的每一列进行可视化。可以使用 `subplots=True` 参数将每一列的图表分别绘制在一个子图中。`plot()` 函数的参数与 `plt.plot()` 函数类似,包括:
- x:x 轴数据,可以是 DataFrame 中的某一列。
- y:y 轴数据,可以是 DataFrame 中的某一列。
- kind:表示图表的类型,例如折线图、柱状图等。
- title:表示图表的标题。
- xlabel:表示 x 轴的标签。
- ylabel:表示 y 轴的标签。
- figsize:表示图表的大小。
例如,下面的代码演示了如何用折线图展示 DataFrame 的所有数据:
```python
import pandas as pd
import matplotlib.pyplot as plt
# 创建 DataFrame 数据
data = {'x': [1, 2, 3, 4, 5], 'y': [1, 3, 2, 4, 5], 'z': [2, 4, 1, 3, 6]}
df = pd.DataFrame(data)
# 用折线图展示所有数据
df.plot(subplots=True, kind='line', title='My plot', xlabel='x', ylabel='values', figsize=(8, 6))
plt.show()
```
输出的图表如下所示:
![image.png](attachment:image.png)