Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axis-wide mark setting causes inconsistency between legend and plot #476

Open
schtandard opened this issue May 29, 2024 · 2 comments
Open

Comments

@schtandard
Copy link

When using a cycle list that does not set mark and setting it in the axis option, the marker appears in the legend but not in the plot.

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
  \begin{axis} [
        cycle list name=color list,
        mark=o,
      ]
    \addplot+ {x^2};
    \addlegendentry{test}
  \end{axis}
\end{tikzpicture}

\end{document}

image

Setting mark in every axis plot instead works.

I'm not sure what is the intended behavior here (I would have expected the axis-wide setting to work, as the cycle list should not override it, but maybe that's not what's supposed to happen) but the inconsistency with the legend surely isn't it.

@muzimuzhi
Copy link
Member

muzimuzhi commented May 30, 2024

Axis-wide mark setting will go into every axis style so I think the expected behavior is that it affects both plot and legend.

mark=<value> stores <value> in \tikz@plot@mark. It seems currently some conditional on \tikz@plot@mark (most likely one or more of several \ifx\tikz@plot@mark\pgfutil@emptys) is wrong. It assumes every axis never contains mark setting.

As a more interesting example, if I add \tikzset{mark=x} to your example, inside axis environment and just before \addplot, both plot and legend use the axis-wide mark=o. That is, if \addplot starts with a non-empty \tikz@plot@mark, the axis-wide mark setting is piked up by both plot and legend, and that non-empty \tikz@plot@mark is totally overwritten.

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

% equivalent to \begin{axis}[mark=o]
\pgfplotsset{every axis/.style={mark=o}}

\begin{tikzpicture}
  \begin{axis} [
        cycle list name=color list,
        % mark=o,
      ]
    \tikzset{mark=x}
    \addplot+ {x^2};
    \addlegendentry{test}
  \end{axis}
\end{tikzpicture}

\end{document}

image

@schtandard
Copy link
Author

Not sure if this is the same issue or just related, let me know if I should open a separate ticket. When plotting with an axis wide only marks, plot and legend agree, but a \ref does not; a line is drawn. Again, using every axis plot instead (i.e. setting only marks at \addplot) works.

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
  \begin{axis} [only marks]
    \addplot+ {x^2}; \label{plt:test}
    \addlegendentry{test}
  \end{axis}
\end{tikzpicture}

\ref{plt:test}

\end{document}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants