mctools / simplebuild-dgcode

dgcode: the Geant4-based simulation framework of the ESS Detector Group. Provided as simple-build-system bundles.
https://mctools.github.io/simplebuild-dgcode/
Other
2 stars 1 forks source link

PyAna/extras tex font settings might need updating #3

Open tkittel opened 9 months ago

tkittel commented 9 months ago

As evidenced in various warnings and this local uncommitted hack, the PyAna/extras tex font settings might need updating:

--- a/packages/Framework/PyAnalysis/PyAna/python/extras.py
+++ b/packages/Framework/PyAnalysis/PyAna/python/extras.py
@@ -59,10 +59,25 @@ def floatToScientificLatex(x):

 def enable_tex_fonts():
     import matplotlib
-    matplotlib.rcParams.update({'text.usetex':1,
-                                'font.family':'serif',
-                                'font.serif':['cmr10','cm'],
-                                'text.latex.preamble' : r'\usepackage{amsmath}'})#LaTeX fonts
+
+    matplotlib.rcParams.update({
+        # Use mathtext, not LaTeX
+        'text.usetex': False,
+        # Use the Computer modern font
+        'font.family': 'serif',
+        'font.serif': 'cmr10',
+        'mathtext.fontset': 'cm',
+        # Use ASCII minus
+        'axes.unicode_minus': False,
+        #cmr10 needs axis formatter to use mathtext:
+        'axes.formatter.use_mathtext': True,
+    })
+    #
+    #matplotlib.rcParams.update({'text.usetex':1,
+    #                            'font.family':'serif',
+    #                            'font.serif':['cmr10','cm'],
+    #                            'text.latex.preamble' : r'\usepackage{amsmath}'})#LaTeX fonts
+
tkittel commented 9 months ago

I also found a related uncommitted modification of PlotXSectFile.py:

diff --git a/packages/Framework/Utils/XSectUtils/XSectParse/python/PlotXSectFile.py b/packages/Framework/Utils/XSectUtils/XSectParse/python/PlotXSectFile.py
index 5c8228b..3621230 100644
--- a/packages/Framework/Utils/XSectUtils/XSectParse/python/PlotXSectFile.py
+++ b/packages/Framework/Utils/XSectUtils/XSectParse/python/PlotXSectFile.py
@@ -80,17 +80,30 @@ def plot_file(filename,mfp=False,save_fig=None,show=None,versus_wavelength=False
     _plot_begin()
     showMFP=mfp

-    colors_nored = ['c', 'm', 'y','k','g','b']
+    palette_Few = dict(red = "#F15854",
+                       blue="#5DA5DA",
+                       orange="#FAA43A",
+                       green="#60BD68",
+                       brown="#B2912F",
+                       purple="#B276B2",
+                       yellow="#DECF3F",
+                       pink="#F17CB0",
+                       gray="#4D4D4D")
+
+    #colors_nored = ['c', 'm', 'y','k','g','b']
+    colors_nored = [palette_Few[s] for s in ('blue','purple','green','orange','gray','yellow')]
+    color_red = palette_Few['red']
+
     p=XSectParse.ParseXSectFile.parse(filename)
     md=p['metadata']
     procs=p['procs']
     physlist = md.get('PhysicsList',None)#not present in older files
-    title=r'%s %s in \texttt{%s} (%s g/cm$^{3}$, %s K, %s bar)'%(md['ParticleName'].capitalize(),
-                                                            ('MFP' if showMFP else 'X-sections'),
-                                                            md['Material'].replace('_',r'\_'),
-                                                            md['MaterialDensity [g/cm3]'],
-                                                            md['MaterialTemperature [K]'],
-                                                            md['MaterialPressure [bar]'])
+    title='%s %s in "$\\mathtt{%s}$" (%s g/cm$^{3}$, %s K, %s bar)'%(md['ParticleName'].capitalize(),
+                                                                     ('MFP' if showMFP else 'X-sections'),
+                                                                     md['Material'].replace('_',r'\_'),
+                                                                     md['MaterialDensity [g/cm3]'],
+                                                                     md['MaterialTemperature [K]'],
+                                                                     md['MaterialPressure [bar]'])
     #move Total to the end:
     procnames=list(procs.keys())
     if 'Total' in procnames:
@@ -104,14 +117,14 @@ def plot_file(filename,mfp=False,save_fig=None,show=None,versus_wavelength=False
         xvals,yvals = _extract_vals(npa,versus_wavelength,showMFP)
         if not len(yvals):
             continue#perhaps we are showing wavelengths and the PL has no contrib in 0.1..25 Aa
-        col='r' if procname=='Total' else colors_nored[iprocname%len(colors_nored)]
+        col=color_red if procname=='Total' else colors_nored[iprocname%len(colors_nored)]
         plt.plot(xvals,yvals,
                  label=procname,color=col)

-    plt.title(title)
+    plt.title(title,fontsize=7)#NOCOMMIT

     if physlist:
-        plt.suptitle(r'\texttt{Geant4} with physics list \texttt{%s}'%physlist.replace('_','\_'))
+        plt.suptitle(r'$\mathtt{Geant4}$ with physics list $\mathtt{%s}$'%physlist.replace('_','\_'),fontsize=12)

     _plot_end(show,save_fig,versus_wavelength,showMFP,logx,logy,softbrackets=softbrackets)

@@ -154,7 +167,7 @@ def plot_file_cmp(filenames,mfp=False,save_fig=None,show=None,

     proctxt=' of the process %s'%xsectname if xsectname!='Total' else ''
     if title!=False:
-        plt.suptitle(r'Comparison of \texttt{Geant4} %s%s'%('Mean Free Path' if showMFP else 'Cross-sections',proctxt))
+        plt.suptitle(r'Comparison of $\mathtt{Geant4}$ %s%s'%('Mean Free Path' if showMFP else 'Cross-sections',proctxt))

     _plot_end(show,save_fig,versus_wavelength,showMFP,logx,logy,extra,mfpunit=mfpunit,softbrackets=softbrackets)