Hot answers tagged

80

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 ...


58

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={...


47

Pgfplots has a couple of helper methods which do the job - and these methods are mostly independent of any axis. The only required things are the text labels and the styles for the individual images. Here is a short draft which might do what you want: \documentclass{article} \usepackage{pgfplots} % argument #1: any options \newenvironment{customlegend}[1]...


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{...


35

Simply set the key legend columns=2. Depending on what you need, you might also be interested in transpose legend and/or reverse legend. EDIT: in order to customize the legend's appearance, you can use legend style={<option list>} where <option list> can be any option which applies to a PGF \matrix. All these options can be found in the PGF ...


26

Here is a solution based on Using a pgfplots-style legend in a plain-old tikzpicture. There are two examples: in the first one, the descriptions in the legend are centered, while in the second one, the descriptions are left aligned. To define numbers in the legend, I added a key number in legend: % definition to insert numbers \pgfkeys{/pgfplots/number in ...


23

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 ...


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 ...


17

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 ...


17

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,...


16

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}} ] ...


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

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} \...


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!


13

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={ ...


12

To add a legend, you just have to call \addlegendentry{label text} at least once, or set the entry/entries in some other way (using \legend{<list of label texts>} or the legend entries={<list of label texts>} key). By default, the label texts are associated with the plots in the sequence they were created. If, in your example, you add the ...


12

You can adapt the approach described by Christian Feuersänger in Using a pgfplots-style legend in a plain-old tikzpicture to provide a command \legendimageintext{mark=x, draw=blue}: \documentclass{article} \usepackage{pgfplots} \newenvironment{customlegend}[1][]{% \begingroup \csname pgfplots@init@cleared@structures\endcsname \pgfplotsset{#1}% ...


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-...


10

Here is one possibility: \documentclass{article} \usepackage[pdftex,active,tightpage]{preview} \setlength\PreviewBorder{2mm} \usepackage{amssymb,amsmath} \usepackage{pgfplots} \pgfplotsset{compat=1.6} \begin{document} \begin{preview} \begin{tikzpicture} \begin{axis}[ axis lines=middle, width=15cm, height=15cm, % size of the image ...


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 ...


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

(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} \...


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