Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pandas 使用多个y值与子地块和groupby进行打印_Pandas_Matplotlib_Pandas Groupby_Subplot - Fatal编程技术网

Pandas 使用多个y值与子地块和groupby进行打印

Pandas 使用多个y值与子地块和groupby进行打印,pandas,matplotlib,pandas-groupby,subplot,Pandas,Matplotlib,Pandas Groupby,Subplot,我有一个df。头部见下文: Country Date suspected case confirmed cases suspected deaths confirmed deaths 0 Guinea 2014-08-29 25.0 141.0 482.0 648.0 1 Nigeria 2014-08-29 3.0

我有一个
df
。头部见下文:

Country         Date     suspected case    confirmed cases   suspected deaths   confirmed deaths   

0   Guinea   2014-08-29       25.0            141.0              482.0              648.0
1   Nigeria  2014-08-29       3.0             1.0                15.0               19.0
2   Liberia  2014-08-29       382.0           674.0              322.0              1378.0
通过使用
df.groupby('Country')
我想使用
xaxis
Date
列,将
疑似病例
确诊病例
进行对比。将这些绘制为(5,2)子图

到目前为止,我所做的还没有完全做到:

fig, ax = plt.subplots(2, 5, sharey=True)
df.groupby('Country').plot(x='Date', y=['suspected cases', 'confirmed cases'], title=f'Suspected vs. Confirmed cases {country}')
plt.show()

到目前为止,出现了一个空的5x2子图,下面分别显示每个图形。为什么会这样

也只是一个小问题,但希望得到一些澄清。在我的
.plot()
函数中,为什么最后一个分组的国家/地区只显示在标题中?例如,本图将10个国家分组,但标题
疑似病例与确诊病例美国
显示了每个图表

查看了一些SO帖子,并结合了一些答案试图解决我的问题,但我似乎在兜圈子。

你可以:

fig, ax = plt.subplots(2, 5, sharey=True)
for (c,d), a in zip(df.groupby('Country'), ax.ravel()):
    d.plot(x='Date', 
           y=['suspected cases', 'confirmed cases'], 
           title=f'Suspected vs. Confirmed cases {c}', 
           ax=a, subplots=False)
输出:


那么你有10个国家,想把每个国家划分成单独的子地块吗?@QuangHoang-Yup!