私は同じデータを含む2つのシリーズを持っていますが、それらはこのデータの出現の数が異なります。私はこれらの2つのシリーズを比較したいと思います。以下は私がこれまで行ってきたことです。私は、次のチャートを与え2つのシリーズを使用するパンダのサブプロット
import matplotlib.patches as 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()
:
私が持っている問題はすべての「ツリー名が」、「合計の木」の各シリーズで同じであっても、ということである
例えば#5(Callery pear)は 'tree_amount15'の#5であり、 'queens_tree_types'の#3などです。シリーズには、グラフに表示されている正しいラベルに対応する値を注文するにはどうすればよいですか?現在、シリーズのラベルが最初に追加されて表示されているため、2番目のシリーズの値は誤解を招きます。
ヒント
ここでは、value_counts()を実行するときの2つのシリーズの外観を示します。
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
「カリグラフィーの梨」に対応する青色のバーが間違っていて、「蜂蜜キャスト」の欄の青色のバーであるはずですか? – James
ラベルは青色のバーに正しく対応していますが、赤いバーは正しく表示されません。それはちょうど彼らがどんな順序であっても2つのシリーズをプロットしたように、最後にシリーズのラベルを追加したものです。これは、赤いバーがラベルに対応していないことを意味します。 – Khaine775
'tree_amount15'と' queens_tree_types'からあなたのデータの例を投稿できますか?これらのパンダシリーズやデータフレームオブジェクトはありますか? – James