Skip to content Skip to sidebar Skip to footer

Set Font Properties To Tick Labels With Matplot Lib

I'm trying to change the font of tick labels with matplotlib from the standard font to Times New Roman. I think this should be as easy as changing the font for the title and axis

Solution 1:

You can also set it before running the command with a parameter list if your running a script. Such as below taken from a script of mine:

fig_size = [fig_width, fig_height] 
tick_size = 9
fontlabel_size = 10.5params = {
    'backend': 'wxAgg',
    'lines.markersize' : 2,
    'axes.labelsize': fontlabel_size,
    'text.fontsize': fontlabel_size,
    'legend.fontsize': fontlabel_size,
    'xtick.labelsize': tick_size,
    'ytick.labelsize': tick_size,
    'text.usetex': True,
    'figure.figsize': fig_size
}
plt.rcParams.update(params)

Or if you want to do it like you had it then run:

for label in ax.get_xticklabels() :
    label.set_fontproperties(ticks_font)

It is getting each label which has all the text properties that you can set for it.

Solution 2:

http://matplotlib.sourceforge.net/users/customizing.html

"Customizing matplotlib: matplotlib uses matplotlibrc configuration files to customize all kinds of properties, which we call rc settings or rc parameters. You can control the defaults of almost every property in matplotlib: figure size and dpi, line width, color and style, axes, axis and grid properties, text and font properties and so on." …

Post a Comment for "Set Font Properties To Tick Labels With Matplot Lib"