0

I want to have several different dataframes plotted on a graph. Which would look something like: enter image description here

And each different plots are from different dataframes. The dataframes look something like (they have many more columns):

a        b      c      d      e             f     g      h     i     j
0      27.0  1.74  12.63   50.0       Sejuani  18.0   5.28  1.17   6.48   
1      22.0  1.58  17.00   56.0       Kalista  12.0  10.92  2.58   3.94   
2      20.0  1.77  18.25   58.3     Gangplank  11.0   9.56  1.71   4.77   
3      17.0  1.72  16.87   60.5          Ryze  12.0  10.75  2.56   4.02   
7      27.0  1.61  11.08   54.2         Braum  11.0   2.68  0.25   6.32   
8      28.0  1.73  16.36   53.3          Azir  13.0  10.35  3.07   3.13   
9      29.0  1.83  16.56   55.4          Gnar  11.0   9.49  1.71   3.83   
16     35.0  1.23  17.72   52.1        Ezreal  11.0   10.5  2.23   4.10  

By default, the dataframes are in descending order according to a column that contains float values. I want to plot a column with the x-axis of the names. Current code I have is:

indices = [x for x in range(0, 30)]
x_tick = list(df_LCK['name'])
plt.xticks(indices, x_tick, rotation='vertical')
plt.plot(indices, df_LCK['pb'][:30])
plt.show()

And since top 30 items from each dataframes are all different, the xticks I declared above is only correct for one plot, and not matching for the other four.

Best would be reordering the dataframes so it's in alphabetical order, and in descending order according to a column. How would I have it so the x-ticks match the y-value for the rest of the plots? Is it to be done while plotting? Or is there a way to change the order of the dataframes' indices so they are in the way I want?

Joseph Seung Jae Dollar
  • 1,016
  • 4
  • 13
  • 28
  • If you are using matplotlib 2.1 or above you can directly plot `plt.plot(x_tick , df_LCK['pb'][:30])`. – ImportanceOfBeingErnest Mar 07 '18 at 14:37
  • @ImportanceOfBeingErnest I don't think that's relevant in my case, but thanks for the info! – Joseph Seung Jae Dollar Mar 07 '18 at 14:43
  • 1
    I wrote this because it is relevant. This would allow you to directly get the desired plot. – ImportanceOfBeingErnest Mar 07 '18 at 14:45
  • @ImportanceOfBeingErnest Oh! Thanks, will try right away! – Joseph Seung Jae Dollar Mar 07 '18 at 14:51
  • ...or I might be misunderstanding the desired plot. Is it one plot or several? If you need it be sorted by something other than the names, you probably even need matplotlib 2.2. – ImportanceOfBeingErnest Mar 07 '18 at 15:04
  • I don't understand the question, if the top 30 items are different for each dataframe, which items do you want plotted? Only the top 30 from the first dataframe and extract the corresponding items for the other dataframes? The top 30 for the combined dataframe? Please explain your problem more thoroughly. Please provide mockup data, in particular check out [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Diziet Asahi Mar 08 '18 at 08:26

0 Answers0