让刻度在 pgfplot 中的图形上停止

让刻度在 pgfplot 中的图形上停止

我有以下情节:

\documentclass[a4paper, 12pt]{report}
\usepackage{graphicx} 
\usepackage{pgfplots}
\usepackage{caption}
\setlength{\abovecaptionskip}{2pt}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\pgfplotsset{every x tick label/.append style={font=\tiny}, compat=1.3}
\begin{axis}[
    title={Temperature Test},
    xlabel={Temperature [\textcelsius]},
    ylabel={Distance [m]},
    xmin=-50, xmax=140,
    ymin=0, ymax=7.5,
    xtick={-50, -30, -10, 10, 30, 50, 70, 90, 110, 130},
    ytick={1, 2, 3, 4, 5, 6, 7},
    extra x ticks = {35.6},
    extra x tick labels = {},
    extra y ticks = {4.372},
    extra y tick labels = {},
    extra tick style = {
        major grid style = {red, solid, very thick}
        } ,
    ymajorgrids=true,
    xmajorgrids=true,
    grid style=dashed,
]

\addplot[
    color=blue,
    mark=*,
    ]
    coordinates {
    (-48,0.883)(18,1.852)(24,2.585)(52,6.891)(136,7.003)
    };
\end{axis}
\end{tikzpicture}
\caption*{Graph of temperature against distance energy with critical point}
\end{center}
\end{figure}
\end{document}

阴谋

我想要红线(额外的刻度)在图表处停止,如下所示: 在此处输入图片描述

我该如何做呢?

此外,我对 LaTeX 相对缺乏经验,尤其不熟悉绘制图表。所以,请随意指出我的代码中可以改进的任何其他内容;上面的代码是我结合了在互联网上找到的零碎代码编写的。

答案1

这个解决方案没有额外的勾选,只是添加了另一个 addplot:

\documentclass[a4paper, 12pt]{report}
\usepackage{graphicx} 
\usepackage{pgfplots}
\usepackage{caption}
\setlength{\abovecaptionskip}{2pt}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\pgfplotsset{every x tick label/.append style={font=\tiny}, compat=1.3}
\begin{axis}[
    title={Temperature Test},
    xlabel={Temperature [\textcelsius]},
    ylabel={Distance [m]},
    xmin=-50, xmax=140,
    ymin=0, ymax=7.5,
    xtick={-50, -30, -10, 10, 30, 50, 70, 90, 110, 130},
    ytick={1, 2, 3, 4, 5, 6, 7},
    ymajorgrids=true,
    xmajorgrids=true,
    grid style=dashed,
]

\addplot[
    color=blue,
    mark=*,
    ]
    coordinates {
    (-48,0.883)(18,1.852)(24,2.585)(52,6.891)(136,7.003)
    };

\addplot[
color=red,very thick,
mark=none,
]
coordinates {
    (-50,4.372)(35.6,4.372)(35.6,0)
};
\end{axis}
\end{tikzpicture}
\caption*{Graph of temperature against distance energy with critical point}
\end{center}
\end{figure}
\end{document}

在此处输入图片描述

相关内容