[Tex/LaTex] drawing two curves in the same figure

graphicsgraphs

Please i need someone who can help me to draw two curves into one figure. I need to draw the two curves Y1 and Y2 in the same figure.

enter image description here

By the way, i tried to write the code below:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}

    \draw[->] (0,0) -- (6,0);
    \draw[->] (0,0) -- (0,1.5);

 \draw[thick, color=red] plot [smooth,tension=0] coordinates{(0.1, 0.003) (0.5, 0.005) (2, 0.4) (5, 1)};
 \draw[thick, color=red] plot [smooth,tension=0] coordinates{(0.1, 0.2) (0.5, 0.5) (2, 0.1) (5, 1.4)};

\end{tikzpicture}
\end{document}

The problem is that i get a very small graph especially a very small y-axis!! so how can i resolve this problem ?

Best Answer

You can use additionaly the pgfplots package.

The first way is using the coordinates directly in the code to produce the graphic.

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

\begin{document}
   \begin{tikzpicture}
        \begin{axis}[%
            axis x line=bottom,
            axis y line=left]
            \addplot[mark=none,red,thick] coordinates {(0.1, 0.003) (0.5, 0.005) (2, 0.4) (5, 1)};
            \addplot[mark=none,red,thick] coordinates {(0.1, 0.2) (0.5, 0.5) (2, 0.1) (5, 1.4)};
        \end{axis}
    \end{tikzpicture}
\end{document}

The second way is use a table, from a .dat file.

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

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[%
            axis x line=bottom,
            axis y line=left]
            \addplot[mark=none,red,thick] table[x=x,y=y1] {table.dat};
            \addplot[mark=none,red,thick] table[x=x,y=y2] {table.dat};
        \end{axis}
    \end{tikzpicture}
\end{document}

The table.dat file is a text document (you can create it with notepad), and the data is written inside it, in columns, like this:

x   y1  y2
0.1 0.003   0.2
0.5 0.005   0.5
2   0.4 0.1
5   1   1.4

Every data is tab-separated.

Both schemes produce this:

enter image description here

In addition, you can describe a legend and labels for both axis.

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

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[%
            axis x line=bottom,
            axis y line=left,
            xlabel=$X$,
            ylabel=$Y$,
            legend pos= south east]
            \addplot[mark=none,blue,thick] table[x=x,y=y1] {table.dat};
            \addplot[mark=none,red,thick] table[x=x,y=y2] {table.dat};
            \legend{$Y_1$,$Y_2$};
        \end{axis}
    \end{tikzpicture}
\end{document}

The result:

enter image description here