如何使用「破折號階段」在 pgfplots 中移動虛線圖案:僅在繪圖中,不在圖例中

如何使用「破折號階段」在 pgfplots 中移動虛線圖案:僅在繪圖中,不在圖例中

如中所提到的這個問題,可以用來dash phase移動繪圖虛線之間空白的位置。然而,這也改變了圖例中的空白。

是否可以僅在圖中移動空白,同時保持圖例不變?

微量元素

\begin{tikzpicture}
\begin{axis}[
width=3in,
height=3in
]
\addplot [black, dashed]
table {%
0 0
1 1
2 0
3 -.5
};
\addlegendentry{w/o dash phase}
\addplot [black, dashed, dash phase = 8pt]
table {%
1 0
2 1
3 0
4 -.5
};
\addlegendentry{w/ dash phase}
\end{axis}
\end{tikzpicture}

這使

在此輸入影像描述

答案1

這就是 的目的legend image post style。您可以使用它來重置dash phase.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=3in,
height=3in,legend image post style={dash phase=0pt},
]
\addplot [black, dashed]
table {%
0 0
1 1
2 0
3 -.5
};
\addlegendentry{w/o dash phase}
\addplot [black, dashed, dash phase=8pt]
table {%
1 0
2 1
3 0
4 -.5
};
\addlegendentryexpanded{w/ dash phase}
\end{axis}
\end{tikzpicture}

\end{document}

在此輸入影像描述

相關內容