0

I am trying to get my 3D Plot colorized in a way that the path is colored by a colormap such as viridis or jet.

I am not seeing the issue in my code:

MWE:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\begin{document}

\pgfplotsset{colormap name=viridis}
    
    \begin{tikzpicture}
        \begin{axis}[% 
            minor tick num = 1,
            width=0.5\textwidth, 
            height=0.58\textwidth, 
            view={20}{20},
            no markers,
            line width=1pt,
            colormap/viridis
        ]
            \addplot3+[mesh/ordering=colwise, shader=interp] table[x=X,y=Y,z=Z,col sep=comma] {M_vec_t_konst_B_3D.csv};
        \end{axis}
    \end{tikzpicture}   
\end{document}

A part of the filecontents looks like this:

\begin{filecontents}{\M_vec_t_konst_B_3D.csv}
t,X,Y,Z
1,-.00497500009974665,.00049916489126945,.999987500047175
2,-.00980050543315321,.00198665703923687,.999950000556712
3,-.0143295126224099,.00443263370356666,.999887502818356
4,-.0184199947073833,.00778784045780322,.999800007717161
5,-.0219372868785203,.0119843856077163,.999687517759949
6,-.0247563606311884,.0169367224299857,.999550035813364
7,-.0267640258546666,.0225430120448395,.999387564968603
8,-.0278608499582266,.0286865788699628,.99920010991405
9,-.0279630289409471,.0352378122081474,.998987674519678
10,-.0270038810677119,.042056007814212,.998750264889457
11,-.0249352365935453,.0489916957762689,.998487886120038
12,-.0217284515057763,.0558887888591327,.998200545575422
13,-.0173752135951718,.0625871942592308,.997888249688422
14,-.0118880219680633,.0689251584129809,.997551006987507
15,-.00530035196029782,.0747420217620526,.997188825287703
16,.00233342919743369,.0798806274188361,.99680171416455
17,.0109385639175199,.0841900702264634,.996389682926374
18,.0204205496072064,.0875280343292949,.995952742128616
19,.030666298224561,.0897633835859951,.99549090245734
20,.0415453168338121,.0907783059402484,.995004175465682
\end{filecontents}

What it currently looks like: enter image description here

2
  • Unrelated: No need for both \pgfplotsset{colormap name=viridis} and colormap/viridis Mar 21, 2022 at 22:09
  • @hpekristiansen Ok thank you. I was just frustrated that I could not get the plot to color so I added colormap as often as possible and hoped for it work, but Hasan has now showed how it should be done. Mar 22, 2022 at 10:34

1 Answer 1

2

Just rewrite your plot as

\addplot3+[mesh] table[x=X,y=Y,z=Z,col sep=comma] {M_vec_t_konst_B_3D.csv};

and it should work.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{compat=1.18}
\begin{document}

\pgfplotsset{colormap name=viridis}

    \begin{tikzpicture}
        \begin{axis}[% 
            minor tick num = 1,
            width=0.5\textwidth, 
            height=0.58\textwidth, 
            view={20}{20},
            no markers,
            line width=1pt,
            colormap/viridis]
            \addplot3+[mesh, shader=interp] 
                 table[x=X,y=Y,z=Z,col sep=comma] 
                 {M_vec_t_konst_B_3D.csv};
        \end{axis}
    \end{tikzpicture}   
\end{document}

enter image description here

3
  • You write "and it should work". No mesh/rows or mesh/cols is supplied and the data is not in mesh format, so does it really work? Please add a picture of your output. Mar 21, 2022 at 21:46
  • Add mesh/rows=1 as an option and it works. Mar 21, 2022 at 22:07
  • 1
    I edited my answer to include the picture. Mar 22, 2022 at 3:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .