| 1 |
%%%============================================================================== |
| 2 |
% WinEdt pragmas |
| 3 |
% !Mode:: "TeX:EN" |
| 4 |
% Default Compile engines: |
| 5 |
% !TEX program = pdflatex |
| 6 |
% !PDFTeXify ext = --enable-etex --enable-write18 |
| 7 |
% !PDFLaTeX ext = --enable-etex --enable-write18 |
| 8 |
% !BIB program = biber |
| 9 |
%%%============================================================================== |
| 10 |
%% Copyright 2025-present by Alceu Frigeri |
| 11 |
%% |
| 12 |
%% This work may be distributed and/or modified under the conditions of |
| 13 |
%% |
| 14 |
%% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt), |
| 15 |
%% version 1.3c (or later), and/or |
| 16 |
%% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html), |
| 17 |
%% version 3 (or later) |
| 18 |
%% |
| 19 |
%% This work has the LPPL maintenance status *maintained*. |
| 20 |
%% |
| 21 |
%% The Current Maintainer of this work is Alceu Frigeri |
| 22 |
%% |
| 23 |
%% This is version {1.1} {2025/11/15} |
| 24 |
%% |
| 25 |
%% The list of files that compose this work can be found in the README.md file at |
| 26 |
%% https://ctan.org/pkg/tikzfxgraph |
| 27 |
%% |
| 28 |
%%%============================================================================== |
| 29 |
\documentclass[10pt]{article} |
| 30 |
\RequirePackage[verbose,a4paper,marginparwidth=27.5mm,top=2.5cm,bottom=1.5cm,hmargin={40mm,20mm},marginparsep=2.5mm,columnsep=10mm,asymmetric]{geometry} |
| 31 |
\usepackage[T1]{fontenc} |
| 32 |
\usepackage[utf8]{inputenc} |
| 33 |
\usepackage{lmodern} |
| 34 |
\usepackage[infograb]{codedescribe} |
| 35 |
\RequirePackage[inline]{enumitem} |
| 36 |
\SetEnumitemKey{miditemsep}{parsep=0ex,itemsep=0.4ex} |
| 37 |
|
| 38 |
\RequirePackage[backend=biber]{biblatex} |
| 39 |
\addbibresource{tikzfxgraph.bib} |
| 40 |
|
| 41 |
\usepackage{tikz} |
| 42 |
\usetikzlibrary{matrix} |
| 43 |
\usepackage{pgfplots} |
| 44 |
\pgfplotsset{compat=1.18} |
| 45 |
\usetikzlibrary{pgfplots.units} |
| 46 |
|
| 47 |
\usepackage[no domain warning, use file]{tikzfxgraph} |
| 48 |
|
| 49 |
|
| 50 |
\RequirePackage[hidelinks,hypertexnames=false]{hyperref} |
| 51 |
|
| 52 |
\begin{document} |
| 53 |
\tstitle{ |
| 54 |
author={Alceu Frigeri\footnote{\tsverb{https://github.com/alceu-frigeri/tikzfxgraph}}}, |
| 55 |
date={\tsdate}, |
| 56 |
title={The tikzfxgraph Package\break simplified $f_i(x)$ graphics\break Version \PkgInfo{tikzfxgraph}{version}} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
\begin{typesetabstract} |
| 61 |
|
| 62 |
|
| 63 |
This package offers a set of streamlined commands to draw algebraic functions, atop of \tsobj[pkg]{pgfplots,gnuplot}. Some auxiliary commands are also defined allowing to create \emph{sets of functions} and \emph{user defined styles}. |
| 64 |
\end{typesetabstract} |
| 65 |
|
| 66 |
\tableofcontents |
| 67 |
|
| 68 |
\section{Introduction} |
| 69 |
|
| 70 |
The \tsobj[pkg]{pgfplots}\cite{PGFPLOTS:1.18} package together with \tsobj[pkg]{gnuplot}\cite{gnuplot:5.4} is extremely flexible, allowing the construction of very intricate graphics, but said flexibility comes at a cost: the sheer number of parameters to be set. |
| 71 |
This package is nothing more than a wrap around \tsobj[pkg]{pgfplots,gnuplot} offering a somewhat simplified interface. |
| 72 |
|
| 73 |
A command (\tsobj{\fxgraphdraw}) and an environment (\tsobj[env]{fxgraph}) are provided for drawing one or more $f_i(x)$ curves, as well some auxiliary commands (\tsobj{\fxsetnew,\fxsetappend}) to define sets of functions and one for user defined styles (\tsobj{\fxsetnewstyle}). |
| 74 |
|
| 75 |
|
| 76 |
\section{Requirements} |
| 77 |
|
| 78 |
One needs to load at least two packages: \tsobj{tikz,pgfplots} (it is advisable to set the \tsobj[pkg]{pgfplots} compatibility to, at least, 1.18 (\tsverb{\pgfplotsset{compat=1.18}}). Like |
| 79 |
\begin{codestore}[demo-pre] |
| 80 |
\usepackage{tikz} |
| 81 |
\usepackage{pgfplots} |
| 82 |
\pgfplotsset{compat=1.18} |
| 83 |
|
| 84 |
\usetikzlibrary{pgfplots.units} %this is optional |
| 85 |
\end{codestore} |
| 86 |
\tscode*{demo-pre} |
| 87 |
|
| 88 |
|
| 89 |
Besides that, \tsobj[pkg]{gnuplot} must be installed/present. |
| 90 |
|
| 91 |
\begin{tsremark} |
| 92 |
to be able to call \tsobj[pkg]{gnuplot} you will need to use the \tsobj[key]{--enable-write18} (or \tsobj[key]{--shell-scape}) option in your \LaTeX{} run. Keep in mind that \tsobj[pkg]{gnuplot} will create a set of files that can be used from one run to another, and, unless you change the domain/functions, \tsobj[key]{--enable-write18} (or \tsobj[key]{--shell-scape}) can be kept disable otherwise. |
| 93 |
\end{tsremark} |
| 94 |
|
| 95 |
\begin{tsremark}[\color{red}Warning:] |
| 96 |
As of now, there is a bug on version 6.0.*, under windows, of \tsobj[pkg]{gnuplot}. It will work, but a series of errors messages will be raised (invalid characters) that's due one of the returning files being written in UTF16 instead of UTF8. |
| 97 |
So, for now, use at most version 5.4.* |
| 98 |
\url{https://sourceforge.net/p/gnuplot/bugs/2747/} |
| 99 |
\end{tsremark} |
| 100 |
|
| 101 |
\section{Package Options} |
| 102 |
|
| 103 |
\begin{describelist}{option}\label{pack-options} |
| 104 |
\describe{samples default}{(default: 2000) Globally sets the default number of samples to be calculated. This can be overwritten per function definition (see \ref{function-set}).} |
| 105 |
\describe{no domain warning}{(default: false) Given the many ways by which a function domain can be defined, in some cases this package will issue a warning if the domain wasn't explicitly defined (see \ref{fx-draw}), which might be (or not) an error. This option suppresses those warnings.} |
| 106 |
\describe{use file}{(default: false) This will globally set \tsobj[key]{use file} for every \tsobj{\fxgraphdraw} or \tsobj[env]{fxgraph} environment. The same conditions (per function) and warnings apply: The corresponding table files must exist but they won't be verified if they are up-to-date. With this global option set, one can selectively reverse it per \tsobj{\fxgraphdraw} or \tsobj[env]{fxgraph} environment, by using \tsobj[option]{use file=false} with them.} |
| 107 |
\end{describelist} |
| 108 |
If each and every function used has a corresponding \emph{distinct} \tsobj[option]{id}, the option \tsobj[option]{use file} can be used to share the \LaTeXe{} document with someone who doesn't have \tsobj[pkg]{gnuplot} installed (or doesn't want to enable \tsobj[key,sep=or]{--enable-write18,--shell-scape}). |
| 109 |
|
| 110 |
\section{Commands} |
| 111 |
|
| 112 |
\subsection{Defining Functions' sets}\label{function-set} |
| 113 |
|
| 114 |
\begin{codedescribe}{\fxsetnew} |
| 115 |
\begin{codesyntax}% |
| 116 |
\tsmacro{\fxsetnew}{new-fxset} |
| 117 |
\end{codesyntax} |
| 118 |
This defines/create a \tsobj[marg]{fxset} for later reference. A \tsobj[marg]{fxset} is just a ''repository'' of functions descriptions/specifications. |
| 119 |
\end{codedescribe} |
| 120 |
|
| 121 |
\begin{tsremark} |
| 122 |
About dataset's names: It can be almost anything, the name can contain strings normally not allowed in a macro name, like spaces, dots, two-dots and so on, including backslashes, meaning that if someone typesets \tsobj{\XYZ} as a dataset, \tsobj{\XYZ} will be it's name: a backslash isn't an active character anymore and one can't use macros when defining a fxset's name. |
| 123 |
\end{tsremark} |
| 124 |
|
| 125 |
|
| 126 |
\begin{codedescribe}{\fxsetappend} |
| 127 |
\begin{codesyntax}% |
| 128 |
\tsmacro{\fxsetappend}{fxset,keyval-list} |
| 129 |
\end{codesyntax} |
| 130 |
Adds a function description to a given fxset. |
| 131 |
\end{codedescribe} |
| 132 |
|
| 133 |
Valid Keys when describing a function: |
| 134 |
\begin{describelist*}{key} |
| 135 |
\describe{fx}{The function itself. It can be any \tsobj[pkg]{gnuplot} valid expression, in terms of $x$.} |
| 136 |
\describe{id}{(optional) An unique identifier. A set of auxiliary files are created by \tsobj[pkg]{gnuplot} using this as a name suffix. As per the \tsobj[pkg]{pgfplot} manual, they are used to determined if there is the need to re-run \tsobj[pkg]{gnuplot}. } |
| 137 |
\describe{legend}{(optional) The name of the function, to appears as a Legend.} |
| 138 |
\describe{samples}{(default: 2000) The default value can be changed by the package option \tsobj[option]{samples default}) Set the number of points to be calculated.} |
| 139 |
\describe{use file}{(optional) If \tsobj[key]{id} is defined, and the corresponding table file exists (\tsobj{\jobname . <id> . table}), then the table file will be used instead of calling gnuplot. {\color{red}Warning:} It won't check if the table file is correct/up to date! This is, mainly, a work around for some cases in which \tsobj[pkg]{pgf/pgfplot} fails to recognize that `nothing has changed' and needless call \tsobj[pkg]{gnuplot}. This setting has precedence over the corresponding global/environment setting.} |
| 140 |
\end{describelist*} |
| 141 |
\begin{tsremark} |
| 142 |
An error is raised if \tsobj[marg]{fxset} isn't defined. |
| 143 |
\end{tsremark} |
| 144 |
\begin{tsremark} |
| 145 |
Either set a legend for each and every function, or to none of them. Mixing styles (some with a legend, some without, will result in functions being wrongfully labelled). |
| 146 |
\end{tsremark} |
| 147 |
Besides those, any other \tsobj[pkg]{pgfplots} valid key can be used. (e.g. red , thick : the specific curve will be in red, using a thick line). |
| 148 |
For example: |
| 149 |
\begin{codestore}[fxset-01] |
| 150 |
\fxsetnew{set-A} %creating a new 'set' |
| 151 |
|
| 152 |
\fxsetappend{set-A}{ |
| 153 |
id=f-A0 , |
| 154 |
fx=x^2-x+2 , |
| 155 |
thick %this key comes from tikz/pgf |
| 156 |
} |
| 157 |
\fxsetappend{set-A}{ |
| 158 |
id=f-A1 , |
| 159 |
fx=x^2+x+3 , |
| 160 |
red %this key comes from tikz/pgf |
| 161 |
} |
| 162 |
\end{codestore} |
| 163 |
\tscode*[ |
| 164 |
codeprefix={} , |
| 165 |
texcs2={fxsetnew,fxsetappend,fxsetnewstyle,fxgraphdraw,fxgraph} , |
| 166 |
emph={id,fx,legend,set} , |
| 167 |
emph={linear,loglog,semilog,ticks,function} , |
| 168 |
emph3={min,max,N,delta,units} , |
| 169 |
]{fxset-01} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
\subsection{User Defined Styles}\label{style-def} |
| 174 |
|
| 175 |
\begin{codedescribe}{\fxsetnewstyle} |
| 176 |
\begin{codesyntax}% |
| 177 |
\tsmacro{\fxsetnewstyle}{style-name,keyval-list} |
| 178 |
\end{codesyntax} |
| 179 |
Defines a new \tsobj[pkg]{pgfplot} style key. Which can be later used when drawing $f_i(x)$ function graphs (can be used, for instance, to assure all graphs follow the same style). |
| 180 |
\end{codedescribe} |
| 181 |
|
| 182 |
|
| 183 |
Valid Keys when describing a function: |
| 184 |
\begin{describelist*}{option} |
| 185 |
\describe{linear}{Both $x$ and $y$ axis are linear.} |
| 186 |
\describe{loglog}{Both $x$ and $y$ axis are logarithmic.} |
| 187 |
\describe{semilog x}{The $x$ axis is logarithmic, the $y$ is linear.} |
| 188 |
\describe{semilog y}{The $y$ axis is logarithmic, the $x$ is linear.} |
| 189 |
\describe{x ticks}{Describes the minor ticks to be drawn in the $x$ axis. See below.} |
| 190 |
\describe{y ticks}{Describes the minor ticks to be drawn in the $y$ axis. See below.} |
| 191 |
\end{describelist*} |
| 192 |
|
| 193 |
Besides those, any other \tsobj[pkg]{pgfplots} valid key can be used. (e.g. red , thick : the specific style will set the lines to be red and thick). |
| 194 |
|
| 195 |
|
| 196 |
Note that the keys \tsobj[key]{x ticks, y ticks} are themselves defined by a set of keyval values, as follow: |
| 197 |
\begin{describelist*}{option} |
| 198 |
\describe{min}{The minimal value (starting value) of the corresponding axis.} |
| 199 |
\describe{max}{It`s maximum value.} |
| 200 |
\describe{delta}{(optional) the $delta$ to be used between \emph{ticks}. Note that, it depends on the kind of the axis. In case of a linear axis, this is just the delta between ticks. If logarithmic, it is the geometric distantce between ticks.} |
| 201 |
\describe{N}{(optional) Sets de number of ticks to be calculated. In case of a linear axis it will set the linear distance to $({max - min})/{N}$. In case of a logarithmic axis it will set the geometric distance to $(\ln(max) - \ln(min))/{N}$. \tsobj[key]{N} has precedence over \tsobj[key]{delta}.} |
| 202 |
\describe{units}{(optional) The units of the corresponding axis.} |
| 203 |
\end{describelist*} |
| 204 |
|
| 205 |
|
| 206 |
The following example will define a style ``my style A'', to be used in a ``semilog x'' graph. The $x$ domain will go from $0.001$ up to $100$ with ticks at $0.001 ,\, 0.01 ,\, 0.1 ,\, 1.0 ,\, 10 \,\textrm{and}\, 100$. Conversely, the $y$ domain will go from $-\pi$ up to $+\pi$, with linearly spaced ticks. The ticks will be inside the graph. |
| 207 |
\begin{codestore}[fxset-02] |
| 208 |
\fxsetnewstyle{my style A}{ |
| 209 |
semilog x , |
| 210 |
x ticks = { |
| 211 |
min = 0.001 , |
| 212 |
max = 100 , |
| 213 |
N = 6 , |
| 214 |
units = rad/s , |
| 215 |
} , |
| 216 |
y ticks = { |
| 217 |
min = -3.14159265 , |
| 218 |
max = 3.14159265 , |
| 219 |
N = 8 , |
| 220 |
units = rad , |
| 221 |
} , |
| 222 |
% the following key comes from pgfplot |
| 223 |
tick align=inside , %this package's default is outside. |
| 224 |
} |
| 225 |
\end{codestore} |
| 226 |
\tscode*[ |
| 227 |
codeprefix={} , |
| 228 |
codeprefix={} , |
| 229 |
texcs2={fxsetnew,fxsetappend,fxsetnewstyle,fxgraphdraw,fxgraph} , |
| 230 |
emph={id,fx,legend,set} , |
| 231 |
emph={linear,loglog,semilog,ticks,function} , |
| 232 |
emph3={min,max,N,delta,units} , |
| 233 |
]{fxset-02} |
| 234 |
|
| 235 |
\begin{tsremark} |
| 236 |
The \tsobj[key]{linear,loglog, semilog x, semilog y} keys are only used here for setting the ticks (linear or logarithmic). If none is given, it is assumed that both $x$ and $y$ axis are linear. |
| 237 |
\end{tsremark} |
| 238 |
\begin{tsremark} |
| 239 |
If either \tsobj[key,sep=or]{min,max} are missing, no tick list will be generated. |
| 240 |
\end{tsremark} |
| 241 |
|
| 242 |
\begin{tsremark} |
| 243 |
In case of a logarithmic axis, both \tsobj[key]{min,max} must greater than zero, otherwise an error will be raised. |
| 244 |
\end{tsremark} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
\subsection{Drawing a $f_i(x)$ Graph}\label{fx-draw} |
| 249 |
There is a single drawing command \tsobj{\fxgraphdraw} and a companion environment \tsobj[env]{fxgraph}, both share the same interface. The graph will be constructed as follow: \begin{enumerate*} |
| 250 |
\item An outer \tsobj[env]{tikzpicture} environment |
| 251 |
\item An inner \tsobj[env]{axis} environment |
| 252 |
\item The function's graphs themself |
| 253 |
\item (in case of the \tsobj[env]{fxgraph} environment) futher \tsobj[pkg]{pgfplot} commands. |
| 254 |
\end{enumerate*} |
| 255 |
The \tsobj[env]{axis} environment will first be ''styled'' (as per \tsobj[key,sep=or]{linear,loglog,semilog x, semilog y}, see \ref{style-default}) then the \tsobj[key]{ticks}, if defined, will be applied, lastly any further \tsobj[pkg]{pgfplot} key used when calling those commands. |
| 256 |
\begin{tsremark} |
| 257 |
Given the above construct, generic \tsobj[pkg]{pgfplot} keys used will always have a precedence over the default styles, regardless of they order of appearance. |
| 258 |
\end{tsremark} |
| 259 |
|
| 260 |
\begin{codedescribe}{\fxgraphdraw} |
| 261 |
\begin{codesyntax}% |
| 262 |
\tsmacro{\fxgraphdraw}{keyval-list} |
| 263 |
\end{codesyntax} |
| 264 |
Creates a graph, and draw one or more functions/sets of functions as describer by \tsobj[marg]{keval-list} (see below). |
| 265 |
\end{codedescribe} |
| 266 |
|
| 267 |
\begin{codedescribe}[env]{fxgraph} |
| 268 |
\begin{codesyntax}% |
| 269 |
\tsmacro{\begin{fxgraph}}{keyval-list} |
| 270 |
\tsobj[oarg]{further commands} |
| 271 |
\tsmacro{\end{fxgraph}}{} |
| 272 |
\end{codesyntax} |
| 273 |
Same as \tsobj{\fxgraphdraw}, allowing to add further \tsobj[pkg]{pgfplot,tikz} commands. |
| 274 |
\end{codedescribe} |
| 275 |
|
| 276 |
Valid Keys when describing a graph: |
| 277 |
\begin{describelist*}{option} |
| 278 |
\describe{linear}{Both $x$ and $y$ axis are linear.} |
| 279 |
\describe{loglog}{Both $x$ and $y$ axis are logarithmic.} |
| 280 |
\describe{semilog x}{The $x$ axis is logarithmic, the $y$ is linear.} |
| 281 |
\describe{semilog y}{The $y$ axis is logarithmic, the $x$ is linear.} |
| 282 |
|
| 283 |
\describe{x ticks}{Describes the minor ticks to be drawn in the $x$ axis. See below.} |
| 284 |
\describe{y ticks}{Describes the minor ticks to be drawn in the $y$ axis. See below.} |
| 285 |
|
| 286 |
\describe{sans tikzpicture}{Suppress the outer \tsobj[env]{tikpicture} environment.} |
| 287 |
\describe{without tikzpicture}{Suppress the outer \tsobj[env]{tikpicture} environment.} |
| 288 |
|
| 289 |
\describe{function}{Adds a function specification, see \ref{function-set}.} |
| 290 |
\describe{fx set}{A comma separated list of \tsobj[key]{fxsets}.} |
| 291 |
\describe{use file}{(optional) This is equivalent of setting \tsobj[key]{use file} for every function to be drawn in this group, as in \ref{function-set}, the same conditions and warnings apply: The corresponding table files must exist but they won't be verified if they are up-to-date.} |
| 292 |
\end{describelist*} |
| 293 |
|
| 294 |
Besides those, any other \tsobj[pkg]{pgfplots} valid key can be used. (e.g. red , thick : the specific style will set the lines to be red and thick). |
| 295 |
|
| 296 |
The \tsobj[key]{x ticks,y ticks} are set the same way as in \ref{style-def} (\tsobj[key]{x tick}=\tsobj[marg]{keyval-list}). |
| 297 |
|
| 298 |
The \tsobj[key]{function} key defines (as in \ref{function-set}) a function to be draw, it can be used multiple times. Note that those functions will be drawn before any \tsobj[key]{fx set}. |
| 299 |
%\fxgraphdraw{semilog x={red},x ticks={min=0.1,max=1000,N=8},y ticks={min=1,max=100,N=10},function={{fX,red,x^2+3}}} |
| 300 |
|
| 301 |
\tsobj[key]{fx set} is a comma separated list of \tsobj[marg]{fxset} (as defined in \ref{function-set}). All functions $f_i(x)$ associated with each \tsobj[marg]{fxset} will be drawn. |
| 302 |
|
| 303 |
Normally, the \tsobj{\fxgraphdraw} command (viz-à-viz \tsobj[env]{fxgraph} environment) will insert an axis environment inside a \tsobj[env]{tizpicture} environment. The \tsobj[key]{sans tikzpicture,without tikzpicture} keys will suppress that external \tsobj[env]{tikzpicture} environment. |
| 304 |
|
| 305 |
\begin{tsremark} |
| 306 |
The \tsobj[env]{fxgraph} environment (as well the \tsobj{\fxgraphdraw} command) usually extracts the many function's domain from \tsobj[key]{x ticks}, if present. Though, the domain can be set by other means (e.g. via \tsobj{\fxsetnewstyle} or directly via \tsobj[pkg]{pgfplots} keys), a warning will be raised if \tsobj[key]{x ticks} isn't explicitly set. This warning can be suppressed with the package option: \tsobj[option]{no domain warning}, see \ref{pack-options}. |
| 307 |
\end{tsremark} |
| 308 |
\begin{tsremark} |
| 309 |
If the package option \tsobj[option]{use file} (see \ref{pack-options}) is set, the local command/environment option \tsobj[option]{use file=false} can be used to locally revert it's effect. Note though, the function definition (see \ref{function-set} has precedence over them). |
| 310 |
\end{tsremark} |
| 311 |
|
| 312 |
\section{Style's Default}\label{style-default} |
| 313 |
|
| 314 |
For each kind of graph (linear, loglog, semilog) there is a corresponding predefined style: |
| 315 |
%123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 |
| 316 |
\begin{describelist*}{key} |
| 317 |
\describe{linear axis}{This is the ``base'' style. Both axis will be gridded (lines at the corresponding ticks), with an axis line at the bottom |
| 318 |
(for $x$) and the left (for $y$). Ticks marks will be outside the graph. The legend (if present) will be at the top right of the graph. The $f_i(x)$ curves will be styled according to two lists: \tsobj[key]{fxgraph color list, fxgraph line list} (see below). The graph width is set to 80\% of \tsobj{\textwidth} and it's height to 35\% of \tsobj{\textwidth}.} |
| 319 |
\describe{loglog axis}{It applies the current \tsobj[key]{linear axis} style and the log basis is set to 10.} |
| 320 |
\describe{semilog x axis}{It applies the current \tsobj[key]{linear axis} style and the log basis is set to 10.} |
| 321 |
\describe{semilog y axis}{It applies the current \tsobj[key]{linear axis} style and the log basis is set to 10.} |
| 322 |
\end{describelist*} |
| 323 |
|
| 324 |
Those styles can be modified with \tsobj[code,sep=or]{\pgfplotsset,\pgfkeys} (using \tsobj[key]{.style append} sub-key, for instance. See \cite{TIKZPGF:3.1} and \cite{PGFPLOTS:1.18}). If using the \tsobj{\pgfkeys} remember to switch first to the \tsobj[key]{pgfplots} `family'. |
| 325 |
|
| 326 |
When styling a set of functions, two lists are used (\tsobj[key]{cycle multiindex* list} from \tsobj[pkg]{pgfplots}): |
| 327 |
|
| 328 |
\begin{describelist*}{key} |
| 329 |
\describe{fxgraph color list}{Function's color will cycle through \tsobj[key]{red!80!black, |
| 330 |
green!80!black, |
| 331 |
blue!80!black, |
| 332 |
black, |
| 333 |
brown!70!black, |
| 334 |
teal!80!black, |
| 335 |
orange!80!black, |
| 336 |
violet!80!black, |
| 337 |
cyan!80!black, |
| 338 |
magenta!80!black, |
| 339 |
yellow!75!black, |
| 340 |
black!60!white}. } |
| 341 |
\describe{fxgraph line list}{Function's line style will cycle through \tsobj[key]{ solid, |
| 342 |
solid, |
| 343 |
solid, |
| 344 |
dashed, |
| 345 |
dashed, |
| 346 |
dashed, |
| 347 |
dashdotdotted, |
| 348 |
dashdotdotted, |
| 349 |
dashdotdotted}.} |
| 350 |
\end{describelist*} |
| 351 |
|
| 352 |
Both can be redefined with \tsobj{\pgfplotscreateplotcyclelist} from \tsobj[pkg]{pgfplots}\cite{PGFPLOTS:1.18}. |
| 353 |
|
| 354 |
|
| 355 |
\newpage |
| 356 |
|
| 357 |
\section{Examples}\label{Examples} |
| 358 |
|
| 359 |
\subsection{Drawing a Bode Diagram} |
| 360 |
% |
| 361 |
\begin{codestore}[fxset-03] |
| 362 |
\fxsetnewstyle{db style}{ |
| 363 |
semilog x , |
| 364 |
y ticks = { min = -20 , max = 80 , N = 5 , units = db } , |
| 365 |
} |
| 366 |
|
| 367 |
\fxsetnewstyle{phi style}{ |
| 368 |
semilog x , |
| 369 |
y ticks = { min = -3.14159265 , max = 3.14159265 , N = 8 , units = rad } , |
| 370 |
} |
| 371 |
|
| 372 |
\fxsetnewstyle{freq range A}{ |
| 373 |
semilog x , |
| 374 |
x ticks = { min = 0.01 , max = 100000 , N = 7 , units = rad/s } , |
| 375 |
} |
| 376 |
% |
| 377 |
%%% This is optional, just defining an auxiliary macro with f(x) core expression |
| 378 |
%%% Note that this is a valid gnuplot's expression (not LaTeX/TeX/...) |
| 379 |
\def\Hs{(x*{0,1}+1)*(x*{0,1}+40000)/((-x^2+0.01*2*400*x*{0,1}+400^2))} |
| 380 |
|
| 381 |
~\hfill |
| 382 |
\fxgraphdraw{ |
| 383 |
semilog x , |
| 384 |
db style , |
| 385 |
freq range A , |
| 386 |
function={fx=20*log10(abs(\Hs))} |
| 387 |
} |
| 388 |
|
| 389 |
~\hfill |
| 390 |
\fxgraphdraw{ |
| 391 |
semilog x , |
| 392 |
phi style , |
| 393 |
freq range A , |
| 394 |
function={fx={atan2( imag(\Hs) , real(\Hs) )}} |
| 395 |
} |
| 396 |
\end{codestore} |
| 397 |
\tsdemo*[ |
| 398 |
codeprefix={} , |
| 399 |
resultprefix={} , |
| 400 |
texcs2={fxsetnew,fxsetappend,fxsetnewstyle,fxgraphdraw,fxgraph} , |
| 401 |
emph={id,fx,legend,set} , |
| 402 |
emph={linear,loglog,semilog,ticks,function} , |
| 403 |
emph3={min,max,N,delta,units} , |
| 404 |
]{fxset-03} |
| 405 |
|
| 406 |
|
| 407 |
\subsection{A Few Curves at Once} |
| 408 |
In the example below note that the \tsobj[key]{fx set} functions are drawn after the `Dx'. And that defines the legend order. |
| 409 |
\begin{codestore}[fxset-04] |
| 410 |
\fxsetnew{set-B} |
| 411 |
\fxsetappend{set-B}{id=B0,fx=2*cos(x)+1,legend=B0} |
| 412 |
\fxsetappend{set-B}{id=B1,fx=2*sin(2*x)-1,legend=B1,thick} |
| 413 |
%the thick (line) keyword comes from tikz |
| 414 |
\fxsetnew{set-C} |
| 415 |
\fxsetappend{set-C}{id=C0,fx=1.5*cos(x+2)+1,legend=C0} |
| 416 |
\fxsetappend{set-C}{id=C1,fx=2*sin(x-2)-1,legend=C1} |
| 417 |
|
| 418 |
\fxgraphdraw{ |
| 419 |
linear , |
| 420 |
y ticks = {min = -3 , max = 3 , N = 6} , |
| 421 |
x ticks = {min = 0 , max = 3*3.14159265 , N = 6 , units = rad} , |
| 422 |
fx set = {set-B , set-C} , |
| 423 |
function = {id=Dx,fx=x-2,legend=Dx} , |
| 424 |
xlabel = some radians , % from pgfplots |
| 425 |
ylabel = This y , % from pgfplots |
| 426 |
title = Graph A % from pgfplots |
| 427 |
} |
| 428 |
|
| 429 |
\fxgraphdraw{ |
| 430 |
linear , |
| 431 |
y ticks = {min = -3 , max = 3 , N = 6} , |
| 432 |
x ticks = {min = 0 , max = 3*3.14159265 , N = 6 , units = rad} , |
| 433 |
fx set = {set-C} , |
| 434 |
xlabel = some more , % from pgfplots |
| 435 |
ylabel = This y , % from pgfplots |
| 436 |
title = Graph B % from pgfplots |
| 437 |
} |
| 438 |
|
| 439 |
\end{codestore} |
| 440 |
\tsdemo*[ |
| 441 |
codeprefix={} , |
| 442 |
resultprefix={} , |
| 443 |
texcs2={fxsetnew,fxsetappend,fxsetnewstyle,fxgraphdraw,fxgraph} , |
| 444 |
emph={id,fx,legend,set} , |
| 445 |
emph={linear,loglog,semilog,ticks,function} , |
| 446 |
emph3={min,max,N,delta,units} , |
| 447 |
]{fxset-04} |
| 448 |
|
| 449 |
\newpage |
| 450 |
\subsection{Further Customization} |
| 451 |
There are many ways, for instance, to have side by side graphs. One could use, for example, a \tsobj[env]{tabular} environment. In the following the \tsobj[pkg]{tikz} library \tsobj[pkg]{matrix} will be used, in which case the option \tsobj[key]{sans tikzpicture} is needed (besides a custom width and height for each graph). Note: Since \tsobj[pkg]{tikz} matrixes cannot be nested, and \tsobj[pkg]{pgfplots} legends are created as a \tsobj[pkg]{tikz} matrix, one can't have a legend in this case. |
| 452 |
|
| 453 |
\begin{codestore}[fxset-05] |
| 454 |
\fxsetnew{set-D} |
| 455 |
\fxsetappend{set-D}{id=B0,fx=2*cos(x)+1} |
| 456 |
\fxsetappend{set-D}{id=B1,fx=2*sin(2*x)-1,thick} |
| 457 |
%the thick (line) keyword comes from tikz |
| 458 |
\fxsetnew{set-E} |
| 459 |
\fxsetappend{set-E}{id=C0,fx=1.5*cos(x+2)+1} |
| 460 |
\fxsetappend{set-E}{id=C1,fx=2*sin(x-2)-1} |
| 461 |
|
| 462 |
\begin{tikzpicture} |
| 463 |
\matrix{ |
| 464 |
\fxgraphdraw{ |
| 465 |
linear , |
| 466 |
y ticks = {min = -3 , max = 3 , N = 6} , |
| 467 |
x ticks = {min = 0 , max = 3*3.14159265 , N = 6} , |
| 468 |
fx set = {set-D} , |
| 469 |
function = {id=Fx,fx=x-2} , |
| 470 |
sans tikzpicture , |
| 471 |
width=0.47\textwidth, % from pgfplots |
| 472 |
height=0.30\textwidth , % from pgfplots |
| 473 |
} & |
| 474 |
\fxgraphdraw{ |
| 475 |
linear , |
| 476 |
y ticks = {min = -3 , max = 3 , N = 6} , |
| 477 |
x ticks = {min = 0 , max = 3*3.14159265 , N = 6} , |
| 478 |
fx set = {set-E} , |
| 479 |
function = {id=Gx,fx=x-2} , |
| 480 |
sans tikzpicture , |
| 481 |
width=0.47\textwidth, % from pgfplots |
| 482 |
height=0.30\textwidth , % from pgfplots |
| 483 |
} \\ |
| 484 |
}; |
| 485 |
\end{tikzpicture} |
| 486 |
|
| 487 |
\end{codestore} |
| 488 |
\tscode*[ |
| 489 |
codeprefix={} , |
| 490 |
resultprefix={} , |
| 491 |
texcs2={fxsetnew,fxsetappend,fxsetnewstyle,fxgraphdraw,fxgraph} , |
| 492 |
emph={id,fx,legend,set} , |
| 493 |
emph={linear,loglog,semilog,ticks,function} , |
| 494 |
emph3={min,max,N,delta,units} , |
| 495 |
]{fxset-05} |
| 496 |
|
| 497 |
\tsresult*[ |
| 498 |
codeprefix={} , |
| 499 |
resultprefix={} , |
| 500 |
texcs2={fxsetnew,fxsetappend,fxsetnewstyle,fxgraphdraw,fxgraph} , |
| 501 |
emph={id,fx,legend,set} , |
| 502 |
emph={linear,loglog,semilog,ticks,function} , |
| 503 |
emph3={min,max,N,delta,units} , |
| 504 |
]{fxset-05} |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
\printbibliography |
| 509 |
|
| 510 |
\end{document} |