Hot answers tagged

86

You have also to specify an anchor of your legend in this way: legend style={at={(0.03,0.5)},anchor=west} the anchor define what point of the legend box will be placed at the coordinates you define with at={(<>,<>)}. If you use only at={(<>,<>)} the coordinates you insert are that of the axis box where the point (0,0) is the left ...


59

pgfplots defines several shortcut legend pos settings, as defined in Section 4.9.5 of its manual; here you could choose legend pos=north west or legend pos=outer north east, which is currently the only pre-defined legend position outside the axis box. If you want to place it in any other location, the legend pos keys are just shorthand for legend style={...


36

You can add fill=none to the legend style key as in this approach. \documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage{pgfplots} \pgfplotsset{compat=1.9} \begin{document} \begin{tikzpicture} \begin{axis}[ legend style={fill=none} ] \addplot {x}; \addlegendentry{$x$}; \end{axis} \end{tikzpicture} \end{...


25

Here's slightly different version of Martin H's excellent answer that works without the \addlegendentry commands and uses the legend entries key instead (I find that to be more readable). The legend entries are assigned to the \addplot and \addlegendimage commands in the order they're given, so if you move the \addlegendimages before the \addplots (or if you ...


19

Originally, you could use legend style={draw=none, legend columns=-1}, which would draw the legend horizontally and doesn’t have a box around it. The draw=none part works, the legend columns key does not work in the legend style style anymore. But it does outside. Ergo: \begin{customlegend}[ legend columns=-1, legend style={ draw=none, column ...


18

It turns out that this is due to a somewhat quirky behaviour of x filter that's described in the manual: Note that you can provide different x filter/y filter arguments to each \addplot command. It seems there are only problems with the #1 argument, and I haven’t yet found out why. Please use \pgfmathresult in place of #1 if you provide \addplot[x ...


18

The first thing I would do is to define some styles for the various types, this makes it much easier to change things (you change the style, instead of changing every node): \begin{tikzpicture}[ blacknode/.style={shape=circle, draw=black, line width=2}, bluenode/.style={shape=circle, draw=blue, line width=2}, greennode/.style={shape=circle, draw=green,...


17

By default, TikZ nodes do not allow line breaks, but if you add the align=<left/right/center> key you can use \\. Hence, you can modify the legend style as below. \documentclass[border=4pt]{standalone} \usepackage{pgfplots} \pgfplotsset{ compat=1.12 } \begin{document} \begin{tikzpicture} \begin{axis}[ legend style={cells={align=left}} ] ...


15

beamer has the additional font switch \Tiny that will give you a smaller size than \tiny (if your current font supports this size); if this is not enough, you can use \fontsize{<size>}{<baselineskip>}\selectfont with appropriate values. The code: \documentclass{beamer} \usepackage{etex} \usepackage[frenchb]{babel} \usepackage[T1]{fontenc} \...


14

You can reverse the order of the legend entries by setting reverse legend: \documentclass{article} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[xbar, reverse legend] \addplot coordinates {(2.659244418,1)}; \addlegendentry{A} \addplot coordinates {(18.95781994,1)}; \addlegendentry{B} \end{axis} \end{tikzpicture} \end{...


14

You were almost there. Since the pgfplots legend is a matrix, you don't have "items" like with a list, rather rows and columns, so adding the following command does the trick: legend style={row sep=0.5pt} Output Code \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ legend style={ ...


13

Another way to change the legend is to use area legend in the \addplot. To adjust the y tick label style you can use y tick label style as shown below: If you comment out the fixed setting you get the scientific notation for the y-ticks: Code: \documentclass{article} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ ybar, ...


13

Seems that the key handler isn't too careful with dropping outer brace groups, this makes it work: legend entries = {}{$a, b$} , %<- error!


11

You should be able to get the first part of your custom legend like so \addlegendimage{line legend,green} \addlegendentry{Simulation} \addlegendimage{line legend,blue} \addlegendentry{Measurement} obviously for that to work you should comment the legend entries= that you have in your code now. Just add the above code after you \addplot commands. I am not ...


11

Updated According to @Jake's comment, adding the key [align=left] will allow one to type multiple lines in the legend (I guess this is the same for entering multi-line texts in a TikZ node): \addlegendentry[align=left]{ $\text{R}_\text{Darcy,pwr}=[1.26 \times 10^{10},\; 3.76\times 10^9]$ \\ $\text{(1/m)MAE}=1.14\times 10^{-2} \text{ (g/min)}$ } A ...


11

forget plot. This key leaves the \addplot in question out of the legend. \documentclass[a4paper]{article} \usepackage{pgfplots} \usepgflibrary{shapes.geometric} \usetikzlibrary{patterns,arrows} \begin{document} \definecolor{plotrangecolor}{HTML}{D8D8D8} %{D8D8D8} %% %% http://tex.stackexchange.com/questions/29359/pgfplots-how-to-fill-the-area-under-a-...


11

I do not know, why we need xmin, xmax, ... here, but well, it works (at least I hope this is what you have wanted): % arara: pdflatex \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.12} \begin{document} \begin{tikzpicture} \begin{axis}[% hide axis, xmin=10, xmax=50, ymin=0, ymax=0.4, legend style={draw=...


10

Basically, what you are looking for is the key legend pos=outer south, which doesn't exist yet, as explained by the PGFPlots developer in the forum discussion you linked to. The reasons are that it's complicated to take into account whether there's an axis title below the axis or not, which has an influence on where to place the legend. However, it turns out ...


10

(I'm not entirely sure if this is what you're after.) By adding name=leg to the legend style, the legend box will get the (node) name leg. You can add nodes relative to this, if you place them outside the axis. For example: \documentclass[ a4paper ]{scrartcl} \usepackage{ amsmath, tikz, pgfplots, } \usepackage{lmodern} \usepackage[T1]{fontenc} \...


9

If I understand correctly, you're not trying to adjust the width of the legend column that contains the lines, but rather you're trying to increase the length of the lines themselves. You can do that by adding legend image post style={xscale=2} to your axis options: \documentclass{article} \usepackage{pgfplots} \pgfplotsset{ compat=newest, every ...


9

Interestingly, this can be fixed by using (0pt, 0pt) instead of (0,0) in the plot mark definition. Some PGF vs. TikZ problem, perhaps. \documentclass{article} \usepackage{pgfplotstable} \usetikzlibrary{shadows} \pgfplotsset{compat=1.8} \pgfdeclareplotmark{*)} {\shade[draw=green!60!black,ball color=green!70] (0pt, 0pt) circle [radius=5pt];} \begin{...


9

A different solution is to delimit the list by \\. To quote the PGFPlots manual v1.9 4.9.4 "Legends": It is also possible to delimit the list by \\. In this case, the last element must be terminated by \\ as well. Example: \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.8} \begin{document} \begin{tikzpicture} \begin{axis}[ ...


9

Try \documentclass{article} \usepackage{pgfplots} \begin{document} \pgfplotsset{width=0.5*\textwidth} \begin{tikzpicture} \begin{axis}[xlabel={$\theta_o$}, legend pos=south east]%or north west, ... ,outer north east \addplot[mark=none, color=red] coordinates {(0,0) (3,3)}; \addlegendentry{red} \addplot[mark=...


9

A sample: \documentclass{article} \usepackage{pgfplots} \begin{document} \pgfplotsset{ compat=newest, /pgfplots/legend image code/.code={% \draw[mark repeat=2,mark phase=2,#1] plot coordinates { (0cm,0cm) (0.3cm,0cm) (0.6cm,0cm) (0.9cm,0cm) (1.2cm,...


9

This worked for me, but am not sure if externalize is working. Anyway, I am assuming that \pgfplotslegendfromname does not use the aux file. \documentclass{article} \usepackage[width=18cm]{geometry} \usepackage{pgfplots} \usepgfplotslibrary{groupplots} \usetikzlibrary{pgfplots.groupplots} \usetikzlibrary{plotmarks} \usetikzlibrary{calc} \...


9

I think the easiest solution is to create your "legend" yourself with the \matrix command. To get the \addplot styles you just need to \label them accordingly and to recall them, use the \ref feature inside a \matrix cell. For more details please have a look at the comments in the code. \documentclass[border=5pt]{standalone} \usepackage{pgfplots} % ...


9

The fillbetween library is for things like this. Note the addition of name path for both plots, and the removal of fill=black from the second one. Because the filling didn't work with an only marks plot, I removed only marks and added draw opacity=0. Note that instead of defining all those \point macros, you can use e.g. (1.5,{exp(-1.5)}) in the coordinate ...


8

This is a bug (thanks for the report). A valid work-around might be to reconfigure the legend for this plot: \documentclass{standalone} \usepackage{tikz,pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[view={0}{90}, legend image post style={ sharp plot, draw=\pgfkeysvalueof{/pgfplots/contour/draw color}, }, legend ...


Only top voted, non community-wiki answers of a minimum length are eligible