0

I am trying to create a factor plot but I am not able to change the kind of it from point to bar. How do we do that?

The codes used are

 import numpy as np
 import matplotlib.pyplot as plt
 import seaborn as sns
 %matplotlib inline
 sns.catplot('Sex',kind="bar",data=titanic_df)
Siong Thye Goh
  • 3,518
  • 10
  • 23
  • 31
chinmay
  • 3
  • 1
  • 3

1 Answers1

1

The seaborn documentation has the exact example you are looking for. Following the documentation, if you run the below lines, it should generate the bar plot shown.

bar plot generated from the code

import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

titanic = sns.load_dataset("titanic")
exercise = sns.load_dataset("exercise")
g = sns.catplot("alive", col="deck", 
                col_wrap=3, data=titanic[titanic.deck.notnull()], 
                kind="count", height=2.5, aspect=.8)

The important argument to note here is kind="count".

CAPSLOCK
  • 6,243
  • 3
  • 33
  • 56
Kani
  • 469
  • 4
  • 13
  • Thankyou for help!! – chinmay Apr 10 '19 at 15:26
  • Is there anyway to `unhide` the index `yes - no` in when a plot is below ? – Benoit Drogou Aug 28 '19 at 15:00
  • Seems like it may not be possible directly with Seaborn. But you can do that through editing each individual axis. After you call the plot function, `for ax in g.axes:`, you can try `plt.setp(ax.get_xticklabels(), visible=True)` – Kani Aug 28 '19 at 20:58