Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 527
optimus_prime Avatar asked Oct 28 '25 05:10

optimus_prime


1 Answers

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

like image 120
jezrael Avatar answered Oct 29 '25 20:10

jezrael