4

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 ?

  • 1
    Welcome to TeX.SX. Questions about how to draw specific graphics are really not reasonable questions to ask on the site. Please post a minimal compilable document showing what you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. Have you tried using the pfgplotstable package? – jub0bs Nov 9 '13 at 21:04
  • ah okk, thank you so much for your response anyway, i will delete my question and post another one with some codes :) – Christina Nov 9 '13 at 21:07
  • Don't delete it. Simply edit and improve it. – jub0bs Nov 9 '13 at 21:07
  • ah ok i will :) – Christina Nov 9 '13 at 21:07
6

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

  • 1
    Sincerely, i don't know how to thank you Dear!! thank you sooooo much – Christina Nov 9 '13 at 22:19
5

Alternative option:

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1.5]
    \draw[->] (0,0) -- (5.5,0) node[right] {$x$}; % x-axis
    \draw[->] (0,0) -- (0,2) node[above] {$y$}; % y-axis
        \foreach \x in {0,0.5,...,5}
            \draw[xshift=\x cm] (0pt,1pt) -- (0pt,-1pt) node[below] {$\x$};
        \foreach \y in {0, 0.5, 1, 1.5}
            \draw[yshift=\y cm] (1pt,0pt) -- (-1pt,0pt) node[left] {$\y$};
 \draw[thick, color=red] plot [smooth,tension=0] coordinates{(0.1, 0.003) (0.5, 0.005) (2, 0.4) (5, 1)} node[right, color=black] {$Y_1$};
 \draw[thick, color=blue] plot [smooth,tension=0] coordinates{(0.1, 0.2) (0.5, 0.5) (2, 0.1) (5, 1.4)} node[right, color=black] {$Y_2$};
\end{tikzpicture}
\end{document}

The following changes the plotting scale.

\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}
\vskip3ex
\begin{tikzpicture}[x=1.5cm,y=2.0cm]

    \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}

enter image description here

  • Thank you so much for your reply :) i really appreciated it :) – Christina Nov 9 '13 at 22:18

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.