TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to LaTeX and am attempting to type up some old differential equations notes. The only part I seem to be having trouble with is graphing multiple functions onto a single graph. For example the family of solutions of: y=2e^x, y=e^x, y=e^-x, y=2e^-x. I was talking to a physics professor and he suggested that I use TikZ or pfgplots. Would there be one program you would recommend over another?

share|improve this question
I recommend TikZ – Kartik Dec 31 '13 at 6:53
I recommend PSTricks as the first resort. – kiss my armpit Dec 31 '13 at 7:11
I allow myself to welcome Christopher to TeX.SX (speaking on behalf of the whole community). @Christopher: You can have a look at our starter guide to familiarize yourself further with our format. I also want to remark at that position that the package PSTricks is incompatible with the compiler pdflatex - just in case that you want to use that one. For graphs (like the one you are speaking about), I can recommend the package pgfplots (works on base of TikZ). – strpeter Dec 31 '13 at 9:10
up vote 13 down vote accepted

With pgfplots. \begin{axis}[options]...\addplot \end{axis} is required.

enter image description here


\begin{axis}[domain=-4:4, samples=100,grid=major,
    restrict y to domain=0:4,xlabel=$x$,ylabel=$y(x)$, legend pos=north west]
\addplot [color=red]    {2*exp(x)};
\addplot [color=green]  {exp(x)};
\addplot [color=purple] {exp(-x)}; 
\addplot [color=blue]   {2*exp(-x)};

\legend{$2e^x$, $e^x$, $e^{-x}$, $2e^{-x}$}
share|improve this answer

With PSTricks. Compile it with latex-dvips-ps2pdf sequence.


    \psaxes[linecolor=gray,ticksize=4pt 0,Dy=2]{->}(0,0)(-5,-1)(5.5,23.5)[$x$,0][$y$,90]
    \foreach \y/\c/\i/\f in 
    }% important percent sign

enter image description here

Important Notes

Even though PSTricks cannot work with pdflatex directly, it really does not bother us because the agile users (who adopt the best practice paradigm, "separation of concern") know that diagrams should be separated from the text contents. It means that each diagram should be put in a separate, standalone, yet compilable input file. For PSTricks, this diagram's input file must be compiled by latex-dvips-ps2pdf sequence. The product of it is a diagram in PDF format which is consumable to pdflatex used to compile the main input file (i.e., the input file containing the text document). Does it make sense?

share|improve this answer
But if your pictures as standalone will not adapt its font or similar whenever something changes etc., do you still have a good answer for me? Thank you! – strpeter Dec 31 '13 at 12:09
@strpeter: We can create our own package common.sty just to load the common settings (fonts, etc). This package then can be loaded from within each input file, either for diagrams or text document. Does it make sense for you? :-) – kiss my armpit Dec 31 '13 at 12:11

With TikZ:




\draw [help lines,xstep=0.5cm] (0,0) grid (3,15);
\draw [red,thick,->] (0,0) plot [domain=0:2] (\x,2*e^\x);
\draw [blue,thick,->] (0,0) plot [domain=0:2.7] (\x,e^\x);
\draw [->] (0,0) -- (3.5,0) ;
\draw [->] (0,0) -- (0,15.5) ;
\node [fill,red] at (4,7.5) {};
\node at (4.85,7.5) {$y=2e^x$};
\node [fill,blue] at (4,6.5) {};
\node at (4.75,6.5) {$y=e^x$};
\foreach \x in {0,...,15}{\node [left] at (0,\x) {\tiny \x};}
\foreach \y in {0,0.5,...,3}{\node [below] at (\y,0) {\tiny \y};}


plot with tikz (image)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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