Here's an example:
titanic = sns.load_dataset("titanic")
g = titanic.groupby('embark_town').count()['survived']
g.plot(kind='bar')
I'm trying for a while to make it count x town, how can I do it?
You can supply kind='barh'
instead of kind='bar'
in the g.plot
:
import matplotlib.pyplot as plt
import seaborn as sns
titanic = sns.load_dataset("titanic")
g = titanic.groupby('embark_town').count()['survived']
g.plot(kind='barh')
plt.tight_layout()
plt.show()
Or you can use g.plot.barh()
import matplotlib.pyplot as plt
import seaborn as sns
titanic = sns.load_dataset("titanic")
g = titanic.groupby('embark_town').count()['survived']
g.plot.barh()
plt.tight_layout()
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.