![グリッドを正しく作成するにはどうすればいいでしょうか?](https://rvso.com/image/266416/%E3%82%B0%E3%83%AA%E3%83%83%E3%83%89%E3%82%92%E6%AD%A3%E3%81%97%E3%81%8F%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B%E3%81%AB%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%81%84%E3%81%84%E3%81%A7%E3%81%97%E3%82%87%E3%81%86%E3%81%8B%3F.png)
グラフィックにグリッドを配置しようとしているのですが、以下の問題が発生しています。グリッド スタイルは補助線と破線にする必要があります。その方法はわかっていますが、グリッドを正しく配置できないという問題が残っています。
私が使用しているコードは次のとおりです。
\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}