Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Underline title
#1
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
Quote
#2
Have you tried \underline without the $ signs? The $ signs are for math formulas if I remember well.
Quote
#3
$ are for Latex use (see axis names for example); as expected it does not work as well without it
Quote
#4
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.
Quote
#5
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); 
İmage
Quote
#6
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)
# -------------
Quote
#7
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
Quote
#8
(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.
Quote
#9
(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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  remove underline from hyperlink in excel SriMekala 0 164 Jul-25-2019, 01:58 PM
Last Post: SriMekala
  Highlight/Underline a string | ValueError: zero length field name in format searching1 1 340 Jul-01-2019, 03:06 AM
Last Post: metulburr
  How to change font size of chart title and axis title ? thrupass 5 4,882 Mar-30-2018, 04:02 PM
Last Post: DrFunn1

Forum Jump:


Users browsing this thread: 1 Guest(s)