Underline title - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Underline title (/thread-20348.html) |
Underline title - paul18fr - Aug-06-2019 All I'm still trying to dinf the good synthax in order to underline the title; I tried Latex methode with $\underline{My Title}$ but it's not recognized import matplotlib.pyplot as plt import numpy as np n = 20; A = np.random.random((n,2)); A = A[A[:,0].argsort()]; fig, ax = plt.subplots(figsize=(16, 9)); ax.plot(A[:,0], A[:,1], marker='o', color = 'green', linewidth=1.5, markersize=8., linestyle ='-'); ax.set_title(r"My title" + "\n",fontsize=26, fontweight='bold'); # r for Latex ax.minorticks_on(); ax.grid(which='major', linestyle='-', linewidth='1.', color='black'); ax.grid(which='minor', linestyle=':', linewidth='0.5', color='blue') ax.set_xlabel(r"$X$ [-]", fontsize=20); ax.set_ylabel(r"$Y$", fontsize=20); #plt.show();(Some other methods from internet were tested with no sucess) How to proceed? Thanks Paul RE: Underline title - Gribouillis - Aug-06-2019 Have you tried \underline without the $ signs? The $ signs are for math formulas if I remember well. RE: Underline title - paul18fr - Aug-06-2019 $ are for Latex use (see axis names for example); as expected it does not work as well without it RE: Underline title - scidam - Aug-06-2019 If you have latex installed on your system, you can try to set matplotlib.rcParams['text.usetex']=True and run the script. Currently, I have no latex installed on my computer, so I cannot test this.
RE: Underline title - paul18fr - Aug-07-2019 Thanks for the advice. I'm currently using Anaconda distribution; I don't know if Latex/Miktex packages have been installed at the same time, but I can say that the following code generates math expressions. Nonetheless \underline don't work for the title Need to look deeper Paul import matplotlib.pyplot as plt import numpy as np import os PATH = str(os.getcwd()); n = 20; A = np.random.random((n,2)); A = A[A[:,0].argsort()]; fig, ax = plt.subplots(figsize=(16, 9)); ax.plot(A[:,0], A[:,1], marker='o', color = 'green', linewidth=1.5, markersize=8., linestyle ='-'); ax.set_title(r"My title" + "\n",fontsize=26, fontweight='bold'); # les r sont obligatoires pour passer sur Latex ax.minorticks_on(); ax.grid(which='major', linestyle='-', linewidth='1.', color='black'); ax.grid(which='minor', linestyle=':', linewidth='0.5', color='blue') ax.set_xlabel(r"$X$ [-] - $\sin(\sigma / \theta)$", fontsize=20); ax.set_ylabel(r"$Y$ [-] - $\frac{\delta * \sigma}{\sqrt[3]{x^2}}$", fontsize=20); plt.savefig(PATH + '/test_plot.png',dpi=100); RE: Underline title - scidam - Aug-07-2019 It is likely that tex/latex engine is not installed on your system. Nevertheless, you can do the following: insert these lines just before rendering the figure ( plt.savefig ):# --- Insertion from matplotlib import lines # put this line to header rr = max(ax.get_ylim()) mm = np.mean(ax.get_xlim()) line = lines.Line2D([mm - 0.1, mm + 0.1], [1.05 * rr, 1.05 * rr], color='black') line.set_clip_on(False) ax.add_line(line) # ------------- RE: Underline title - paul18fr - Aug-08-2019 Thanks Scidam for the answer, (Aug-07-2019, 11:46 PM)scidam Wrote: It is likely that tex/latex engine is not installed on your system. Strange while Latex formulas have been inserted. I understood your trick of adding manually a line. Paul RE: Underline title - scidam - Aug-08-2019 (Aug-08-2019, 07:08 AM)paul18fr Wrote: Strange while Latex formulas have been inserted.From here: Quote:Note that you do not need to have TeX installed, since matplotlib ships its own TeX expression parser, layout engine and fonts. RE: Underline title - paul18fr - Aug-09-2019 (Aug-08-2019, 11:37 PM)scidam Wrote: Note that you do not need to have TeX installed, since matplotlib ships its own TeX expression parser, layout engine and fonts. ah ok I understand Thanks |