Skip to content

Commit c8a7664

Browse files
authored
Merge pull request #15663 from rmcdermo/master
Python: use Nimbus Roman serif font for Linux systems
2 parents 04a3740 + 99e221b commit c8a7664

File tree

1 file changed

+71
-18
lines changed

1 file changed

+71
-18
lines changed

Utilities/Python/fdsplotlib.py

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,57 @@ def get_data(E, spec, start_idx):
708708
return y, col_names
709709

710710

711+
def configure_fds_fonts():
712+
import matplotlib.pyplot as plt
713+
import platform
714+
715+
system = platform.system()
716+
717+
if system == "Linux":
718+
# Linux: use Nimbus Roman as primary serif, with Times ahead of Times New Roman in the fallback chain
719+
primary_serif = "Nimbus Roman"
720+
serif_list = [
721+
"Nimbus Roman", # primary on Linux
722+
"Times",
723+
"Times New Roman",
724+
"serif",
725+
]
726+
else:
727+
# macOS ("Darwin") and Windows: prefer Times, then Times New Roman
728+
primary_serif = "Times"
729+
serif_list = [
730+
"Times", # first choice
731+
"Times New Roman",
732+
"Nimbus Roman",
733+
"serif",
734+
]
735+
736+
plt.rcParams.update({
737+
# Core-14 fonts for small PDFs (Times-Roman in output)
738+
"pdf.use14corefonts": True,
739+
"text.usetex": False,
740+
741+
# Make serif the default everywhere
742+
"font.family": "serif",
743+
"font.serif": serif_list,
744+
745+
# If something explicitly requests 'sans-serif', try to keep it Times-like too
746+
"font.sans-serif": serif_list,
747+
748+
# Math text: follow the same primary serif
749+
"mathtext.fontset": "custom",
750+
"mathtext.rm": primary_serif,
751+
"mathtext.it": f"{primary_serif}:italic",
752+
"mathtext.bf": f"{primary_serif}:bold",
753+
"mathtext.cal": f"{primary_serif}:italic",
754+
"mathtext.tt": "Courier",
755+
"mathtext.default": "rm",
756+
757+
"axes.unicode_minus": False,
758+
"pdf.compression": 9,
759+
})
760+
761+
711762
def plot_to_fig(x_data,y_data,**kwargs):
712763
"""
713764
Create a simple x,y plot and return the fig handle
@@ -718,30 +769,32 @@ def plot_to_fig(x_data,y_data,**kwargs):
718769
# for key, value in kwargs.items():
719770
# print ("%s == %s" %(key, value))
720771

721-
plot_style = get_plot_style("fds")
722-
723772
import matplotlib.pyplot as plt
724773
import matplotlib.ticker as ticker
725774

726-
plt.rcParams.update({
727-
"pdf.use14corefonts": True,
728-
"text.usetex": False,
775+
plot_style = get_plot_style("fds")
729776

730-
# Text and math in Times New Roman
731-
"font.family": "serif",
732-
"font.serif": ["Times", "Times New Roman"],
777+
configure_fds_fonts()
733778

734-
"mathtext.fontset": "custom",
735-
"mathtext.rm": "Times",
736-
"mathtext.it": "Times New Roman:italic",
737-
"mathtext.bf": "Times:bold",
738-
"mathtext.cal": "Times New Roman:italic",
739-
"mathtext.tt": "Courier New",
740-
"mathtext.default": "it",
779+
# plt.rcParams.update({
780+
# "pdf.use14corefonts": True,
781+
# "text.usetex": False,
741782

742-
"axes.unicode_minus": False,
743-
"pdf.compression": 9,
744-
})
783+
# # Text and math in Times New Roman
784+
# "font.family": "serif",
785+
# "font.serif": ["Times", "Times New Roman"],
786+
787+
# "mathtext.fontset": "custom",
788+
# "mathtext.rm": "Times",
789+
# "mathtext.it": "Times New Roman:italic",
790+
# "mathtext.bf": "Times:bold",
791+
# "mathtext.cal": "Times New Roman:italic",
792+
# "mathtext.tt": "Courier New",
793+
# "mathtext.default": "it",
794+
795+
# "axes.unicode_minus": False,
796+
# "pdf.compression": 9,
797+
# })
745798

746799
import logging
747800
# Suppress just the 'findfont' warnings from matplotlib's font manager

0 commit comments

Comments
 (0)