2

The legend of my scatter plot is not picking up the sizes of the markers that I'm using. I'm being extreme here so that the difference is obvious. I'm hoping to understand how to get the sizes to be accurately reflected in the legend.

scatter plot

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{semilogyaxis}
    \addplot[ only marks,scatter,scatter src=explicit symbolic,
    scatter/classes={
      1={mark=square*,red},
      2={mark=triangle*,scale=3,blue},
      3={mark=*,,scale=0.5,orange}
    }]
    table[col sep=comma,x=Time,y=Error,meta=MethodID] {
      RunID, MethodID, Method, Error, Time
      1, 1, A, 0.0867695, 11.480295
      1, 2, B, 0.0866708, 9.202405
      1, 3, C, 0.086605, 7.313438
      2, 1, A, 0.00846272, 15.640081
      2, 2, B, 0.00846088, 10.154310
      2, 3, C, 0.00846057, 17.586641
      3, 1, A, 0.000857559, 20.381943
      3, 2, B, 0.000857549, 15.004824
      3, 3, C, 0.000857547, 33.210958
      4, 1, A, 8.42488e-05, 24.970190
      4, 2, B, 8.42485e-05, 17.180806
      4, 3, C, 8.42482e-05, 33.687078
    };
    \legend{A,B,C}
  \end{semilogyaxis}
\end{tikzpicture}
\end{document}

1 Answer 1

5

You should use the option mark size which scales only the marker rather than scale. This way, the markers will also scale in the legend.

The option mark size takes a dimension that defaults to 2pt. So, in order to scale the marker to three times the original size, you would need to set mark size=6pt.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{semilogyaxis}
    \addplot[only marks,scatter,scatter src=explicit symbolic,
    scatter/classes={
      1={mark=square*,red},
      2={mark=triangle*,mark size=6pt,blue},
      3={mark=*,mark size=1pt,orange}
    }]
    table[col sep=comma,x=Time,y=Error,meta=MethodID] {
      RunID, MethodID, Method, Error, Time
      1, 1, A, 0.0867695, 11.480295
      1, 2, B, 0.0866708, 9.202405
      1, 3, C, 0.086605, 7.313438
      2, 1, A, 0.00846272, 15.640081
      2, 2, B, 0.00846088, 10.154310
      2, 3, C, 0.00846057, 17.586641
      3, 1, A, 0.000857559, 20.381943
      3, 2, B, 0.000857549, 15.004824
      3, 3, C, 0.000857547, 33.210958
      4, 1, A, 8.42488e-05, 24.970190
      4, 2, B, 8.42485e-05, 17.180806
      4, 3, C, 8.42482e-05, 33.687078
    };
    \legend{A,B,C}
  \end{semilogyaxis}
\end{tikzpicture}
\end{document}

enter image description here

1
  • Perfect. Thank you!
    – tgkolda
    Aug 5, 2022 at 16:32

You must log in to answer this question.

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