1

MWE

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

And displayed,

enter image description here

But the graphics should be below. Where is my fault? And how to remove gaps?

enter image description here

  • Well, if you use the "add fill afterwards" from here, it would be great if you give some credit to it. And make your question clearer. How do you obtain the lower screen shot. When I compile your code, I get the upper one, as expected. – marmot Mar 24 at 14:34
1

Your first drawing is right. Because the instantaneous power is calculated as:

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

Hence the magnitude of the instantaneous power is 1.875, not 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}

enter image description here

  • I understood my fault. – Özgür Mar 25 at 6:14

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.