3

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}

Relay plots

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
2
  • Welcome to TeX.Stackexchange! Why don't you show us the code for your boolean plot to give us something to start with? Jul 27, 2016 at 20:13
  • Thanks. I edited the post and included the code and data. Jul 27, 2016 at 23:31

1 Answer 1

2

Using some ideas from this post, I made a solution. I defined rectangle* and rectangle2* marks for non-zero and zero values respectively. I used two \addplot in order to plot one signal.

Signals A and B are the same because there is only one digital signal in the data file, but the figure shows that its possible to plot several digital signals in the same axes. The following code:

\documentclass[12pt]{article}
\usepackage{tikz,pgfplots}
\usepackage{pst-plot}
\usepackage{siunitx}
\usepackage{graphicx}
\usepackage{stmaryrd}
\usepackage{pgfplotstable}
\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}    

\pgfkeysdef{/pgf/mark color}{\def\pgf@mark@color{#1}}
\pgfkeysdef{/pgf/colorA}{\def\colorA{#1}}

\pgfdeclareplotmark{rectangle*}{%
\pgfpathmoveto{\pgfqpoint{\pgfplotmarksize}{3\pgfplotmarksize}}%
\pgfpathlineto{\pgfqpoint{0\pgfplotmarksize}{3\pgfplotmarksize}}%
\pgfpathlineto{\pgfqpoint{0\pgfplotmarksize}{-3\pgfplotmarksize}}%
\pgfpathlineto{\pgfqpoint{\pgfplotmarksize}{-3\pgfplotmarksize}}%
\pgfpathmoveto{\pgfqpoint{\pgfplotmarksize}{3\pgfplotmarksize}}%
\pgfsetfillcolor{\pgf@mark@color}
\pgfusepathqfill
}
\pgfdeclareplotmark{rectangle2*}{%
\pgfpathmoveto{\pgfqpoint{\pgfplotmarksize}{0.25\pgfplotmarksize}}%
\pgfpathlineto{\pgfqpoint{0.0\pgfplotmarksize}{0.25\pgfplotmarksize}}%
\pgfpathlineto{\pgfqpoint{0.0\pgfplotmarksize}{-0.25\pgfplotmarksize}}%
\pgfpathlineto{\pgfqpoint{\pgfplotmarksize}{-0.25\pgfplotmarksize}}%
\pgfpathmoveto{\pgfqpoint{\pgfplotmarksize}{0.25\pgfplotmarksize}}%
\pgfsetfillcolor{\pgf@mark@color}
\pgfusepathqfill
}

\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=5.0cm, width=12.0cm,
xlabel={$t~[\si{\ms}]$},
axis y line=middle,
axis x line=bottom,
enlarge x limits={0.01,upper},
enlarge y limits={0.1,upper},
xmajorgrids,
ymin=1,
ymax=7,
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)}},
each nth point=1
]
\nextgroupplot[title={Saída do SF},ylabel={SF},
ytick={2,3,4,5,6,7},yticklabels={\textcolor{blue}{A},\textcolor{red} {B},C,AB,BC,CA}]%
\addplot[only marks,mark=rectangle*,mark size=1,mark color=blue,shift={(axis direction cs:0,1)}] table [x expr=\thisrow{Time}*1000, y expr=\thisrow{Tx}>0] {\datosB};
\addplot[only marks,mark=rectangle2*,mark size=1,mark color=blue,shift={(axis direction cs:0,1)}] table [x expr=\thisrow{Time}*1000, y expr=\thisrow{Tx}<1] {\datosB};
\addplot[only marks,mark=rectangle*,mark size=1,mark color=red,shift={(axis direction cs:0,2)}] table [x expr=\thisrow{Time}*1000, y expr=\thisrow{Tx}>0] {\datosB};
\addplot[only marks,mark=rectangle2*,mark size=1,mark color=red,shift={(axis direction cs:0,2)}] table [x expr=\thisrow{Time}*1000, y expr=\thisrow{Tx}<1] {\datosB};
\end{groupplot}
\end{tikzpicture}
\end{document}

Generates:

Digital outputs

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .