0

Using the example page 288 of the pgfplots layers manual, I cannot use another style than mark size.

% Preamble: \pgfplotsset{width=7cm,compat=1.5.1}
\begin{tikzpicture}
\begin{axis}
    \addplot+[
        scatter,
        scatter src=y,
        samples=40,
        visualization depends on={5*cos(deg(x)) \as \perpointmarksize},    
        scatter/@pre marker code/.append style={
            /tikz/mark size=\perpointmarksize,
            /tikz/opacity=\perpointmarksize    % <-- this line has no effect
        }
    ]
    {sin(deg(x))};
\end{axis}
\end{tikzpicture}

Is there something I miss or is it a bug in the library?

  • Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code. Also, what other styles do you want to use? – Andrew Jan 16 at 14:43
1

No, there is no bug. Following the manual one has to use scatter/@pre marker code/.code in a slightly different way, and, more importantly, make sure that the opacity takes values between 0 and 1.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}
    \addplot+[
        scatter,
        scatter src=y,
        samples=40,
        visualization depends on={5*cos(deg(x)) \as \perpointmarksize},
        scatter/@pre marker code/.code={
          \pgfplotscolormapdefinemappedcolor\pgfplotspointmetatransformed
          \pgfmathsetmacro{\myopacity}{max(0,min(1,1+\perpointmarksize/5))}
          \def\markopts{mark size=\perpointmarksize,%
          mapped color,
          opacity=\myopacity}
          \expandafter\scope\expandafter[\markopts]
        },
        scatter/@post marker code/.code={
          \endscope
        },    
    ]
    {sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • Thanks ! Actually, I took the example from the manual, but my version is slightly different: I use a table with a label column. This is set to the meta parameter and I color/shape the marks based on the label. With your solution here, it doesn't work. As I think your answer answers the question, I will leave it unchanged, and create another separate question. Thanks again. – Jav Jan 17 at 9:47

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.