5

I don't really like how my legend is showing up, there is no space between the line and the text in the legend and i don't know how to rectify it. I set the font to \tiny in my legend style but it does not look good at all. This is my piece of code,

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[
legend style={font=\small},
legend pos=north west,
title={Performance},
xmin=5,
ymin=0,
xmax=35,
ymax=10,
axis lines=middle,
grid=both,
xtick={0,5,...,35},
ytick={0,1,...,10},
axis line style={->},
ylabel near ticks,
xlabel near ticks,
%scaled y ticks = false,
%yticklabel style={/pgf/number format/fixed, precision=2},
xlabel={Number of interpolating points, m},
ylabel={Time-taken}]
\addplot[thick, color=red,mark=x] coordinates {
    (8,4.3093)
    (16,6.0535)
    (32,9.8420)
};
\addplot[very thick, color=cyan,mark=x] coordinates {
    (8,0.1893)
    (16,0.1843)
    (32,0.1933)
  };
\addplot[very thick, color=yellow,mark=x] coordinates {
    (8,1.1684)
    (16,0.8889)
    (32,1.3953)
 };
\legend{RBF-HFD,RBF-FD,RBF-RA}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

Here is the output: Performance

Any help would be greatly appreciated. Thank you.

2
  • 1
    Hi, please can you put a complete code that it compiles?
    – Sebastiano
    Mar 31, 2019 at 20:33
  • 1
    Please -- as usual here -- make your code snippet compilable, then we do not have to guess what you are doing ...
    – Mensch
    Mar 31, 2019 at 20:38

1 Answer 1

2

I can't reproduce your problem and to my taste the result is nice. However, if you like to left align text in legend, than try the following:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}      % <---


\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
legend style={font=\small},
legend cell align=left,        % <---
legend pos=north west,
title={Performance},
xmin=5,
ymin=0,
xmax=35,
ymax=10,
axis lines=middle,
grid=both,
xtick={0,5,...,35},
ytick={0,1,...,10},
axis line style={->},
ylabel near ticks,
xlabel near ticks,
%scaled y ticks = false,
%yticklabel style={/pgf/number format/fixed, precision=2},
xlabel={Number of interpolating points, m},
ylabel={Time-taken}]
\addplot[thick, color=red,mark=x] coordinates {
    (8,4.3093)
    (16,6.0535)
    (32,9.8420)
};
\addplot[very thick, color=cyan,mark=x] coordinates {
    (8,0.1893)
    (16,0.1843)
    (32,0.1933)
  };
\addplot[very thick, color=yellow,mark=x] coordinates {
    (8,1.1684)
    (16,0.8889)
    (32,1.3953)
 };
\legend{RBF-HFD,RBF-FD,RBF-RA}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .