简体   繁体   中英

Presenting the index labels in the x axis of a Scatter Plot with Seaborn

I have created a Scatter Plot with Seaborn and I was thinking that if I could present the index labels of the Observations on the x axis --rotated by 90 degrees-- this would help the reader interpret the plot. However I do not know how to do this.

My data:

                      Response8  Nulls_prevalence
Employment_Info_1     0.001348              0.00
Employment_Info_4    -0.000049              0.11
Medical_History_1     0.078445              0.15
Employment_Info_6     0.003095              0.18
Family_Hist_4        -0.119424              0.32
Insurance_History_5  -0.003648              0.43
Family_Hist_2        -0.004765              0.48
Family_Hist_3        -0.003509              0.58
Family_Hist_5        -0.003889              0.70
Medical_History_15    0.263364              0.75
Medical_History_24    0.112906              0.94
Medical_History_32    0.485493              0.98
Medical_History_10    0.203842              0.99

My code:

import pandas as pd
import seaborn as sns

sns.regplot(x = 'Nulls_prevalence', y='Response8' , data = plot_data8, fit_reg=False)

plt.title('Response8:  Nulls_prevalence of Predictors vs. Correlation with Target')

plt.xlabel('Nulls Prevalence of Predictor')

plt.ylabel('Correlation of Predictor with Target')

plt.tight_layout()

plt.show()

The output:

在此处输入图片说明

I gave it a shot but I could not make all the index labels appear (only a subset appeared on the x axis).

I think that what you are asking is the functionality of the seaborn's rugplot function.

import pandas as pd
import seaborn as sns

ax = sns.regplot(x = 'Nulls_prevalence', y='Response8' , data = plot_data8, fit_reg=False)

sns.rugplot(plot_data8['Nulls_prevalence'], ax=ax) # Don't forget to pass the axis from regplot

plt.title('Response8:  Nulls_prevalence of Predictors vs. Correlation with Target')

plt.xlabel('Nulls Prevalence of Predictor')

plt.ylabel('Correlation of Predictor with Target')

plt.tight_layout()

plt.show()

I think you need, plt.xticks :

import pandas as pd
import seaborn as sns

plt.figure(figsize=(15,8)
sns.regplot(x = 'Nulls_prevalence', y='Response8' , data = plot_data8, fit_reg=False)

plt.title('Response8:  Nulls_prevalence of Predictors vs. Correlation with Target')

plt.xlabel('Nulls Prevalence of Predictor')

plt.ylabel('Correlation of Predictor with Target')

plt.tight_layout()

#plt.xticks line
plt.xticks(plot_data8['Nulls_prevalence'], rotation=90)

plt.show()

Output:

在此处输入图片说明

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM