
座標系の端まで正確に Y 方向に垂直線を描くにはどうすればよいでしょうか?
·ymax=<value>
(自動的に設定される)「ymax=10」は変更される可能性があることに注意してください (テーブルにはランダムな数字が含まれているため、わかりません)。
·x 値 '6' が指定されていることに注意してください (通常はテーブルから特別な値として読み取られます)。
\documentclass[margin=5mm, tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\pgfplotstableread[col sep=comma]{
0, 0
1, 0
2, 0
3, 1
4, 3
5, 2
6, 5
7, 0
8, 1
12,10
13,5
}\mytable
\begin{tikzpicture}[]
\begin{axis}[
xmin=0, ymin=0,
]
\addplot[mark=*] table[]{\mytable};
\addplot[densely dashed, red] coordinates{(6,0) (6,10)};
\end{axis}
\end{tikzpicture}
\end{document}
答え1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\pgfplotstableread[col sep=comma]{
0, 0
1, 0
2, 0
3, 1
4, 3
5, 2
6, 5
7, 0
8, 1
12,10
13,5
}\mytable
\begin{tikzpicture}
\begin{axis}[
xmin=0, ymin=0,
]
\addplot[mark=*] table[]{\mytable};
\draw[red, ultra thick, densely dashed] (6,0) -- (6,0|-current axis.north);
\draw[green, densely dashed] (6,0) -- (6,\pgfkeysvalueof{/pgfplots/ymax});
\end{axis}
\end{tikzpicture}
\end{document}
答え2
2 つのアイデア (compat
いずれの場合も、オプションを最近の反転に設定する必要があります):
update limits=false
線の座標が y 軸の制限を超えないようにするには、を使用します。
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\pgfplotstableread[col sep=comma]{
0, 0
1, 0
2, 0
3, 1
4, 3
5, 2
6, 5
7, 0
8, 1
12,10
13,5
}\mytable
\begin{tikzpicture}[]
\begin{axis}[
xmin=0, ymin=0,
]
\addplot[mark=*] table[]{\mytable};
\addplot[densely dashed, red, update limits=false] coordinates{(6,0) (6,11)};
\end{axis}
\end{tikzpicture}
\end{document}
- 次のコマンドを使用して線を描画します
\draw
。
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\pgfplotstableread[col sep=comma]{
0, 0
1, 0
2, 0
3, 1
4, 3
5, 2
6, 5
7, 0
8, 1
12,10
13,5
}\mytable
\begin{tikzpicture}[]
\begin{axis}[
xmin=0, ymin=0
]
\addplot[mark=*] table[]{\mytable};
\draw[densely dashed, red]
(6,0 |- {yticklabel cs:0}) -- (6,0 |- {yticklabel cs:1});
% alternatively:
% \draw[densely dashed, red]
% (6,\pgfkeysvalueof{/pgfplots/ymin}) -- (6,\pgfkeysvalueof{/pgfplots/ymax});
\end{axis}
\end{tikzpicture}
\end{document}
どちらのコード例でも同じ出力が生成されます。