python - Pandas subplot using two series -


i have 2 series' contains same data, contain different number of occurrences of data. want compare these 2 series' making bar chart, 2 compared. below i've done far.

import matplotlib.patches mpatches  fig = plt.figure()  ax = fig.add_subplot(111)  width = 0.3  tree_amount15.plot(kind='bar', color='red', ax=ax, width=width, position=1, label='nyc') queens_tree_types.plot(kind='bar', color='blue', ax=ax, width=width, position=0, label='queens') plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,        ncol=2, mode="expand", borderaxespad=0.)  ax.set_ylabel('total trees') ax.set_xlabel('tree names')  plt.show() 

which gives me following chart:

enter image description here

the problem have that, though 'tree names' same in each series, 'total trees' of course different, example, #5 (callery pear) #5 in 'tree_amount15', it's #3 in 'queens_tree_types' , on. how can order series such it's value corresponds right label shown on chart? because right now, it's labels series gets added first, shown, makes values of second series misleading.

any hints?

here's how 2 series look, when value_counts() them.

tree_amount15:

london planetree     87014 honeylocust          64264 callery pear         58931 pin oak              53185 norway maple         34189 littleleaf linden    29742 cherry               29279 japanese zelkova     29258 ginkgo               21024 sophora              19338 red maple            17246 green ash            16251 american linden      13530 silver maple         12277 sweetgum             10657 northern red oak      8400 silver linden         7995 american elm          7975 maple                 7080 purple-leaf plum      6879 

queens_tree_types:

london planetree     31111 pin oak              22610 honeylocust          20290 norway maple         19407 callery pear         16547 cherry               13497 littleleaf linden    11902 japanese zelkova      8987 green ash             7389 silver maple          6116 ginkgo                5971 sophora               5386 red maple             4935 american linden       4769 silver linden         4146 purple-leaf plum      3035 maple                 2992 northern red oak      2697 sweetgum              2489 american elm          1709 

you can create data frame 2 series uses tree name index. default pandas sort index alphabetically, tell sort using values of nyc. both series columns, can use single call plot method put them on same graph.

df = pd.concat([tree_amount15, queens_tree_types], axis=1).rename_axis(           {0:'nyc', 1:'queens'}, axis='columns') # sets column names  df.sort_values('nyc', ascending=false)           # sort df using nyc values  df.plot.bar(color=['red','blue'])   

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -