7

Can I draw figure 3 y axis using pgfplot? That figure has 3 y axis. 1 y axis in the left, 2 y axis in right position. I am sorry, I could not attach a graph for that.

\documentclass{article}

\usepackage{pgfplots}

\begin{document}
data y1
(0,0)
(1,2)
(2,3)
(3,4)
(4,6)
(5,11)
(6,20)
(7,15)
(8,12)
(9,8)
(10,7)
(11,3)
(12,0)

data y2
(0,0)
(1,0.2)
(2,0.3)
(3,0.4)
(4,0.6)
(5,1.1)
(6,2.0)
(7,1.5)
(8,1.2)
(9,0.8)
(10,0.7)
(11,0.3)
(12,0)

data y3 
(0,4)
(1,6)
(2,8)
(3,9)
(4,13)
(5,18)
(6,29)
(7,50)
(8,32)
(9,38)
(10,27)
(11,23)
(12,10)

\end{document}

Actually I want to make figure like below

enter image description here

Source of image : JBC, Vol. 264, No. 5, Issue of February 15, pp. 2672-2677,1989

azetina
  • 28,884
limpato
  • 349

1 Answers1

10

In my understanding you want a two ordinate plot. The pgfplots manual suggests drawing two axis in one:

\documentclass{book}
\usepackage{pgfplots}

\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}

\begin{axis}[ scale only axis, xmin=0,xmax=12, axis y line*=left, xlabel=x, ylabel=Small Axis (green)]
    \addplot[green] coordinates {(0,0)          
    (1,0.03)(2,0.04)
    (3,0.06)(4,0.7)
    (5,1.1)(6,1.4)
    (7,1.5)(8,1.2)
    (9,0.8)(10,0.5)
    (11,0.3)(12,0.1)};
\end{axis}
%
\begin{axis}[ scale only axis, xmin=0,xmax=12, axis y line*=right, axis x line=none, ylabel=Second ordinate (blue)]%
    \addplot[blue] coordinates {(0,0)
    (1,2)(2,3)
    (3,4)(4,6)
    (5,11)(6,20)
    (7,15)(8,12)
    (9,8)(10,7)
    (11,3)(12,0)};
%
    \addplot[blue] coordinates {(0,4)
    (1,6)(2,8)
    (3,9)(4,13)
    (5,18)(6,29)
    (7,50)(8,32)
    (9,38)(10,27)
    (11,23)(12,10)};
\end{axis} 

\end{tikzpicture}

\end{document}

enter image description here

Remark: one should be very carefull with this kind of figures. You have to tell your readers very explicitly that those three curves are not in the same scale. Readers can easily get confused. Although such drawings are quite common in engineering reference books i would not recommend to use that in an educational context nor a paper.

Update In order to draw three lines we need to shift the axis manually. The resulting code is quite a mess but it seems to work. It should be possible to draw even more than 3 axis in this way. You ´ll find your first and second data lining exactly on top of each other. Dataset number one is drawn anyway.

\documentclass{book}
\usepackage{pgfplots}

\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}
 \pgfplotsset{every axis/.style={ymin=0}}
\begin{axis}[ scale only axis, xmin=0,xmax=12, axis y line*=left, xlabel=fractions, ylabel=Small Axis (green)]
    \addplot[green, mark=o, draw] coordinates {(0,0)
    (1,0.03)(2,0.04)
    (3,0.06)(4,0.7)
    (5,1.1)(6,1.4)
    (7,1.5)(8,1.2)
    (9,0.8)(10,0.5)
    (11,0.3)(12,0.1)};
\end{axis}
%
\begin{axis}[ scale only axis, xmin=0,xmax=12, axis y line*=right, axis x line=none, ylabel=Second ordinate (blue)]%
    \addplot[blue, mark=x] coordinates {(0,0)
    (1,2)(2,3)
    (3,4)(4,6)
    (5,11)(6,20)
    (7,15)(8,12)
    (9,8)(10,7)
    (11,3)(12,0)};
%
\end{axis}
%
\begin{axis}[red, scale only axis, xmin=0,xmax=12, axis y line*=right, axis x line=none, ylabel=third ordinate (red)]%
\pgfplotsset{every outer y axis line/.style={xshift=2cm}, every tick/.style={xshift=2cm}, every y tick label/.style={xshift=2cm} }
    \addplot[red ,mark=+] coordinates {(0,4)
    (1,6)(2,8)
    (3,9)(4,13)
    (5,18)(6,29)
    (7,50)(8,32)
    (9,38)(10,27)
    (11,23)(12,10)};
\end{axis} 

\end{tikzpicture}

\end{document}

3 y axis plot

One last remark: as Christian Feuersänger tell us in the pgfplots documentation pgfplots has no idea whats going on. So i suggest that you check your plots made in such a way for errors.

Edit I added ymin to force zeros on the same line.

bloodworks
  • 10,178
  • thank you, yes, bloodworks, what I want to tell that three plot are different scale. as this is my first posting, sorry for making you confuse, now I can make link to the picture what I want, actually I need to draw the graph like the link I just attach http://imgur.com/h0LMP – limpato Jul 05 '12 at 14:06
  • sorry to ask you again, i notice that the x and y axis in region for zero are separated each other, can we make only one point (coordinate) for zero? – limpato Jul 05 '12 at 16:18
  • It´s possible to explicitly define a minimum value for the y-axis. Just give the axis environment ymin=0 as a option. (For every axis, as global option you need to type \pgfplotsset{every axis/.style={ymin=0}} right before the first axis ) – bloodworks Jul 05 '12 at 16:24
  • that is so cool!!!... thank you again for your help.. – limpato Jul 05 '12 at 16:30