[英]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.我用 Seaborn 创建了一个散点图,我在想,如果我可以在 x 轴(旋转 90 度)上显示观测值的索引标签,这将有助于读者解释该图。 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).我试了一下,但我不能让所有的索引标签都出现(只有一个子集出现在 x 轴上)。
I think that what you are asking is the functionality of the seaborn's rugplot function.我认为您要问的是 seaborn 的 rugplot 功能的功能。
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
:我认为你需要, 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:输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.