在 tikz 中错误地绘制了我的图表

在 tikz 中错误地绘制了我的图表

平均能量损失

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\usetikzlibrary{patterns,backgrounds}
\def\mytypesetter#1{
\pgfmathparse{#1/pi}
\pgfkeys{/pgf/number format/precision=2}
\pgfmathroundtozerofill{\pgfmathresult}
\pgfmathifisint{\pgfmathresult}{
\pgfmathprintnumber{\pgfmathresult}$\pi$
}{
\pgfmathprintnumber[/pgf/number format/frac, frac denom=2, frac whole=false]{\pgfmathresult}$\pi$
}
}
\begin{document}

\begin{tikzpicture}[>=latex]
\datavisualization [
 school book axes,
  all axes={},
  x axis={
    label=$\omega t$,
    ticks={
      step=(pi/2),
      tick typesetter/.code=\mytypesetter{##1},}
  },
  y axis={
    label=$v\char 44 v_C\char 44 i\char 44 i_C \char 44 p_C$, 
    ticks=none,
    %grid={step=1}
  },
  %style sheet=vary hue,
  style sheet=strong colors,
  style sheet=vary dashing,
  visualize as smooth line/.list={voltage,current,power},
  voltage={label in legend={text={$v \char 44 v_C$}}},
  current={label in legend={text={$i \char 44 i_C$}}},
  power={label in legend={text={$p_C$}}},
]
data [set=voltage, format=function] {
  var x : interval [-pi/2:2*pi] samples 100;
  func y = 2.5*sin(\value x r);
}
data [set=current, format=function] {
  var x : interval [-pi/2:2*pi] samples 100;
func y = 1.5*cos((\value x)r);
}
data [set=power, format=function] {
  var x : interval [-pi/2:2*pi] samples 100;
  func y = 2.5*1.5*sin(\value x r))*(cos(\value x r));
}
;
\begin{scope}[on background layer]
 \path[pattern=vertical lines,pattern color=blue] 
 plot[variable=\x,domain=0:2*pi] ({\x},{2.5*1.5*sin(\x r)*cos(\x r)}); % 7 instead 2.5*1.5 true graph
\end{scope}
\fill[red] (0,3.75) circle (1pt);    
\end{tikzpicture}
\end{document}

并显示,

在此处输入图片描述

但图形应该在下面。我的错在哪里?如何消除间隙?

在此处输入图片描述

答案1

你的第一幅图是正确的。因为瞬时功率的计算方式如下:

p(t)= Vm * Im * sin(wt)* cos(wt)= 1/2 * Vm * Im * sin(2 * wt)

因此瞬时功率的大小是 1.875,而不是 3.75。

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\usetikzlibrary{patterns,backgrounds}
\def\mytypesetter#1{
\pgfmathparse{#1/pi}
\pgfkeys{/pgf/number format/precision=2}
\pgfmathroundtozerofill{\pgfmathresult}
\pgfmathifisint{\pgfmathresult}{
\pgfmathprintnumber{\pgfmathresult}$\pi$
}{
\pgfmathprintnumber[/pgf/number format/frac, frac denom=2, frac whole=false]{\pgfmathresult}$\pi$
}
}
\begin{document}

\begin{tikzpicture}[>=latex]
\datavisualization [
 school book axes,
  all axes={},
  x axis={
    label=$\omega t$,
    ticks={
      step=(pi/2),
      tick typesetter/.code=\mytypesetter{##1},}
  },
  y axis={
    label=$v\char 44 v_C\char 44 i\char 44 i_C \char 44 p_C$, 
    ticks=none,
    %grid={step=1}
  },
  %style sheet=vary hue,
  style sheet=strong colors,
  style sheet=vary dashing,
  visualize as smooth line/.list={voltage,current,power},
  voltage={label in legend={text={$v \char 44 v_C$}}},
  current={label in legend={text={$i \char 44 i_C$}}},
  power={label in legend={text={$p_C$}}},
]
data [set=voltage, format=function] {
  var x : interval [-pi/2:2*pi] samples 100;
  func y = 2.5*sin((\value x) r);
}
data [set=current, format=function] {
  var x : interval [-pi/2:2*pi] samples 100;
func y = 1.5*cos((\value x) r);
}
data [set=power, format=function] {
  var x : interval [-pi/2:2*pi] samples 100;
  func y = 1.5*2.5/2*sin(2*\value x r));
}
;
\begin{scope}[on background layer]
 \path[pattern=vertical lines,pattern color=blue] 
 plot[variable=\x,domain=0:2*pi] ({\x},{2.5*1.5/2*sin(2*\x r)}); % 7 instead 2.5*1.5 true graph
\end{scope}
\fill[red] (0,1.875) circle (1pt);  
\draw [dashed] (-1,1.875)node[right=15,above]{\tiny 1.875}--(5,1.875);  
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容