2

I want to draw a 3D graph that uses point meta = explicit symbolic for the nodes near coord, and I also want to use meta = explicit symbolic (or something similar) for coloring the blocks in function of z entries from the data. Here is my actual code.

\begin{tikzpicture}
\begin{axis}[
title={\textbf{Graphique 5. Vue 3D du graphique 4 avec l'âge moyen à la maternité des générations}},
title style= {text width=14cm, align = center},
ymajorgrids,
xmajorgrids,
zmajorgrids,
enlargelimits,
z buffer = sort,
width=15cm,
height=12cm,
ylabel={ISF},
xlabel={Descendance finale},
zlabel={AMM},
%x dir = reverse,%y dir = reverse,%z dir = reverse,
    colormap={summap}{
    color=(black); color=(violet) ;
    color=(orange)
    color=(red)
},
 scatter/use mapped color={
    draw=mapped color,fill=mapped color!70},
scatter src=z,
point meta= explicit symbolic
]
\addplot3[only marks,ycomb,scatter,mark=cube*,mark size=7, mark color=blue, nodes near coords*, every node near coord/.append style={anchor = south, font=\tiny}] 
coordinates {
(3.489,4.0375, 29) [1925]
(3.354,4.0055, 28) [1930]
(2.821,3.6745, 27) [1935]
(2.360,2.7205, 26) [1940]
(1.948,1.9355, 26) [1945]
(1.693,1.6930, 27) [1950]
(1.608,1.4805, 27) [1955]
(1.618,1.4155, 28) [1960]
(1.642,1.6360, 28) [1965]
(1.632,1.4940, 28) [1970]
};
\end{axis}
\end{tikzpicture}

enter image description here

On this picture, the nodes names are right, but not the block colors.

If I do this:

scatter src=z,
%point meta= explicit symbolic

then the colors are right, but not the node names:

enter image description here

How could I solve this? Thank you!

3

If you restructure your "coordinates" to a "table" then it is quite easy to accomplish what you need. Then you can use the visualization depends on feature to store the Meta values and apply these stored values to the nodes near coords.

% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        compat=1.3,
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        title={\textbf{Graphique 5. Vue 3D du graphique 4 avec l'âge moyen à la
               maternité des générations}},
        title style={
            text width=14cm,
            align=center,
        },
        ymajorgrids,
        xmajorgrids,
        zmajorgrids,
        enlargelimits,
        z buffer=sort,
        width=15cm,
        height=12cm,
        ylabel={ISF},
        xlabel={Descendance finale},
        zlabel={AMM},
        colormap={summap}{
            color=(black)
            color=(violet)
            color=(orange)
            color=(red)
        },
         scatter/use mapped color={
            draw=mapped color,
            fill=mapped color!70,
        },
        ycomb,
        % ---------------------------------------------------------------------
        % store the value of column "Meta" in the macro `\Meta' ...
        visualization depends on={
            value \thisrow{Meta} \as \Meta
        },
        % ... and use it as label for `nodes near coords'
        nodes near coords*=\Meta,
        % ---------------------------------------------------------------------
        nodes near coords style={
            anchor=south,
            font=\tiny,
        },
    ]
        \addplot3 [
            mark=cube*,
            mark size=7,
        % restructured "coordinates" to "table" which makes it much easier
        % to write and also to provide a solution to your problem
        ] table [x=X,y=Y,z=Z,meta=Meta] {
            X       Y       Z   Meta
            3.489   4.0375  29  1925
            3.354   4.0055  28  1930
            2.821   3.6745  27  1935
            2.360   2.7205  26  1940
            1.948   1.9355  26  1945
            1.693   1.6930  27  1950
            1.608   1.4805  27  1955
            1.618   1.4155  28  1960
            1.642   1.6360  28  1965
            1.632   1.4940  28  1970
        };
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

  • +1, Like this more than mine... but I'll let it here because sometimes is a useful technique. – Rmano May 16 '17 at 12:01
  • @Rmano, thank you. Sure, I also like more than one solution to a problem. Than everybody is free to choose what fits his/her needs best. – Stefan Pinnow May 16 '17 at 12:05
  • Thank you a lot for the very quick answer! I will try next time to provide a proper "MWE" format. – Philip Gaudreau May 17 '17 at 1:41
  • @PhilipGaudreau, you are welcome. The only think missing for a "proper MWE format" was the preamble and \begin{document} and \end{document} respectively. But in this case that wasn't a problem, because nothing "special" was needed. But in general it is nice when a full MWE is given, which makes live a bit easier for us (the helpers). – Stefan Pinnow May 17 '17 at 4:45
1

One solution is to plot twice, once the cubes and then the labels (do not put point meta=... in the global axis definition in this case):

\addplot3[only marks,ycomb,scatter,mark=cube*,mark size=7, mark color=blue, 
] 
coordinates {
(3.489,4.0375, 29) [1925]
(3.354,4.0055, 28) [1930]
(2.821,3.6745, 27) [1935]
(2.360,2.7205, 26) [1940]
(1.948,1.9355, 26) [1945]
(1.693,1.6930, 27) [1950]
(1.608,1.4805, 27) [1955]
(1.618,1.4155, 28) [1960]
(1.642,1.6360, 28) [1965]
(1.632,1.4940, 28) [1970]
};
\addplot3[only marks,  scatter,mark=none,mark size=7, point meta=explicit symbolic, 
mark color=blue, nodes near coords*, every node near coord/.append style={anchor = south, font=\tiny}] 
coordinates {
(3.489,4.0375, 29) [1925]
(3.354,4.0055, 28) [1930]
(2.821,3.6745, 27) [1935]
(2.360,2.7205, 26) [1940]
(1.948,1.9355, 26) [1945]
(1.693,1.6930, 27) [1950]
(1.608,1.4805, 27) [1955]
(1.618,1.4155, 28) [1960]
(1.642,1.6360, 28) [1965]
(1.632,1.4940, 28) [1970]
};

...but you have to play a bit with the label positions now. And obviously it would be much better to define the data in a command to not repeat it.

enter image description here

(PS the strange labels is because you didn't post a proper MWE ;-) and I forgot to add the inputenc...)

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.