Created
March 4, 2014 14:13
-
-
Save gapato/9347187 to your computer and use it in GitHub Desktop.
pgfplots example/boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass[draft]{article} | |
\usepackage{pgfplots} | |
\pgfplotsset{compat=newest} | |
\usepackage{pgfplotstable} | |
\begin{document} | |
%% Linear plot | |
\begin{tikzpicture} | |
\begin{axis}[ | |
title=\texttt{pgfplots} example, | |
xlabel=shooting parameter $\alpha$, | |
ylabel=$\lambda_i$ axis, | |
enlarge x limits=false, | |
legend entries={$f_1$, $f_2$, $f_3$}, | |
% positioning is relative to the unit frame | |
%legend style={at={(0.1,0.1)}, anchor=south west} | |
] | |
%% Read data from file | |
\pgfplotstableread{spectrum.txt}\spectrum | |
\addplot[color=green, line width=1pt] table[x=x, y=l2, header=true] \spectrum; | |
%% Plot expressions from table data | |
\addplot[color=red] table[x=x, y expr=exp(-(\thisrow{l2})^2), header=true] \spectrum; | |
%% Plot function directly | |
\addplot[color=blue, mark=o, domain=0:6] { 1 - (x/3)^2 }; | |
%% Plot coordinates | |
\addplot coordinates { (0, 1) (0.5, 0.5) (1, 0.5) (2, 0) (4, -1) (6, 0) }; | |
%% Tags | |
\node[coordinate, pin=45:{$\lambda_2$}] at (axis cs:5.25,-1) {}; | |
%% Axis lines | |
\draw[ultra thin, color=lightgray] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0); | |
%\draw[ultra thin, color=lightgray] (axis cs:0,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:0,\pgfkeysvalueof{/pgfplots/ymax}); | |
\end{axis} | |
\end{tikzpicture} | |
%% Linear-Log plot | |
\begin{tikzpicture} | |
\begin{semilogyaxis}[xlabel=$x$ axis, ylabel=$f(x)$ axis] | |
\addplot[color=green] table[x index=0, y index=3]{131021-154107.db.txt}; | |
\addplot[color=blue, mark=o, domain=0:6] { 1 - (x/3)^2 }; | |
\addplot[color=blue, mark=false, domain=0:6] { 1 - (x/4)^2 }; | |
\end{semilogyaxis} | |
\end{tikzpicture} | |
%% Subplots | |
\begin{figure} | |
\centering | |
\begin{tikzpicture} | |
\matrix { | |
\begin{axis}[width=4cm] | |
\addplot[mark=false] {sin(deg(x))}; | |
\end{axis} | |
& | |
\begin{axis}[width=4cm] | |
\addplot[mark=false] {cos(deg(x))}; | |
\end{axis} | |
\\ | |
\begin{axis}[width=4cm] | |
\addplot[mark=false] {x}; | |
\end{axis} | |
& | |
\begin{axis}[width=4cm] | |
\addplot[mark=false] {x^2}; | |
\end{axis} | |
\\ | |
}; | |
\end{tikzpicture} | |
\end{figure} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment