Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try this:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading