Set the font of x ticks and y ticks of plots in subplots

Issue

I want to plot a subplot with three figures. I have two questions: 1- I can not set the font for x tick and y tick. With the following code, I can only set the font for the last plot.
2- I want to stick only two values on the y ticks. 0 and int(maximum of frequency) + 1.

Could you help me with that?

    import pandas as pd 
    import numpy as np
    import matplotlib.pyplot as plt
    xaxes = ['RMSE', 'SMAPE', 'MAPE']
    f,a = plt.subplots(3,figsize=(20,15))
    f.subplots_adjust(hspace=0.4)

    a = a.ravel()
    for idx,ax in enumerate(a):
        plt.xticks(fontsize=30)
        plt.yticks(fontsize=30)
        ax.hist(np.random.rand(100,1), bins=300)
        ax.set_xlabel(xaxes[idx], fontsize = 30)
        ax.set_ylabel("Frequency", fontsize = 30)
        plt.rcParams["font.serif"] = ["Times New Roman"]

Solution

Try this:

hfont = {'fontname':'Helvetica'}
plt.xticks(np.arange(min(x), max(x)+1, 1.0),fontsize=30, **hfont)

Answered By – Stephan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published