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

  • Context: Python 
  • Thread starter Thread starter amjad-sh
  • Start date Start date
  • Tags Tags
    Font Matplotlib
Click For Summary

Discussion Overview

The discussion revolves around changing the default font in matplotlib to "Times New Roman" for figures intended for submission to an APS journal. Participants explore methods to set the font, check its availability, and address issues related to font weight in mathematical text.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant seeks to set "Times New Roman" as the default font in matplotlib for figure labels and questions how to do this after finding the font unavailable.
  • Another participant suggests that "Times" might be the name used in the package instead of "Times New Roman."
  • A participant shares a link to a resource that may provide guidance on changing fonts in matplotlib.
  • Concerns are raised about the boldness of text in math mode, with one participant noting that they want the font weight of mathematical symbols to match the rest of the text.
  • It is mentioned that matplotlib has a fontweight property that can be applied to text, but issues with math mode symbols appearing bold persist.
  • One participant questions whether the boldness issue is significant and suggests checking with the journal editor about their guidelines for figure submissions.
  • There is a suggestion to focus on more pressing project tasks rather than getting caught up in minor issues like font weight.

Areas of Agreement / Disagreement

Participants express differing views on the significance of the boldness issue in math mode and whether it can be resolved with existing matplotlib settings. No consensus is reached on the best approach to address the font weight problem.

Contextual Notes

Participants mention potential limitations in font availability and the need for specific font packages for proper display of mathematical symbols. The discussion does not resolve the technical challenges presented.

amjad-sh
Messages
240
Reaction score
13
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?
 
Technology news on Phys.org
amjad-sh said:
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   Reactions: amjad-sh and jedishrfu
anorlunda said:
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?
 
amjad-sh said:
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.
 
websterling said:
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.
 
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   Reactions: amjad-sh

Similar threads

  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 15 ·
Replies
15
Views
8K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
7K
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K