optimus_prime
optimus_prime

Reputation: 827

Box plot using pandas

Trying to plot a box plot for a pandas dataframe but the x-axis column names don't appear to be clear.

import matplotlib.pyplot as plt
pd.set_option('display.mpl_style', 'default')
fig, ax1 = plt.subplots()
%matplotlib inline
df.boxplot(column = ['avg_dist','avg_rating_by_driver','avg_rating_of_driver','avg_surge','surge_pct','trips_in_first_30_days','weekday_pct'])

Below is the output

image

How to fix this so that the x-axis columns appear clear

Upvotes: 4

Views: 2745

Answers (2)

piRSquared
piRSquared

Reputation: 294218

Another option is to make the orientation of you boxes horizontal.

np.random.seed(100)
cols = ['avg_dist','avg_rating_by_driver','avg_rating_of_driver',
        'avg_surge','surge_pct','trips_in_first_30_days','weekday_pct']
df = pd.DataFrame(np.random.rand(10, 7), columns=cols)
df.boxplot(column=cols, vert=False)

enter image description here

Upvotes: 2

jezrael
jezrael

Reputation: 862511

I think you need parameter rot:

cols = ['avg_dist','avg_rating_by_driver','avg_rating_of_driver',
        'avg_surge','surge_pct','trips_in_first_30_days','weekday_pct']

df.boxplot(column=cols, rot=90)

Sample:

np.random.seed(100)
cols = ['avg_dist','avg_rating_by_driver','avg_rating_of_driver',
        'avg_surge','surge_pct','trips_in_first_30_days','weekday_pct']
df = pd.DataFrame(np.random.rand(10, 7), columns=cols)
df.boxplot(column=cols, rot=90)

graph

Upvotes: 2

Related Questions