At the moment I use TikZ shadings to show up longitudinal waves in my document like this:
The shading is white where the sine is –1 and blue where the sine equals 1. This looks ok, but unfortunately it is in RGB and I need a clean CMYK document. The above mentioned questions led me to use pgfplots
to make the shading but actually I don’t know how …
This is my MWE
\documentclass{article}
\usepackage[cmyk]{xcolor}
\definecolor{wave}{cmyk}{1,0.35,0,0}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
samples=100,
}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
% Variables
\pgfmathsetmacro\T{1}
\pgfmathsetmacro\A{0.2}
\pgfmathsetmacro\N{5}
\pgfmathsetmacro\D{\N*\T}
\begin{document}
\section{With TikZ}
\begin{tikzpicture}
% Shading
\coordinate (C) at (0.25pt,0);% small overlapping
\foreach \x in {1,...,\N} {
\shade [shading=axis, right color=white, left color=wave, shading angle=90]
($(\x*\T-\T,-\A)-(C)$) rectangle ++($(\T/2,2*\A)+(C)$);
\shade [shading=axis, left color=white, right color=wave, shading angle=90]
($(\x*\T-\T/2,-\A)-(C)$) rectangle ++($(\T/2,2*\A)+(C)$);
}
% Cosine Wave
\draw [black] plot [id=sine, domain=0:\D]
function {\A*cos(2*pi/\T*x)};
\end{tikzpicture}
\section{With PGFplots}
\begin{tikzpicture}
\begin{axis}
\addplot [domain=0:\D] {\A*cos(2*pi/\T*x)};
\end{axis}
\end{tikzpicture}
\end{document}
It would be great if I can only specify the function, e.g. \A*cos(2*pi/\T*x)
and a rectangle to clip the shading, and the rest of the work is done by TeX …
Bonus question: How can I imitate a radial shading like this one
which is done with
\pgfdeclareradialshading{wave}{\pgfpoint{0cm}{0cm}}%
{%
color(0.0cm)=(white);
color(0.01cm)=(white);
color(0.1cm)=(wave);
color(0.2cm)=(white);
color(0.3cm)=(wave);
color(0.4cm)=(white);
color(0.5cm)=(wave);
color(0.6cm)=(white);
color(0.7cm)=(wave);
color(0.8cm)=(white);
color(0.9cm)=(wave)
}
\begin{tikzpicture}
\shade [shading=wave] circle [radius=5] ;
\end{tikzpicture}