数据颜色标签在 tikz 环境中不起作用

数据颜色标签在 tikz 环境中不起作用

我正在尝试为我的图添加彩色标签(我使用 \datavisualization 命令,而不是 \begin{axis} 环境),但效果不佳:我的标签(sinx)仍然是黑色,但我希望它与图一样为蓝色。我读了手册,但我不知道我错在哪里,我按照手册说的做了...有人能帮我吗?

\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}

答案1

感谢您提供可编译的示例!如果您添加适当的样式表,它就可以工作。

\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}

在此处输入图片描述

至于您的评论:老实说,这里的行为对我来说有点奇怪。也可以使用绿色文本,例如

\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}

在此处输入图片描述

但我同意你的观点,这比它应该的要复杂得多。

相关内容