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

mark=ball connects and fills the path #473

Open
ynikitenko opened this issue Mar 10, 2024 · 8 comments
Open

mark=ball connects and fills the path #473

ynikitenko opened this issue Mar 10, 2024 · 8 comments

Comments

@ynikitenko
Copy link

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.

@muzimuzhi
Copy link
Member

I can provide my whole script if needed.

Yes please provide a minimal working example.

@ynikitenko
Copy link
Author

ynikitenko commented Mar 11, 2024

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

@ynikitenko
Copy link
Author

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.

@muzimuzhi
Copy link
Member

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

@ynikitenko
Copy link
Author

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?

@muzimuzhi
Copy link
Member

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.

@ynikitenko
Copy link
Author

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.

@muzimuzhi
Copy link
Member

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.

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