Graphics, Figures & Tablespgfplots | Axis Definition for Plot of Gauss Functions

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
thinkpadT
Posts: 25
Joined: Wed Sep 26, 2012 5:46 pm

pgfplots | Axis Definition for Plot of Gauss Functions

Post by thinkpadT »

Hi everyone,

I have a problem with plotting using pgfplots. What I want is a spectrum as attached in file. But my code I don't get what I want.

I guess the problem lies within the axis definition; but I couldn't find enough information online. I would appreciate it if someone can point me to the right direction.

Code: Select all

\documentclass{article}
\usepackage{pgfplots}
%\usepackage{tikz}

%-----------------------------defining my own coordinate system---
\pgfplotsset{
  mystyle/.style={%
    smooth,
    width=10cm,
    ylabel={Intensity [a.u.] (log)},
    xlabel={Order of High Harmonics},
    xmin=0,xmax=31,
    xtick={1,3,5,...,31}
  }
}

\begin{document}

\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1*exp(-((x-#1)^2)/(2*#2^2))}% 
  %\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}% 
}

\begin{tikzpicture}
\begin{axis}[mystyle]

  \addplot {gauss(3,0.09)};
 \addplot {gauss(5,0.09)};
 \addplot {gauss(7,0.09)};
  \addplot {gauss(9,0.09)};
  \addplot {gauss(11,0.09)};
  \addplot {gauss(13,0.09)};
  \addplot {gauss(15,0.09)};
  \addplot {gauss(17,0.09)};
 \addplot {gauss(19,0.09)};

\end{axis}
\end{tikzpicture}
\end{document}
Thanks alot,
Fawad
Attachments
hhg-spectrum.png
hhg-spectrum.png (37.03 KiB) Viewed 3226 times
Last edited by localghost on Thu Sep 27, 2012 4:55 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

thinkpadT
Posts: 25
Joined: Wed Sep 26, 2012 5:46 pm

pgfplots | Axis Definition for Plot of Gauss Functions

Post by thinkpadT »

hi everyone,

i have improved my code and i am totally satisfied with it. The only thing i cant get running is how to the x-axis so that i get only odd numbers relating to peaks, like shown in the paint diagram. xtickslabel ={1,3,...,31} didnt help. any suggestions

Code: Select all

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=newest}

\begin{document}  

\begin{tikzpicture}
\begin{axis}[
width=13cm, %the width of the box
height=8cm, %the height of the box
xlabel= Order of harmonics,
xmax=31,
xmin=2.5,
ylabel=Intensity (a.u.)
yticklabels= , %supress the ylabe numbering
ymax=9,
ymin=0,
mark = none,
color = black
]  
\addplot[
mark=none, % do not show the points of sampling
smooth,    %smoothen the curve 
domain=1:31
] 
gnuplot [id=exp2,samples=1000]
{7.9*exp(-(x-3)**2/0.05)
%,8*exp(-(x-3)**2/0.05),
%7*exp(-(x-5)**2/0.05),
%6*exp(-(x-7)**2/0.05),
%5*exp(-(x-9)**2/0.05)
};
\end{axis}
\end{tikzpicture}
\end{document}
thanks
feuersaenger
Posts: 34
Joined: Sun Oct 16, 2011 5:56 pm

pgfplots | Axis Definition for Plot of Gauss Functions

Post by feuersaenger »

Hi,

the xticklabels key attaches labels to a previously determined (or defined) set of positions.

In order to define the positions, you can use xtick={1,3,5,...,31} as in your initial style definition.

Note that you may want to use the semilogyaxis environment to get log scaling for y.

Best regards

Christian
Post Reply