pgf-tikz/pgfplots

mark=ball connects and fills the path

Opened this issue · 8 comments

I'm creating a simple graph. When I use

    mark=ball,
    ball color=black,

my path gets connected (the last and the first points) and filled (which i do not want). When I use the same TeX file with

    mark=*,
    mark options={
        fill=black,
    },

everything works as expected, and I get a simple graph. I believe markers should not influence the construction of the whole path.

I can provide my whole script if needed.

This behaviour happens to both of my installations of TeXLive, from 2021 and 2023. compat=1.18.

I can provide my whole script if needed.

Yes please provide a minimal working example.

Well, it was trivial to create that. At least easier than to upload it here. Please change the extension to tex.

addplot or addplot+ don't make a difference. Regular marks (the red plot) work as expected.

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

\pgfplotsset{
  IBD/.style={
    color=black,
    mark=ball,
    ball color=black,
  },
  MC/.style={
    color=red,
    mark=*,
    mark options={
      fill=red,
    },
  },
}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    legend entries={MC,IBD}
  ]
    \addplot [MC] {x^2};
    \addplot [IBD] {x^3};
  \end{axis}
\end{tikzpicture}

\end{document}

mwe.txt
mwe

I can provide my whole script if needed.

Yes please provide a minimal working example.

Thank you for giving me a link to what an MWE is; I think you could add it into a template for new issues.

The culprit is ball color=black, which is an tikz option. From its doc in the pgfmanual (unofficial online version), it seems what you get (a path is auto closed and then shaded) is expected behavior.

/tikz/ball color=⟨color⟩ (no default)

This option sets the color used for the ball shading. It sets the shade and shading=ball options. Note that the ball will never “completely” have the color ⟨color⟩. At its “highlight” spot a certain amount of white is mixed in, at the border a certain amount of black. Because of this, it also makes sense to say ball color=white or ball color=black.

In your use case ball color=<color> should be used inside mark options={<options>} to limit its scope to markers and to not influence the main ploting.

\documentclass[margin=5pt, varwidth]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
  \begin{axis}
    % using inside "mark options"
    \addplot [mark=ball, mark options={ball color=red}] {x^2};
    % reproducible with just "ball color"
    \addplot [ball color=black] {x^3};
  \end{axis}
\end{tikzpicture}

% effect of "ball color" on simple un-closed tikz path
\begin{tikzpicture}
  \draw[ball color=red] (0,0) -- (1,1) -- (1,0);
\end{tikzpicture}
\end{document}

image

Thank you for the clarification.
I never thought that pgfplots can have such interference with TikZ.
I use the standard pgfplots manual from my TeXLive distribution, maybe you could add an example of a proper ball color there?

Do you have access to the official manual, why does there have to be an unofficial one?

I never thought that pgfplots can have such interference with TikZ.

The pgfplots package manual (v1.18.1), sec. 4.4.1 "PGFPlots and TikZ Options" reads

TikZ options and pgfplots options can be mixed inside of the axis arguments and in any of the associated styles.

I use the standard pgfplots manual from my TeXLive distribution, maybe you could add an example of a proper ball color there?

Like this?

--- a/doc/latex/pgfplots/pgfplots.reference.markers-meta.tex
+++ b/doc/latex/pgfplots/pgfplots.reference.markers-meta.tex
@@ -98,7 +98,8 @@ And with |\usetikzlibrary{plotmarks}|:
 
         This marker is special and can easily generate big output files if
         there are lots of them. It is also special in that it needs
-        |ball color| to be set (in our case, it is |ball color=yellow!80!black|.
+        |ball color| to be set inside |mark options|
+        (in our case, it is |ball color=yellow!80!black|).
 
     \item[mark=text] \showit{mark=text,every mark/.append style={scale=0.5}}
 

Do you have access to the official manual, why does there have to be an unofficial one?

Yes I have access to the official manual in PDF. The unofficial one provides webpage links to sections, commands, and/or options in pgfmanual and pgfplots manual, which may be preferable when referring to them on web. The word "unofficial" doesn't mean the content is unreliable, but only indicates it's not maintained by pgf-tikz team.

I would say "It is also special in that inside |mark options| it needs |ball color| to be set" (because otherwise people might think that only this option needs to be set inside mark options). I would say that in that section on markers it is not clear that markers should be set within that scope.

Moreover, I can see that the option mark color has an example outside of that scope, simply

\addplot [ red, mark color=red!50!white, mark=halfsquare*, ]

If I were a developer, I would disallow such syntax (because ball color in the same place is very different). However, it is your choice then.

Thank you for clarifications and quick replies! Feel free to close it when you feel appropriate.

True this reflects some inconsistent design and maybe misleading naming, all inherited from pgf/tikz.

  • mark color sets filling color of plot marks only, but ball color does three things. It sets shading, turns on shading mode, and sets shading color. The first two things are equivalent to shading=ball.
  • Color of plot marks is only picked up when drawing plot marks, but shading mode immediately affects current path.
  • Things may be a bit clearer if there's a separate ball shading color option. Then one can use
    \addplot [ mark color=..., ball shading color=..., mark=..., mark options={shading=ball} ]
  • Other shading options like top color share similar issue with ball color. Their key names read like xxx color, but apart from color setting, they also select shading and turns on shading mode for current path.