Home > OS >  Set the font of x ticks and y ticks of plots in subplots
Set the font of x ticks and y ticks of plots in subplots

Time:06-11

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"]

CodePudding user response:

Try this:

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