0

All, I am pretty new to matplotlib. How could I change the font.weight when using [text.usetex]: In the following code, I am using a greek symbol (lambda) for the xaxis but the weight of the symbol itself seems to be light and is poorly noticeable when a pdf file is produced from the latex file.

I don't understand why setting font.weight='bold' doesn't have an effect.

Any idea how could I change the weight of the {lambda} symbol. Please, NOTE: I don't mean to change the font size but the font weight.

Thank you in advance!

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.gridspec as gridspec
from list2nparr import list2nparr

plt.rcParams['text.latex.preamble']=[r"\usepackage{lmodern}"]
plt.rcParams['text.usetex'] = True 
plt.rcParams['font.family'] = 'lmodern'
plt.rcParams['font.weight'] = 'bold'

fig = plt.figure()
for j in range(1,5):

  l = str(j)
  ax = fig.add_subplot(2,2,j)
  data = list2nparr('pwq'+l+'.txt')
  data2 = list2nparr('ssflux.dat')

  x  = data[:,0]
  y1 = data[:,1]
  y2 = data[:,2]
  y3 = data[:,3]
  y4 = data[:,4]

  mxval = []
  for i in range(len(x)):
     c= data[i,1]+data[i,2]+data[i,3]+data[i,4]
     mxval.append(c)

  fact = 26*max(mxval)
  xc = data2[:,0]
  yc = data2[:,1]
  yer = data2[:,2]

  ax.bar(x,y1, 1.6666, color='#FFA500',lw = 0.5)
  ax.bar(x,y2, 1.6666, color='#00BFFF',bottom = y1,lw=0.5)
  ax.bar(x,y3, 1.6666, color='m',bottom = y2+y1, lw=0.5)
  ax.bar(x,y4, 1.6666, color='g',bottom = y3+y2+y1,lw = 0.5)
  ax.errorbar(xc,yc*fact,yerr=yer*fact,fmt='o',c='k',mec='k',lw = 0.2, ms=2.5)
  plt.ylim(ymin=0)
  ax.tick_params(axis='both', labelsize=16)
  ax.ticklabel_format(style='sci',scilimits=(-3,4),axis='both',labelsize=17)  
#  ax.yaxis.major.formatter._useMathText = True

  if j == 1 or j == 2:
    ax.axes.xaxis.set_ticklabels([])

  if j == 1 or j == 3:
    plt.ylabel('N',rotation = 0,labelpad=20)

  if j == 3 or j == 4:
    plt.xlabel(r"$\lambda_{\odot}$, (deg)", fontsize=17,fontweight='bold')

plt.subplots_adjust(hspace=0.12)
plt.savefig('figure.eps', fmt = 'eps',bbox_inches='tight')
Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
user3578925
  • 881
  • 3
  • 16
  • 26
  • Did the format used in the answer for http://stackoverflow.com/questions/3899980/how-to-change-the-font-size-on-a-matplotlib-plot not work for you? – Mike 'Pomax' Kamermans Oct 21 '15 at 04:07
  • Unfortunately, the suggested answer does not work for me. If I disable the lines: plt.rcParams['text.usetex'] = True plt.rcParams['font.family'] = 'lmodern' then it works, but what I want is to change Tex fonts. Any ideas. – user3578925 Oct 21 '15 at 09:01
  • Is there a reason you want to specifically use TeX fonts instead of the normal OpenType versions? Latin Modern can be found over on https://www.ctan.org/tex-archive/fonts/lm/fonts/opentype/public/lm – Mike 'Pomax' Kamermans Oct 21 '15 at 15:45
  • The reason I prefer the Tex fonts is because they look nicer and more scientific. Before, I started using matplotlib I was using GNUPLOT and the latex font rendition was way better. So, I thought since matplotlib is so versatile, it would allow to handle the latex fonts much better. – user3578925 Oct 21 '15 at 16:46
  • Right, so that has nothing to do with what I suggested: Latin Modern (the `lmodern` you're calling) is the typeface you're selecting. Whether you load that as "TeX Font" version, or OpenType version, or any other version from the official Latin Modern CTAN repository doesn't matter: they all look the same. So to make life easy on yourself, just use the OpenType versions *unless* those are not available (and as far as I know, all the fonts you might want to pull from the TeX collection have OpenType versions) – Mike 'Pomax' Kamermans Oct 21 '15 at 16:50
  • Thank you so much for the suggestion. Could you please illustrate how I can "lmodern" with the OpenType fonts? I mean could you show me how the rc.Params in my code should look like? – user3578925 Oct 22 '15 at 22:15
  • look up [how to use a font from file with matplotlib](http://stackoverflow.com/questions/7726852/how-to-use-a-random-otf-or-ttf-font-in-matplotlib), and then download and use the .otf file from the CTAN repository. – Mike 'Pomax' Kamermans Oct 23 '15 at 16:45

0 Answers0