
私が本当に望んでいたものについて混乱があったので、実際の使用例をここに含めます。MWE プラスの対応する画像は、投稿の下部にあります。
見栄えの良いグラフをいくつか作成しましたが、その中でカスタム グリッド ラインを使用しています。一部のグリッド ラインは、カスタム定義した軸まで届きません。これを実現するにはどうすればよいでしょうか。
\documentclass{standalone}
\usepackage{pgf}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,shapes, positioning}
\tikzset{
shadowed/.style={preaction={
transform canvas={shift={(2pt,-1pt)}},draw opacity=.2,#1,preaction={
transform canvas={shift={(4pt,-1.75pt)}},draw opacity=.1,#1,preaction={
transform canvas={shift={(6pt,-2.5pt)}},draw opacity=.05,#1,preaction={
transform canvas={shift={(8pt,-3.25pt)}},draw opacity=.025,#1,
}
}}}},
}
\makeatletter
\def\pgfplotsdataxmin{\pgfplots@data@xmin}
\def\pgfplotsdataxmax{\pgfplots@data@xmax}
\def\pgfplotsdataymin{\pgfplots@data@ymin}
\def\pgfplotsdataymax{\pgfplots@data@ymax}
\makeatother
\pgfplotsset{
range frame/.style={
tick align=outside,
axis line style={opacity=0},
after end axis/.code={
\draw[cyan,thick,double=white,double distance=1.4pt,line cap=round,rounded corners] ({rel axis cs:0,0}-|{axis cs:\pgfplotsdataxmax,0}) -- ({rel axis cs:0,0}-|{axis cs:\pgfplotsdataxmin,0}) -- ({rel axis cs:0,0}|-{axis cs:0,\pgfplotsdataymin}) -- ({rel axis cs:-.1,0}|-{axis cs:0,\pgfplotsdataymax});
}
}
}
\begin{document}
\begin{tikzpicture}[scale=2]
\begin{axis}[range frame,
domain=25.29325198:97,
axis lines*=left,
yticklabel=\empty,
xticklabels=\empty,
xtick style={draw=none},
ytick style={draw=none},
extra description/.code={%
\node[] at (axis cs:6,60) {$60$};
\node[] at (axis cs:8.6,40) {$40$};
\node[] at (axis cs:11.5,20) {$20$};
\node[] at (axis cs:15,0) {$0$};
\node[] at (axis cs:25,-11.3) {$25$};
\node[] at (axis cs:50,-11.3) {$50$};
\node[] at (axis cs:75,-11.3) {$75$};
\draw[ultra thin,lightgray] (axis cs:25,-9) -- (axis cs:25,-7);
\draw[ultra thin,lightgray] (axis cs:50,-9) -- (axis cs:50,-7.5);
\draw[ultra thin,lightgray] (axis cs:75,-9) -- (axis cs:75,-7.5);
\node[] at (axis cs:\pgfplotsdataxmin-15.5,\pgfplotsdataymax+4.4) {$m_\mathrm{gr}$};
\node[] at (axis cs:\pgfplotsdataxmax+5.5,\pgfplotsdataymin-7) {$m_\mathrm{f}$};
}
]
\draw[ultra thin,lightgray] (axis cs:-8.05,20) -- (axis cs:\pgfplotsdataxmax,20);
\draw[ultra thin,lightgray] (axis cs:-8.05,0) -- (axis cs:\pgfplotsdataxmax,0);
\draw[ultra thin,lightgray] (axis cs:-8.05,40) -- (axis cs:\pgfplotsdataxmax,40);
\draw[ultra thin,lightgray] (axis cs:-8.05,60) -- (axis cs:\pgfplotsdataxmax,60);
\addplot[shadowed={double=gray,draw=gray},thick,line cap=round,rounded corners, draw=purple,double=white,double distance=1.6pt,
] {-23.73194+0.9382716*x};
\end{axis}
\end{tikzpicture}
\makeatother
\end{document}
元の投稿:独自のグリッド ラインを作成せざるを得ませんが、以下のコードを使用すると軸がグリッド ラインと重なります。このため、グリッド ラインの一部が無視されます。軸のすぐ後ろに描画し、指定した x 座標に従いたいのですが、軸と曲線が描画される前に、軸によって生成される重なり合う空白なしで線を描画するにはどうすればよいでしょうか。
\documentclass{standalone}
\usepackage{pgfplots}
\makeatletter
\begin{document}
\begin{tikzpicture}[scale=2]
\begin{axis}[
extra description/.code={%preaction={ %preaction doesn't work
},%}
]
\draw[ultra thick,lightgray] (axis cs:-2,2) -- (axis cs:\pgfplots@data@xmax,2);
\draw[ultra thick,lightgray] (axis cs:.04,4) -- (axis cs:\pgfplots@data@xmax,4);
\draw[ultra thick,lightgray] (axis cs:0,6) -- (axis cs:\pgfplots@data@xmax,6);
\addplot[
] table {
dof l2_err level
.2 2.6 2
.4 2.3 4
.5 2.4 5
.6 1.1 6
.7 1.8 7
.8 4.6 8
.9 3.3 9
1 6.2 10
};
\end{axis}
\end{tikzpicture}
\makeatother
\end{document}
答え1
より一貫性のある出力を得るために、キーを使用できますexecute at <begin/end> <certain events>
。また、最大データ ポイントの代わりに、axis description cs
データ ポイントの場所に関係なく軸全体の長さを取得するためにも使用できます。
\documentclass{standalone}
\usepackage{pgfplots}
\makeatletter
\pgfplotsset{compat=1.11,
my extras/.style={
execute at begin axis={
\draw[ultra thick,lightgray] (axis cs:.08,2) -- (axis cs:\pgfplots@data@xmax,2);
\draw[ultra thick,lightgray] (axis cs:.04,4) -- (axis cs:\pgfplots@data@xmax,4);
\draw[ultra thick,lightgray] (axis cs:0,6) -- (axis cs:\pgfplots@data@xmax,6);
}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}[scale=2]
\begin{axis}[my extras]
\addplot+[ultra thick,
] table {
dof l2_err level
.2 2.6 2
.4 2.3 4
.5 2.4 5
.6 1.1 6
.7 1.8 7
.8 4.6 8
.9 3.3 9
1 6.2 10
};
\end{axis}
\end{tikzpicture}
\end{document}
答え2
更新された質問の解決策は、
clip=false,
環境によって異なりますaxis
。お使いのバージョンでは、手動の水平グリッド線は軸の元のサイズの外側に切り取られます。
次に、水平線の端も調整する必要があります。例:
\draw[ultra thin,lightgray] (axis cs:17,0) -- (axis cs:\pgfplotsdataxmax,0);
\draw[ultra thin,lightgray] (axis cs:14.3,20) -- (axis cs:\pgfplotsdataxmax,20);
\draw[ultra thin,lightgray] (axis cs:11.6,40) -- (axis cs:\pgfplotsdataxmax,40);
\draw[ultra thin,lightgray] (axis cs:9,60) -- (axis cs:\pgfplotsdataxmax,60);