0

Pandas DataFrame.plot is nice. 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. How can I do that?

Wen Li
  • 117
  • 1
  • 3
  • You could just reoder your columns like: `cols = ['col4', 'col2', 'col1', 'col3'] df = df.ix[:,cols]` see: http://stackoverflow.com/questions/13148429/how-to-change-the-order-of-dataframe-columns – EdChum Oct 09 '14 at 08:25

1 Answers1

1

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]:

enter image description here

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]:

enter image description here

EdChum
  • 376,765
  • 198
  • 813
  • 562