Epimetheus
Epimetheus

Reputation: 393

How to change only xticks fontsize in pandas Dataframe barplot?

I want to create a barplot from pandas. But I want to change fontsize for x and y-axis separately.

This code:

max_coef.plot.bar(fontsize = 15, x = 'coef_word', y = 'coefficient', color=['yellow'])

Creates this plot:

enter image description here

I tried to play around with xticks and xticklabels, but apparently this does not work similar to matplotlib syntax. I already checked documentation but I cannot wrap my head around it.

I want to change x and y ticks separately. Please help. + Thanks in advance!

Upvotes: 2

Views: 912

Answers (2)

Mohil Patel
Mohil Patel

Reputation: 510

Alternatively, you can do something like this.

data.plot.bar(fontsize = 15, x = 'coef_word', y = 'coefficient', color=['yellow'])
plt.xticks(fontsize=7)  # for xticks
plt.yticks(fontsize=24) # for yticks

Sorry for weird values, just to show the change

enter image description here

Upvotes: 2

gtomer
gtomer

Reputation: 6564

See the code below for changing the font size:

import matplotlib.pyplot as plt

SMALL_SIZE = 8
MEDIUM_SIZE = 10
BIG_SIZE = 12

plt.rc('font', size=SMALL_SIZE)          # default text sizes
plt.rc('axes', titlesize=MEDIUM_SIZE )   # axes title fontsize
plt.rc('axes', labelsize=MEDIUM_SIZE)    # x and y labels fontsize
plt.rc('xtick', labelsize=MEDIUM_SIZE )  # x tick labels fontsize
plt.rc('ytick', labelsize=MEDIUM_SIZE )  # y tick labels fontsize
plt.rc('legend', fontsize=MEDIUM_SIZE )  # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE)  # figure title fontsize

You may find more info here: matplotlib rc

Upvotes: 2

Related Questions