Changing the default font in matplotlib to "Times New Roman".

  • Python
  • Thread starter amjad-sh
  • Start date
  • #1
222
7

Main Question or Discussion Point

I want to submit an article to an aps journal, so the labels of the figures have the "Times New Roman" font.
I had used the package matplotlib to get the figures and I want to make "Times New Roman" the default font. So, what code I need to write for this to be achieved?
Note that I used the package subplots to get the figures, by implementing this code:
from matplotlib.pyplot import subplots, show

I also tried the code below to check if the font is available:

import matplotlib.font_manager
flist = matplotlib.font_manager.get_fontconfig_fonts()
names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist]
print (names)
if "Times New Roman" in names:
print ("Yes")
else:
print ("font not available")

and the output was "font not available". Does this mean I need to add it to matplotlib? and if yes, how?
 

Answers and Replies

  • #2
anorlunda
Staff Emeritus
Insights Author
8,604
5,495
and the output was "font not available". Does this mean I need to add it to matplotlib? and if yes, how?
Might it be called just "Times" in the package?
 
  • Like
Likes amjad-sh and jedishrfu
  • #4
222
7
Might it be called just "Times" in the package?
I think the last code I wrote is meaningless, because I tried @jedishrfu's link and could change the default font into Times New Roman. But a problem still remaing. The part of the label which is written in mathmode always appears bold:
r"\mathcal{L}^s$"
I want the boldness of the text written in mathmode and the rest of the text be the same ( I want the font to be light). What is needed to be done for this to be achieved?
 
  • #5
140
92
I want the boldness of the text written in mathmode and the rest of the text be the same
Matplotlib does have a fontweight (or just weight) property that can be applied to most text.
 
  • #6
222
7
Matplotlib does have a fontweight (or just weight) property that can be applied to most text.
I used this code to make the weight of the labels appears light:
matplotlib.rcParams['axes.labelweight']=100,
but the the mathematical symbols written in the mathmode still look bold.
 
  • #7
11,827
5,450
Isn't this bold issue a nit? It may be that a different font is required for the math symbols to be properly displayed.

You could generate a plot and send it to the publishing journal editor to see if it is acceptable or if they have any guidelines on how best to make a plot. Their rules might only apply to the article and not the plot images. They may also have some recommended font packages to use as well.

Do you have other more pressing things to work on to complete your project? or is this the last thing? I'm asking because sometimes we focus on a minor issue to the detriment of other things we need to solve. I've done this too and missed deadlines which teach you to stay focused on the end goal.
 
  • Like
Likes amjad-sh

Related Threads on Changing the default font in matplotlib to "Times New Roman".

Replies
1
Views
818
Replies
3
Views
762
Replies
4
Views
12K
Replies
0
Views
2K
  • Last Post
Replies
6
Views
2K
Replies
4
Views
752
Replies
3
Views
47K
  • Last Post
Replies
1
Views
510
Replies
1
Views
2K
Top