그래픽에 그리드를 넣으려고 하는데 아래에서 이 문제가 발생합니다. 그리드 스타일은 도움말 라인과 점선이어야 합니다. 이 작업을 수행하는 방법을 알고 있지만 그리드를 올바르게 배치하는 데 문제가 남아 있습니다.
내가 사용하는 코드는 다음과 같습니다.
\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}
답변1
나는 그렇게 할 수 있는 방법을 찾는다.
\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}