7

I have the following plot:

\begin{tikzpicture}

  \begin{axis}[
  xlabel={\tiny X},
  ylabel={\tiny Y},
  xmin=0, xmax=5,
  ymin=0, ymax=18,
  minor x tick num=4,
  minor y tick num=4,
  ytick={0, 2, 4, 6, 8, 10, 12, 14, 16, 18},
  y tick label style={
      /pgf/number format/.cd,
          fixed,
          fixed zerofill,
          precision=2,
      /tikz/.cd,
      font=\tiny},
  x tick label style={font=\tiny},
  every x tick/.style={color=black, thin},
  every y tick/.style={color=black, thin},
  xtick pos=left,
  ytick pos=left,
  axis on top,
  width=5cm,
  height=5cm,
  legend style={mark options={scale=5.0}, at={(0.97,0.03)}, anchor=south east},
  clip mode=individual
  ]
  \addplot+[
  color=red,
  solid,
  line width=1.0pt,
  mark size=1.8pt,
  mark=star,
  mark options={solid, line width=0.5pt},
  error bars/.cd, y dir=both,y explicit]
  plot coordinates {
  (0, 1)
  (1, 2)
  (2, 4)
  (3, 8)
  (4, 16)
  };
  \addlegendentry{My plot};
  \end{axis}
  \end{tikzpicture}

And I am trying to change the scale/size of the markers inside the legend. I have been looking around for a while now and could not find a solution. The only solution I found was a thread where someone wanted to reduce the scale of the markers in the legend and the suggested solution was to add

    legend style={mark options={scale=0.5}

I tried to use that to increase the scale, but it still doesn't do anything to my final output. I also did try:

    legend style={mark options={size=5pt}

and

    legend style={mark size=5pt}

without success.

I am running: Package: tikz 2010/10/13 v2.10 (rcs-revision 1.76) Package: pgfplots 2015/01/31 v1.12 Data Visualization (1.12)

Does anyone have a suggestion why it would not work, or any other solution to increase the mark size in the legend?

  • Weirdly enough, it works if you use legend style={mark size=5pt} and comment out the mark size=1.8pt line in the \addplot options. See tex.stackexchange.com/questions/89797/… – JamesNZ Oct 12 '15 at 9:30
  • Thanks for the suggestion. That does work. Unfortunately, now the mark size in the plot is too small. I am guessing its just the default value now. – J DSP lab Oct 12 '15 at 9:48
4

You can use legend image post style={scale=0.5},. For details, consult page 209-210 of pgfplots manual.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
  \begin{tikzpicture}

  \begin{axis}[
  xlabel={\tiny X},
  ylabel={\tiny Y},
  xmin=0, xmax=5,
  ymin=0, ymax=18,
  minor x tick num=4,
  minor y tick num=4,
  ytick={0, 2, 4, 6, 8, 10, 12, 14, 16, 18},
  y tick label style={
      /pgf/number format/.cd,
          fixed,
          fixed zerofill,
          precision=2,
      /tikz/.cd,
      font=\tiny},
  x tick label style={font=\tiny},
  every x tick/.style={color=black, thin},
  every y tick/.style={color=black, thin},
  xtick pos=left,
  ytick pos=left,
  axis on top,
  width=5cm,
  height=5cm,
  legend image post style={scale=0.5},  %%% <--- here
  legend style={at={(0.97,0.03)}, anchor=south east},
  clip mode=individual
  ]
  \addplot+[
  color=red,
  solid,
  line width=1.0pt,
  mark=star,  
  mark options={mark size=4pt,solid, line width=0.5pt}, %% make size 4pt for demo
  error bars/.cd, y dir=both,y explicit]
  plot coordinates {
  (0, 1)
  (1, 2)
  (2, 4)
  (3, 8)
  (4, 16)
  };
  \addlegendentry{My plot};
  \end{axis}
  \end{tikzpicture}
\end{document}

enter image description here

Another option is to use forget plot in the \addplot+ options and the add

\addlegendimage{red,line width=1.0pt,,mark=star,mark options={mark size=2pt,solid, line width=0.5pt}};
  \addlegendentry{My plot};
  • Thanks! That works perfectly. I would have never though of looking at the "legend image post style". – J DSP lab Oct 12 '15 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.