3

This is my first time using tikz/pgfplots; I'm not even sure I understand the difference between tiki and pgfplots. Please forgive my ignorance.

I have a plot defined as:

\begin{tikzpicture}
\begin{axis}[
  ticks = none,
  axis lines = center,
  xlabel = energy,
  ylabel = cross section,
  xlabel style = {below},
  ylabel style = {left,rotate=90},
  xmin = 0.0,
  xmax = 5,
  ymin = 0.0,
  ymax = 2.0,
]
\addplot[
  blue,
  samples=200,
] {1/sqrt(x)};
\end{axis}
\end{tikzpicture}

Now I want to add some points (markers) on the curve (defined by 1/sqrt(x)) at a few points specified by the x-value (0.5, 1.25, 1.5, 1.75, 2.20). I could determine the y-value for each x-value, but I figured there was someway for LaTeX to determine what the y-value was.

I'd like to add these points individually as I'll be animating this in Beamer at a later date.


On a different note, how can I center the axes labels at the center of the axes instead of the end?

3

You can use samples at key

\begin{tikzpicture}
\begin{axis}[
  ticks=none,
  axis x line=bottom,
  axis y line=left,
  xlabel = energy,
  ylabel = cross section,
  xmin = 0.0,
  xmax = 5,
  ymin = 0.0,
  ymax = 2.0,
]
\addplot[blue,samples=200]{1/sqrt(x)};
\addplot[only marks,samples at={0.5, 1.25, 1.5, 1.75, 2.20}]{1/sqrt(x)};
\end{axis}
\end{tikzpicture}

enter image description here

2
\documentclass[border=2mm,tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\xdef\Lst{}
\foreach \X in {0.5, 1.25, 1.5, 1.75, 2.20}
{\xdef\Lst{\Lst (\X,{1/sqrt(\X)})}}
\typeout{\Lst}
\begin{tikzpicture}
\begin{axis}[
  ticks = none,
  axis lines = center,
  xlabel = energy,
  ylabel = cross section,
  xlabel style = {below,anchor=north east},
  ylabel style = {above,rotate=90,anchor=south east},
  xmin = 0.0,
  xmax = 5,
  ymin = 0.0,
  ymax = 2.0,
]
\addplot[
  blue,
  samples=200,
] {1/sqrt(x)};
\addplot[only marks,
  red] coordinates \Lst;
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.