How to increase the size of xticks in pandas plot

Viewed 3696

This is a follow up for a question which i asked here: The code is as follows:

from pandas_datareader import data as web
import matplotlib.pyplot as plt
import matplotlib.dates as md

fig, (ax1, ax2) = plt.subplots(2, 1)
df = web.DataReader('F', 'yahoo')
df2 = web.DataReader('Fb', 'yahoo')
ax = df.plot(figsize=(35,15), ax=ax1)
df2.plot(y = 'Close', figsize=(35,15), ax=ax2)
plt.xticks(fontsize = 25)

for ax in (ax1, ax2):
    ax.xaxis.set_major_locator(md.MonthLocator(bymonth = range(1, 13, 6)))
    ax.xaxis.set_major_formatter(md.DateFormatter('%b\n%Y'))
    ax.xaxis.set_minor_locator(md.MonthLocator())
    plt.setp(ax.xaxis.get_majorticklabels(), rotation = 0 )

plt.show()

This produces this plot: enter image description here

How can i increase the size of both the xticks in the two subplots as you can see the size was increased for the bottom one only.

  [1]: https://stackoverflow.com/questions/62358966/adding-minor-ticks-to-pandas-plot
1 Answers

You can use the tick_params function on the ax instance to control the size of the tick-labels on the x-axis. If you want to control the size of both x and y axis, use axis='both'. You can additionally specify which='major' or which='minor' or which='both' depending on if you want to change major, minor or both tick labels.

for ax in (ax1, ax2):
    # Rest of the code
    ax.tick_params(axis='x', which='both', labelsize=25)
Related