【发布时间】:2018-06-17 12:15:16
【问题描述】:
我有一个在这里采样的多索引数据框:
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
df = pd.read_csv('https://docs.google.com/uc?id=1mjmatO1PVGe8dMXBc4Ukzn5DkkKsbcWY&export=download', index_col=[0,1])
df
我试图绘制这个图,以便每一列 ['Var1', 'Var2', 'Var3', 'Var4'] 在一个单独的图中,Country 是一条曲线,y-axis,Year 是 x-axis
请求的图形会像这个 Ms-Excel 图形
我尝试使用
绘制它f, a = plt.subplots(nrows=2, ncols=2, figsize=(9, 12), dpi= 80)
df.xs('Var1').plot(ax=a[0])
df.xs('Var2').plot(ax=a[1])
df.xs('Var3').plot(x=a[2])
df.xs('Var4').plot(kax=a[3])
但它给了KeyError: 'Var1'
我也尝试了以下
f, a = plt.subplots(nrows=2, ncols=2,
figsize=(7, 10), dpi= 80)
for indicator in indicators_list:
for c, country in enumerate(in_countries):
ax = df[indicator].plot()
ax.title.set_text(country + " " + indicator)
我的试验出了什么问题,我可以做些什么来得到我需要的东西?
【问题讨论】:
标签: python pandas matplotlib seaborn multi-index