From: Arnaldo R. <arn...@gm...> - 2014-09-05 19:54:27
|
Hi, I'm trying to figure out how I could use greek letters on axis labels, without italic. I have read a lot about alternatives, but I do need to use LaTeX to insert a table inside the plot area. Using mathtex it responds with normal font on greek letters. What I`m doing wrong? The following code plots my table, but greek letters are not in Arial. import numpy as npimport matplotlib.pyplot as plt t2 = np.arange(100) fig = plt.figure(figsize=(8,4)) ax = fig.add_subplot(111) plt.rcParams.update({'font.family' : 'sans-serif', 'font.sans-serif' : 'Arial', 'font.style' : 'normal', 'xtick.labelsize' : 12, 'ytick.labelsize' : 12, 'mathtext.fontset' : 'stixsans', 'mathtext.default': 'regular', 'mathtext.tt' : 'Arial', }) plt.subplots_adjust(left=0.12, right=0.95, top=0.95, bottom=0.1) ax.set_xlim(0,100) xvals = [0, 16.6, 33.33, 50, 66.66, 83.33, 100] ax.set_xticks(xvals) ax.set_xticklabels(['tick 0', 'tick 1', 'tick 2','tick 3', 'tick 4', 'tick 5', 'tick 6']) ax.set_ylabel(r'$\mu$text $\eta$text $\cdot$ m$^{-2}$ s$^{-1}$') ax.set_yticklabels(['0', '200', '400', '600', '800', '1000', '1200', '1400']) ax.plot(t2, color='black') ax.fill_between(np.arange(0, len(t2)),t2,0, color='black', alpha=0.8) from matplotlib import rc rc('font',**{'family':'sans-serif','sans-serif':['Arial']}) rc('text', usetex=True) table = r'''\begin{tabular}{lccccccc}\hline&tick 0& tick 1 & tick 2 & tick 3 & tick 4 & tick 5 & tick 6 \\\hline Vals & 32.00 & 3.28 & 5.80 & 5 & 8 & 45 & 7.3 \\\hline \end{tabular}''' plt.text(20,80,table,size=10) plt.show() And an example using Mathtex, using regular fonts work out of the box, but my table of course is included as plain text. I have to close my IPython session and start it again to correct usage of plot parameters. import numpy as npimport matplotlib.pyplot as plt t2 = np.arange(100) fig = plt.figure(figsize=(8,4)) ax = fig.add_subplot(111) plt.rcParams.update({'xtick.labelsize' : 12, 'ytick.labelsize' : 12, 'mathtext.fontset' : 'stixsans', 'mathtext.default': 'regular', 'mathtext.tt' : 'Arial', }) plt.subplots_adjust(left=0.12, right=0.95, top=0.95, bottom=0.1) ax.set_xlim(0,100) xvals = [0, 16.6, 33.33, 50, 66.66, 83.33, 100] ax.set_xticks(xvals) ax.set_xticklabels(['tick 0', 'tick 1', 'tick 2','tick 3', 'tick 4', 'tick 5', 'tick 6']) ax.set_ylabel(r'$\mu$text $\eta$text $\cdot$ m$^{-2}$ s$^{-1}$') ax.set_yticklabels(['0', '200', '400', '600', '800', '1000', '1200', '1400']) ax.plot(t2, color='black') ax.fill_between(np.arange(0, len(t2)),t2,0, color='black', alpha=0.8) #from matplotlib import rc#rc('font',**{'family':'sans-serif','sans-serif':['Arial']})#rc('text', usetex=True) table = r'''\begin{tabular}{lccccccc}\hline&tick 0& tick 1 & tick 2 & tick 3 & tick 4 & tick 5 & tick 6 \\\hline Vals & 32.00 & 3.28 & 5.80 & 5 & 8 & 45 & 7.3 \\\hline \end{tabular}''' plt.text(20,80,table,size=10) plt.show() Regards, Arnaldo. --- *Arnaldo D'Amaral Pereira Granja Russo* Lab. de Estudos dos Oceanos e Clima Instituto de Oceanografia - FURG |