I have two parameters from panda’s dataframe, bmi
and heart_disease
. I want to show them with relplot
, it shows information that other plots lose. I used this simple code:
JavaScript
x
3
1
facetObj = sns.relplot(x="heart_disease", y="bmi", data=data);
2
facetObj;
3
The heart_disease
parameter only has two values: 1
or 0
. However, the plot gave me a whole range of numbers from 0 to 1. How do I make it only 0 and 1 ?
Advertisement
Answer
This is because your heart_disease
column is integer. To change, you can do one of the following:
- Change the heart_disease column to string before plotting (before sns.relplot)
JavaScript
1
2
1
data['heart_disease'] = data['heart_disease'].astype(str)
2
- After plotting, you can use set
x_ticks
and setx_ticklables
to show just 0 and 1. Note you need to set the plot as below (g=sns.replot(…))
JavaScript
1
3
1
g = sns.relplot(x="heart_disease", y="bmi", data=data)
2
g.ax.set_xticks([0,1])
3
The plot