Posts: 299
Threads: 72
Joined: Apr 2019
Aug-06-2019, 09:18 AM
(This post was last modified: Aug-06-2019, 09:18 AM by paul18fr.)
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
Posts: 4,784
Threads: 76
Joined: Jan 2018
Aug-06-2019, 06:08 PM
(This post was last modified: Aug-06-2019, 06:08 PM by Gribouillis.)
Have you tried \underline without the $ signs? The $ signs are for math formulas if I remember well.
Posts: 299
Threads: 72
Joined: Apr 2019
$ are for Latex use (see axis names for example); as expected it does not work as well without it
Posts: 817
Threads: 1
Joined: Mar 2018
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.
Posts: 299
Threads: 72
Joined: Apr 2019
Aug-07-2019, 07:13 AM
(This post was last modified: Aug-07-2019, 07:13 AM by paul18fr.)
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);
Posts: 817
Threads: 1
Joined: Mar 2018
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)
# -------------
Posts: 299
Threads: 72
Joined: Apr 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
Posts: 817
Threads: 1
Joined: Mar 2018
(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.
Posts: 299
Threads: 72
Joined: Apr 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
|