[英]Can I assign an order of subplots for Pandas DataFrame.plot?
Pandas DataFrame.plot
is nice. 熊猫DataFrame.plot
很不错。 But I did not find a way to assign an order for my subplots so that I can plot columns in an order I want. 但是我没有找到一种方法来为子图分配顺序,以便可以按所需顺序绘制列。 For example, I want plot column 4, 2, 1, 3 from top to bottom. 例如,我要从上到下绘制第4、2、1、3列。 How can I do that? 我怎样才能做到这一点?
You can just reorder the columns in your dataframe if you want the order to be different, you can see that the columns are shifted around in the last example: 如果您希望顺序不同,则可以只对数据框中的列进行重新排序,您可以在上一个示例中看到列的移动:
In [89]:
df = pd.DataFrame({'a':randn(5), 'c':randn(5), 'b':randn(5)})
print(df)
df.plot()
a b c
0 -0.902707 0.652272 -1.033054
1 0.482112 0.300324 1.440294
2 -1.091794 0.007883 -0.068403
3 -1.444140 0.137132 0.315419
4 0.634232 1.259193 -0.011486
Out[89]:
In [90]:
df = df.ix[:,['c','b','a']]
print(df)
df.plot()
c b a
0 -1.033054 0.652272 -0.902707
1 1.440294 0.300324 0.482112
2 -0.068403 0.007883 -1.091794
3 0.315419 0.137132 -1.444140
4 -0.011486 1.259193 0.634232
Out[90]:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.