# Label in data color don't work in tikz environment

I'm trying to get a colored label for my plot (I use \datavisualization command, not \begin{axis} environment) but with no good results: my label (sinx) still remain black but I wpuld like to have it blue as the plot. I red the manual but I don't understand where I'm wrong, I did as the manual says... can someone help me?

\documentclass{report}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}
\datavisualization [
school book axes,
visualize as smooth line=i,
x axis={label={$\omega t$},
grid,grid={style={dashed,draw opacity=1},step=1},
ticks={{major at={
0 as 0,
1 as $\frac \pi 2$,
2 as $\pi$,
3 as []$\frac{3\pi} 2$,
4 as $2\pi$
}}}},
y axis={ticks=none},
i={style=blue,label in data={text=sinx, when=x is 1,
text colored}}]
data [format=function, set= i] {
var x : interval [0:4] ;
func y = sin(deg(\value x*pi*0.5 ));
};
\end{tikzpicture}
\end{document}

• Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Skillmon Oct 19 '18 at 20:14
• Do you compile with xelatex? The reason I am asking this is this question. – marmot Oct 19 '18 at 20:26
• I edit the post to make the code compilable. I normally use PDFLaTex to compile. – marcoroberto94 Oct 19 '18 at 23:05

Thanks for providing a compilable example! If you add an appropriate style sheet, it works.

\documentclass{report}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}
\datavisualization [
school book axes,
visualize as smooth line=i,
x axis={label={$\omega t$},
grid,grid={style={dashed,draw opacity=1},step=1},
ticks={{major at={
0 as 0,
1 as $\frac \pi 2$,
2 as $\pi$,
3 as []$\frac{3\pi} 2$,
4 as $2\pi$
}}}},
y axis={ticks=none},
style sheet=vary hue,
i={style=blue,label in data={text=$\sin x$, when=x is 1,text colored}}]
data [format=function, set=i] {
var x : interval [0:4] ;
func y = sin(deg(\value x*pi*0.5 ));
};
\end{tikzpicture}

\end{document}


As for your comment: honestly, the behavior here appears a bit odd to me. On can do green text as well, e.g. with

\documentclass{report}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\tikzdvdeclarestylesheetcolorseries{greens}{hsb}{0.3,1.3,0.8}{0,-.4,-.1}
\begin{document}
\begin{tikzpicture}
\datavisualization [
school book axes,style sheet=greens,
%style sheet=marco roberto,
visualize as smooth line=i,
x axis={label={$\omega t$},
grid,grid={style={dashed,draw opacity=1},step=1},
ticks={{major at={
0 as 0,
1 as $\frac \pi 2$,
2 as $\pi$,
3 as $\frac{3\pi} 2$,
4 as $2\pi$
}}}},
y axis={ticks=none},
i={label in data={text=$\sin x$, when=x is 1,text colored}}
]
data [format=function, set=i] {
var x : interval [0:4] ;
func y = sin(deg(\value x*pi*0.5 ));
};
\end{tikzpicture}
\end{document}


But I agree with you that this is more complicated than it should.

• @marcoroberto94 Good point. I also do not know what's going on. Could be that you found a bug. I added something that does the green thingy but it is unnecessarily complicated. – marmot Oct 20 '18 at 4:01