I'm working on converting matlab files to TiKz, and I wanted to do it as cute as possible…
Can anybody help me to find a good and complete tutorial for "pgfplots" ?
[Tex/LaTex] ny good and complete tutorial for pgfplots
pgfplotstutorials
Related Solutions
Today LaTeX is more than just its core. I don't want to go without amsmath, inputenc, fontenc, babel, microtype, hyperref, natbib, graphicx and many more.
To learn just about the LaTeX kernel, Lamports book is not bad, it's good to read what the author said. It's his reference manual. Reading source2e.pdf provides further insights.
But the LaTeX Companion is really something you could keep under your pillow. It gives deep insights but also an overview to important packages for various subjects. For me it's the LaTeX encyclopedia, because it goes beyond the LaTeX kernel. The companion could be a good foundation and roadmap. I recommend it to you, because I think you prefer a good recommendation over just hearing there's none.
Current LaTeX distributions install a huge amount of documentation, you could access it by texdoc
at the command prompt. For instance:
texdoc source2e
for the commented LaTeX source,texdoc clsguide
for LaTeX2e for class and package writers,texdoc koma
to get the KOMA-Script classes guide
and documentation to many hundred packages and classes, from small to big. What a book cannot provide, texdoc does for me.
I've used PGFplots to generate some maps of a local area in the past, doing watershed calculations in GRASS and exporting the vectors as ASCII files, which can be plotted by PGFplots relatively easily. That only required an xy coordinate system (spatial extent of about 100 km by 100 km), and distortions were negligible.
As you noted, on a (near) global scale, things become more complicated, and plate caree is by far the easiest thing to start with.
Here's a very basic attempt to get started (I've been meaning to look into this for a while):
World map in equidistant rectangular (Plate Caree) projection, with Tissot's Indicatrix in blue, and the Bermuda Triangle shown in orange
The world map is part of the Gnuplot data: world.dat
By setting disabledatascaling
in PGFplots, you can use normal coordinates instead of axis cs
coordinates, and the scaling factors to convert between canvas coordinates and data coordinates will be available in \pgfplotunitxlength
and \pgfplotsunitylength
.
axis equal
makes sure that the x and y unit lengths are the same.
I've written a key called scale circle
, which you can add to the options of a \draw circle
. The key will scale the x radius according to the latitude.
What this approach doesn't do is curve lines that don't follow longitudes or latitudes. I'm not sure what the best approach for this is, I'm guessing some to path
magic (Andrew Stacey?), or an \addplot
expression. I'll have a think about this.
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\makeatletter
\pgfmathsetmacro\kmAtEquator{36/4200} % Degree/km at equator
\tikzset{
scale circle/.code={
\pgfgetlastxy{\x@coord}{\y@coord}
\pgfmathsetmacro\xscale{\pgfkeysvalueof{/tikz/x radius}*1/cos(\y@coord/\pgfplotsunitylength)}
\tikzset{/tikz/x radius=\xscale}
},
scale bar/.code={
\pgfgetlastxy{\x@coord}{\y@coord}
\pgfmathsetmacro\xscale{1/cos(\y@coord/\pgfplotsunitylength)}
\tikzset{
insert path={
node [
below,
font=\scriptsize
] {0}
+(0,-2pt) -- +(0,0) -- ++(#1*\xscale*\kmAtEquator,0)
node [
below,
font=\scriptsize,
inner xsep=1pt,
label={[inner sep=0pt,font=\scriptsize]right:km}] {#1}
-- +(0,-2pt)
}
}
},
scale bar/.default=2000
}
\makeatother
\begin{tikzpicture}
\begin{axis}[
grid=both, ytick={-60,-30,...,90}, xtick={-180,-150,...,180},
grid style=black!10,
enlargelimits=false,
axis equal,
scale only axis,
width=10cm,
height=5cm,
disabledatascaling, clip=false
]
\addplot [] table {world.dat};
\pgfplotsextra{
\foreach \x in {-160,-120,...,160}{
\foreach \y in {-75,-50,...,75}{
\fill [cyan, opacity=0.25] (\x,\y) circle [radius=5, scale circle];
}
}
\fill [orange] (-64.9,32.3) -- (-66.1,18.5) node [anchor=mid west, inner sep=1pt, orange!75!black, fill=white, text opacity=1,fill opacity=0.75, align=left] {Bermuda\\Triangle} -- (-80.4,25.2) -- cycle;
\draw (185,0) [scale bar];
\draw (185,45) [scale bar];
\draw (185,60) [scale bar];
}
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
Tutorials
In the unstable version the PGFPlots manual has a section containing step-by-step tutorials. The latest unstable version can always be obtained here: http://pgfplots.sourceforge.net/pgfplots_unstable.pdf
Screenshot of the table of contents
Introductory talk
On the official PGFPlots Homepage at Sourceforge, there is a link to an introductory talk, which was originally held by the main developer Christian Feuersänger. The link is here: http://pgfplots.sourceforge.net/pgfplots_talk_FTUG_2012_final.pdf
Screenshot of the outline slide