# How can I get the grid done correctly?

I'm trying to put the grid in my graphic, and I'm getting this problem below. The grid style must be help lines, and dashed, this I know how to do, but the problem remains in put the grid correctly.

Here is the code that I'm using.

 \documentclass[a4paper,10pt]{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage{lmodern}
\pgfplotsset{compat=1.3}
\usepgfplotslibrary{groupplots}

\begin{filecontents*}{dataCL.csv}
x, y
10, 0.7
15, 0.6
20, 0.5
\end{filecontents*}
\begin{filecontents*}{dataCD.csv}
x, y
10, 0.4
15, 0.3
20, 0.2
\end{filecontents*}

\begin{document}

\pgfkeys{
/pgf/number format/.cd,
set decimal separator={,{\!}},
set thousands separator={}
}
\pgfplotsset{
every axis/.append style = {
line width = 0.5pt,
tick style = {line width=1pt},
grid style={dashed}
}
}
\begin{tikzpicture}
% provide shared options here with pgfplotsset:
\pgfplotsset{
height=6cm, width=9cm,
no markers=major
}
% this is the leftmost y axis (y2)
\begin{axis}[
xmin=0,xmax=1,%--- CF
xshift=0cm,%-- CF
width=2cm,
hide x axis,
axis y line*=left,
ymin=0, ymax=1.2,
ytick = {0,0.24,0.48,...,1.2},
ylabel={$C_l$}
]
\end{axis}
\begin{axis}[
xmin=0, xmax=10,
xshift=7cm,%-- CF
width=2cm,
hide x axis,
axis y line*=right,
ymin=0, ymax=0.5,
ytick = {0,0.1,0.2,...,0.5},
ylabel={$C_D$}
]
\end{axis}
\begin{axis}[
height=2cm,
xmin=0, xmax=25,
ymin=0, ymax=1.2,
minor ytick = {0,5,10,...,25},
axis x line*=bottom,
hide y axis,
xlabel={$\alpha$}
]
\end{axis}
\begin{axis}[
xmin = 0, xmax=25,
ymin = 0, ymax=1.2,
hide x axis,
hide y axis,
]
\addplot+ [mark = none] table [col sep=comma, x=x, y=y]{dataCL.csv};
\end{axis}
\begin{axis}[
xmin = 0, xmax=25,
ymin = 0, ymax=0.5,
hide x axis,
hide y axis,
]
\addplot+ [mark = none] table [col sep=comma, x=x, y=y]{dataCD.csv};
\end{axis}
\begin{axis}[grid]

\end{axis}

\end{tikzpicture}

\end{document}


-
Why are you using so many axis environments? Use only one. – Qrrbrbirlbel Apr 13 '13 at 1:28
Your grid looks fine, as @Qrrbrbirlbel says you should have the addplots in a single axisenvironment. – Peter Grill Apr 13 '13 at 1:30
Because are three different axis, and each one have differents limits. – user28527 Apr 13 '13 at 1:33
Actually the right curves are [link] (i.stack.imgur.com/6PYPG.jpg), there you can see what the grid is doing. I don't want that extra axis points, I just want that the grid between the y axis and x axis, without creat any extra points in the axis. – user28527 Apr 13 '13 at 1:38
Pardon me, but I fail to see what you're trying to achieve with the graph you linked to. Why show two plots on the same graph if the x-ticks do not coincide? What is this graph supposed to tell your reader? Please consider presenting your data differently. – Jubobs Apr 13 '13 at 8:20

I find a way to do that.

\documentclass[a4paper,10pt]{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage{lmodern}
\pgfplotsset{compat=1.3}
\usepgfplotslibrary{groupplots}

\begin{filecontents*}{dataCL.csv}
x, y
10, 0.7
15, 0.6
20, 0.5
\end{filecontents*}
\begin{filecontents*}{dataCD.csv}
x, y
10, 0.4
15, 0.3
20, 0.2
\end{filecontents*}

\begin{document}

\pgfkeys{
/pgf/number format/.cd,
set decimal separator={,{\!}},
set thousands separator={}
}
\pgfplotsset{
every axis/.append style = {
line width = 0.5pt,
tick style = {line width=1pt},
grid style={dashed}
}
}
\begin{tikzpicture}
% provide shared options here with pgfplotsset:
\pgfplotsset{
height=6cm, width=9cm,
no markers=major
}
% this is the leftmost y axis (y2)
\begin{axis}[ymajorgrids,
xmin=0,xmax=1,%--- CF
% xshift=0cm,%-- CF
%width=2cm,
hide x axis,
axis y line*=left,
ymin=0, ymax=1.2,
ytick = {0,0.24,0.48,...,1.2},
ylabel={$C_l$}
]
\end{axis}
\begin{axis}[
xmin=0, xmax=10,
xshift=7cm,%-- CF
width=2cm,
hide x axis,
axis y line*=right,
ymin=0, ymax=0.5,
ytick = {0,0.1,0.2,...,0.5},
ylabel={$C_D$}
]
\end{axis}
\begin{axis}[xmajorgrids,
height=6cm,
xmin=0, xmax=25,
ymin=0, ymax=1.2,
minor ytick = {0,5,10,...,25},
axis x line*=bottom,
hide y axis,
xlabel={$\alpha$}
]
\end{axis}
\begin{axis}[
xmin = 0, xmax=25,
ymin = 0, ymax=1.2,
hide x axis,
hide y axis,
]
\addplot+ [mark = none] table [col sep=comma, x=x, y=y]{dataCL.csv};
\end{axis}
\begin{axis}[
xmin = 0, xmax=25,
ymin = 0, ymax=0.5,
hide x axis,
hide y axis,
]
\addplot+ [mark = none] table [col sep=comma, x=x, y=y]{dataCD.csv};
\end{axis}
\end{tikzpicture}
\end{document}

-
It would be helpful if you added some explanation of what you did to resolve this issue. – Peter Grill Apr 19 '13 at 2:45