Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing X axis labels in seaborn boxplot

I have a pandas dataframe with multiple columns I am trying to plot the column "Score" (on x axis) with another column called "interest rate". I am using the following commands:

box_plot=sns.boxplot(x=list(Dataframe['Score']),y=list(Dataframe['Interest.Rate']),data=Dataframe)
box_plot.set(xlabel='FICO Score',ylabel='Interest Rate')

This works fine and it create a boxplot with appropriate axes. Seems like I have to pass the variables as list in boxplot function. Maybe there is better way to do it.

The problem is x axis labels are too crowded and are not readable so I don't want them all too print, only some of them for better readability.

I have tried multiple options with xticks and xticklabel functions but none of them seem to work.

like image 783
Tars Avatar asked May 09 '16 06:05

Tars


Video Answer


2 Answers

you could do simply this:

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

data = pd.read_csv('your_data.csv', index_col=0)

sns.boxplot(
    x='Score', 
    y='Interest.Rate', 
    data=data
).set(
    xlabel='FICO Score', 
    ylabel='Interest Rate'
)
plt.show()
like image 87
Serge Avatar answered Oct 06 '22 02:10

Serge


try it this way:

box_plot=sns.boxplot(x='Score', y='Interest.Rate',data=Dataframe)

instead of converting pandas series to lists

if you need help with the X axis please post sample data set which helps to reproduce your problem.

like image 22
MaxU - stop WAR against UA Avatar answered Oct 06 '22 03:10

MaxU - stop WAR against UA