Wie kann ich eine einzige Legende über zwei Seeborn -Barplots ausrichten?Python

Python-Programme
Anonymous
 Wie kann ich eine einzige Legende über zwei Seeborn -Barplots ausrichten?

Post by Anonymous »

Ich möchte eine einzige Legende haben, die gut auf beide Nebenhandlungen passt (muss nicht unbedingt die gesamte Breite der Diagramme umfassen, sondern muss sich außerhalb der Handlung befinden). Ich weiß, dass Sie mit bbox_to_anchor () arbeiten können, aber irgendwie scheint dies nicht gut zu funktionieren. Es wird immer eine Nebenhandlung wegbewegt.

Code: Select all

fig, ax = plt.subplots(1, 2)
sns.barplot(x="day", y="total_bill", hue="sex", data=tips, ax = ax[0])
ax[0].legend_.remove()
sns.barplot(x="day", y="total_bill", hue="sex", data=tips, ax = ax[1])
sns.move_legend(ax[1], loc = "center", bbox_to_anchor=(-0.5, 1.1), ncol=2, title=None, frameon=False)
fig.tight_layout()

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post