【发布时间】:2019-09-01 14:08:06
【问题描述】:
我是熊猫和所有这些数据框的新手。我很想知道如何将当前代码转换为 plt.figure 。我想将 2 列(旅游收据、访客)绘制为线,同时将另一列作为 x 轴(季度)。
似乎这段代码有效。但我想知道是否有更好的方法,例如 plt.plot 但允许我将 x 轴设置为 Quarters 并将其他 2 列设置为线?
df1= df.set_index('Quarters').plot(figsize=(10,5), grid=True)
数据框(来自我的 csv 文件):
| Quarters | Tourism Receipts | Visitors |
| 2019 Q1 | 10 | 1 |
| 2019 Q2 | 20 | 2 |
| 2019 Q3 | 30 | 3 |
| 2019 Q4 | 40 | 4 |
我理解下面这个方法
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,10))
plt.plot(x,y)
plt.title
plt.xlabel
plt.ylabel
我想询问是否有办法将'df.set_index'方法转换为plt?
【问题讨论】:
-
图表与我当前的代码如下所示:imgur.com/a/N9CXSV0(抱歉,我无法将其与我的问题一起上传)
标签: pandas matplotlib