I work with electrical power systems and always I need to plot voltage and current signals. Sometimes I need to plot boolean signals. I'm using pgfplots and groupplots specifically to do this work as shown in the first figure (with titles in portuguese) using the following code (headers not included):
\pgfplotstableread{FaltaBCplots.dat}{\datosB}
\raggedleft
\begin{tikzpicture}
\begin{groupplot}[group style={group size=1 by 9, vertical sep=0.84cm, group name=mygroup},/tikz/background rectangle/.style={draw=none},
legend columns=-1,
cycle list name=Renzo04,
height=2.86cm, width=16.0cm,
xlabel={$t~[\si{\ms}]$},
%hide y axis,
legend style={mark options={scale=1.35},/tikz/every even column/.append style={column sep=1.0ex}},
axis y line=middle,
%axis x line=middle,
axis x line=bottom,
%enlarge x limits=0.05,
enlarge x limits={0.01,upper},
%enlarge x limits=0.01,
enlarge y limits={0.1,upper},
xmajorgrids,
%enlargelimits = true,
xmin=0, xmax=200,
every axis x label/.append style={at={(current axis.south east)},anchor=west,font=\footnotesize},
every axis y label/.append style={at={(current axis.north west)},above=0mm,font=\footnotesize},
every axis title/.append style={at={(0.5,0.975)}},
xticklabel = \relax,
each nth point=1
%samples=200,
%xtick={0,60, 120, 180, 240, 300, 360},
]
\nextgroupplot[title={Tens\~oes no terminal emissor},%ylabel={\small $f_1(t)$},
legend entries={Fase A, Fase B, Fase C},
legend to name=legendas,ylabel={$v~[\si{\kV}]$}]%,ymin=-0.2,ymax=0.2]
\addplot table [x expr=\thisrow{Time}*1000, y={LSva}] {\datosB};
\addplot table [x expr=\thisrow{Time}*1000, y={LSvb}] {\datosB};
\addplot table [x expr=\thisrow{Time}*1000, y={LSvc}] {\datosB};
\nextgroupplot[title={Correntes no terminal emissor},ylabel={$i~[\si{\kA}]$}]%
\addplot table [x expr=\thisrow{Time}*1000, y={LSia}] {\datosB};
\addplot table [x expr=\thisrow{Time}*1000, y={LSib}] {\datosB};
\addplot table [x expr=\thisrow{Time}*1000, y={LSic}] {\datosB};
\nextgroupplot[title={Tens\~oes no ponto de falta},ylabel={$v~[\si{\kV}]$}]%
\addplot table [x expr=\thisrow{Time}*1000, y={LFva}] {\datosB};
\addplot table [x expr=\thisrow{Time}*1000, y={LFvb}] {\datosB};
\addplot table [x expr=\thisrow{Time}*1000, y={LFvc}] {\datosB};
\nextgroupplot[title={Corrente de falta},%ylabel={\small $f_1(t)$},
ylabel={$i~[\si{\kA}]$},legend style={draw=none},
legend entries={$i_{bc}$},legend to name=legendaIF]%,ymin=-0.2,ymax=0.2]
\addplot+[red!50!black] table [x expr=\thisrow{Time}*1000, y={IbcFault}] {\datosB};
\nextgroupplot[title={Tens\~oes no terminal receptor},ylabel={$v~[\si{\kV}]$}]%
\addplot table [x expr=\thisrow{Time}*1000, y={LRva}] {\datosB};
\addplot table [x expr=\thisrow{Time}*1000, y={LRvb}] {\datosB};
\addplot table [x expr=\thisrow{Time}*1000, y={LRvc}] {\datosB};
\nextgroupplot[title={Correntes no terminal receptor},ylabel={$i~[\si{\kA}]$},
xticklabel={}]%
\addplot table [x expr=\thisrow{Time}*1000, y={LRia}] {\datosB};
\addplot table [x expr=\thisrow{Time}*1000, y={LRib}] {\datosB};
\addplot table [x expr=\thisrow{Time}*1000, y={LRic}] {\datosB};
\nextgroupplot[title={Componente real das imped\^ancias usadas pelo SF},
cycle list name=C6e,
ylabel={$R~[\si{\ohm}]$},legend entries={$Z^{SF}_a$,$Z^{SF}_b$,$Z^{SF}_c$,$Z^{SF}_{ab}$,$Z^{SF}_{bc}$,$Z^{SF}_{ca}$},
legend to name=legendas2,yshift=-1.13cm]%
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZANRE}] {\datosB};
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZBNRE}] {\datosB};
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZCNRE}] {\datosB};
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZABRE}] {\datosB};
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZBCRE}] {\datosB};
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZCARE}] {\datosB};
\nextgroupplot[title={Componente imagin\'aria das imped\^ancias usadas pelo SF},
cycle list name=C6e,
ylabel={$X~[\si{\ohm}]$}]%
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZANIM}] {\datosB};
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZBNIM}] {\datosB};
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZCNIM}] {\datosB};
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZABIM}] {\datosB};
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZBCIM}] {\datosB};
\addplot+[mark repeat=5,mark phase=2,const plot mark right] table [x expr=\thisrow{Time}*1000, y={ZCAIM}] {\datosB};
\nextgroupplot[title={Saída do SF},
xticklabel={},ylabel={SF},ytick=data]%
\addplot+[cdef1,very thick] table [x expr=\thisrow{Time}*1000, y={Tx}] {\datosB};
\end{groupplot}
\node [above] at ($(mygroup c1r1.north) + (0,0.55cm)$) {\ref{legendas}};
\node [above] at ($(mygroup c1r7.north) + (0,0.6cm)$) {\ref{legendas2}};
\node [above] at ($(mygroup c1r4.north) - (5.7,0.7cm)$) {\ref{legendaIF}};
\end{tikzpicture}
The last plot is a boolean variable and I need to plot some variables like this, but I want to do this work like the second figure, where the boolean signals are in blue and there is a bar for values different from zero and line for values=0.
For help, the following full code only for digital input was included:
\documentclass[12pt]{article}
\usepackage{pstricks}
\usepackage{tikz,pgfplots}
\usepackage{pst-plot}
\usepackage{psfrag}
\usepackage{siunitx}
\usepackage{steinmetz}
\usepackage{import}
\usepackage{graphicx}
\usepackage{stmaryrd}
\usepackage{filecontents}
\usepackage{pgfplotstable}
\usepackage{flowchart}
\usepackage{xfrac}
\usepackage{anyfontsize}
\pgfplotsset{compat=newest}
\usetikzlibrary{backgrounds,pgfplots.groupplots}
\usetikzlibrary{arrows}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\PassOptionsToPackage{english, brazilian}{babel}
\usepackage{babel}
\PassOptionsToPackage{T1}{fontenc}
\usepackage{fontenc}
\begin{document}
\pagestyle{empty}
\pgfplotstableread{FaltaBCplots.dat}{\datosB}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=1 by 9, vertical sep=0.84cm, group name=mygroup},/tikz/background rectangle/.style={draw=none},
height=2.86cm, width=16.0cm,
xlabel={$t~[\si{\ms}]$},
legend style={mark options={scale=1.35},/tikz/every even column/.append style={column sep=1.0ex}},
axis y line=middle,
axis x line=bottom,
enlarge x limits={0.01,upper},
enlarge y limits={0.1,upper},
xmajorgrids,
xmin=0, xmax=200,
every axis x label/.append style={at={(current axis.south east)},anchor=west},
every axis y label/.append style={at={(current axis.north west)},above=0mm},
every axis title/.append style={at={(0.5,0.975)}},
xticklabel = \relax,
each nth point=1
]
\nextgroupplot[title={Saída do SF},
xticklabel={},ylabel={SF},ytick=data]%
\addplot[red,very thick] table [x expr=\thisrow{Time}*1000, y={Tx}] {\datosB};
\end{groupplot}
\end{tikzpicture}
\end{document}
The data file is FaltaBCplots.dat. The digital inputs of this file are similar to:
Time SignalA SignalB
0.0 0 0
0.0005 0 0
0.0010 0 0
0.0015 1 6
0.0020 1 6
0.0025 1 6
0.0030 1 6
0.0035 1 0
0.0040 1 0
0.0045 1 0