Showing posts with label LaTeX. Show all posts
Showing posts with label LaTeX. Show all posts

12 November 2015

Adaptive mark in PGFplots

It often happens that we want to draw some graphs with few traces that have sharp resonances/sharp peaks, etc. As illustrated in the below figure, flat parts of the curve get a lot of markers, while sharp parts get only few markers, if any. An illustration of the problem is in the figure below:

Too many markers in the slow area, and only few markers in the sharp area
 Matlab users often have this problem (I had this issue very often when I used it to draw graphics). This issue can be avoided in graphs drawn by pdfLaTeX and PGFplots by the following trick.

\makeatletter
\tikzset{
 nomorepostactions/.code={\let\tikz@postactions=\pgfutil@empty},
 mymark/.style 2 args={decoration={markings,
   mark= between positions 0 and 1 step (1/20)*\pgfdecoratedpathlength with{%
    \tikzset{#2,every mark}\tikz@options
    \pgfuseplotmark{#1}%
   },
  },
  postaction={decorate},
  /pgfplots/legend image post style={
   mark=#1,#2,every path/.append style={nomorepostactions}
  },
 },
}
\makeatother

Here,  we define a custom TIKZ style, and specify the maximum distance between adjacent points.
Sharp traces with equally spaced markers
This post is based on this answer from StackExchange.com. For additional info about this please see here.
A complete working example is as follows:


1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
\documentclass[]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{decorations.markings}
\makeatletter
\tikzset{
 nomorepostactions/.code={\let\tikz@postactions=\pgfutil@empty},
 mymark/.style 2 args={decoration={markings,
   mark= between positions 0 and 1 step (1/20)*\pgfdecoratedpathlength with{%
    \tikzset{#2,every mark}\tikz@options
    \pgfuseplotmark{#1}%
   },
  },
  postaction={decorate},
  /pgfplots/legend image post style={
   mark=#1,#2,every path/.append style={nomorepostactions}
  },
 },
}
\makeatother

\begin{document}
 \begin{tikzpicture}
 \begin{axis}[axis x line=middle, axis y line=left, xmax=2.5, xlabel=$x$, ylabel=$y$, ymin=-0.15]
 
 \addplot[blue, domain=0:3,samples=150,mymark={*}{dotted}]
 {exp(-400*(x-1)^2)};
 
 \addplot[red, domain=0:3,samples=150,mymark={*}{dotted}]
 {exp(-400*(x-1.5)^2)};
 \end{axis}
 \end{tikzpicture}
\end{document}

18 May 2015

A template for supplementary material in IEEEtran format

A template for supplementary material of the manuscripts in IEEE format (IEEEtran.cls) is not wrapped up for the IEEEtran. For my latest manuscript (which is still under review), I needed to put some graphs in the supplementary, so I could gather these hacks from the web. I gathered  all these HACKS couple of months ago, from different blogs, and sites for supplementary files of other journals. I could not find those blogs, so sorry for not providing reference.

I liked to change the section, figure, table, equation, citation numbering to include an additional S.  The following should be inserted into preamble.


1
2
3
% Hack For section headers starting with S
\renewcommand{\thesection}{S.\Roman{section}}
\renewcommand{\thesubsection}{\thesection.\Alph{subsection}}

To change the format of citations in the bibliography and the main text, a combination of natbib and IEEEtranN is needed
1
2
3
4
5
6
% Hack for citation command 
% use bibnumfmt to change style at the end of the document
\usepackage[numbers]{natbib}
\renewcommand{\bibnumfmt}[1]{[S#1]}
% citenumfont command adds S to all numbers
\renewcommand{\citenumfont}[1]{\textit{S#1}}

Numbering of the figures and table are done with
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
% Hack for making figures Say \figurename S\thefigure, e.g. Figure S1:
\makeatletter
\makeatletter \renewcommand{\fnum@figure}
{\figurename~S\thefigure}
\makeatother
 
% Hack for making figures Say \figurename S\thefigure, e.g. Figure S1:
\makeatletter
\makeatletter \renewcommand{\fnum@table}
{\tablename~S\thetable}
\makeatother
And for the equations, we need the following
1
2
3
% Hack for making SOM Equations Conform to Science Format
% e.g. (S1), (S2), etc
\renewcommand{\theequation}{S\arabic{equation}}
A drawback of this method is that \eqref is not working, but \ref command still works pretty good. :)

I also find it handy to cross-reference labels between main and supplementary document. In the supplementary, we need to reference to the aux file of the main file, like:
1
2
\usepackage{xr}
\externaldocument{Main}% Main.tex is the main file of the manuscript.

A sample output is shown below: