# plot using pgfplots

I have the following MWE:

\documentclass[xcolor=pdftex,t,11pt]{beamer}

\usepackage{pgfplots}

\begin{document}

\begin{frame}
\frametitle{Panel data models}
\framesubtitle{Fixed effects}
\begin{center}
\begin{tikzpicture}
\begin{axis}[scale=.8,
axis lines = left,
xlabel = $x$,
ylabel = {$f(x)$},
]
domain=0:30,
samples=20,
color=red,
]
{100+8*x};

domain=0:30,
samples=20,
color=blue,
]
{130+8*x};

\end{axis}
\end{tikzpicture}
\end{center}
\end{frame}

\end{document}


Basically, I would like to plot a graph containing three or more lines. They have the same slope but different intercept. I cannot see how I can have the y-axis starting from 0. Differently it seems that the red one starts from the origin. Moreover, I would like to put a label close to each line explaining it (something like line 1, line 2). I do not need a cumulative legend (which I could obtain with \addlegendentry{} as far as I know. Currently the above is what I was able to obtain so far. Thanks in advance.

• are you wanting a node, something like \addplot [ domain=0:30, samples=20, color=red, ] {100+8*x} node {text}; – cmhughes May 8 '17 at 20:29

\documentclass{beamer}

\usepackage{pgfplots}

\begin{document}

\begin{frame}
\frametitle{Panel data models}
\framesubtitle{Fixed effects}
\begin{center}
\begin{tikzpicture}
\begin{axis}[scale=.8,
axis lines = left,
xlabel = $x$,
ylabel = {$f(x)$},
ymin = 0,
ymax = 200,
]
% Plot 1
domain=0:30,
samples=20,
color=red,
]
{100+8*x};
% Plot 2
domain=0:30,
samples=20,
color=blue,
]
{130+8*x};
%
\end{axis}
\end{tikzpicture}
\end{center}
\end{frame}

\end{document}


• Have you had a look in the manual?
• Just look for legend (4.9.4 Legends)...
• The other question is solved with ymin (4.14 Specifying the Plotted Range).
• Thanks for your reply. Indeed, I know that I could use \addlegendentry[]{Plot 1}. The point is that I would like a label close to each of the lines. Consider like a text box without delimiting lines. Is this possible? – Dario May 8 '17 at 20:19
• Surely, I explained my point badly in my question. I know how to use addlegendentry, but this is not what I want. See my comment above. – Dario May 8 '17 at 20:21
• @Dario I didn't read your question careful enough. I am offline for the rest of the week. Look for annotation in the manual and/or hope for others to help :). – Dr. Manuel Kuehner May 8 '17 at 20:21
• Thanks Manuel. I will have a look at 'annotation'. Thanks again – Dario May 8 '17 at 20:22
• @Dario Any maybe make your question clearer. For example by using bullet points. – Dr. Manuel Kuehner May 8 '17 at 20:22