插入曲线中点的标签

插入曲线中点的标签

我尝试为以下示例图中的每个点添加一些标签(这是背页)类似于这些标签答案

我选择这个 Overleaf 示例代码的原因是,总体来说,情节与我想要的非常相似,只是缺少标签。

我在 Overleaf 网站上找不到如何使用nodeandpos而不是coordinates。当我coordinatesnodeand poslike 替换此回答,我收到一条错误消息。

有没有解决方案可以稍微修改这个示例代码,从而为每个点添加标签?

附言。由于本文中有不同轴长的不同图表,因此我不愿意使用pgfplotstableread

\begin{tikzpicture}
\begin{axis}[
    title={Temperature dependence of CuSO\(_4\cdot\)5H\(_2\)O solubility},
    xlabel={Temperature [\textcelsius]},
    ylabel={Solubility [g per 100 g water]},
    xmin=0, xmax=100,
    ymin=0, ymax=120,
    xtick={0,20,40,60,80,100},
    ytick={0,20,40,60,80,100,120},
    legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
]

\addplot[
    color=blue,
    mark=square,
    ]
    coordinates {
    (0,23.1)(10,27.5)(20,32)(30,37.8)(40,44.6)(60,61.8)(80,83.8)(100,114)
    };
    \legend{CuSO\(_4\cdot\)5H\(_2\)O}
    
\end{axis}
\end{tikzpicture}

答案1

这个选项nodes near coords可能就是你正在寻找的:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    title={Temperature dependence of CuSO\(_4\cdot\)5H\(_2\)O solubility},
    xlabel={Temperature [\textcelsius]},
    ylabel={Solubility [g per 100 g water]},
    xmin=0, xmax=100,
    ymin=0, ymax=120,
    xtick={0,20,40,60,80,100},
    ytick={0,20,40,60,80,100,120},
    legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
]

\addplot[
        color=blue,
        mark=square,
        nodes near coords,
        node near coord style={below right}
    ]
    coordinates {
        (0,23.1)(10,27.5)(20,32)(30,37.8)(40,44.6)(60,61.8)(80,83.8)(100,114)
    };

\legend{CuSO\(_4\cdot\)5H\(_2\)O}
    
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述


根据您的评论,您拥有与每个坐标相关的更多信息,而不仅仅是X值。我建议您使用table而不是 列表coordinates,因为这样可以更轻松地将所有信息添加为标签:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    title={Temperature dependence of CuSO\(_4\cdot\)5H\(_2\)O solubility},
    xlabel={Temperature [\textcelsius]},
    ylabel={Solubility [g per 100 g water]},
    xmin=0, xmax=100,
    ymin=0, ymax=120,
    xtick={0,20,40,60,80,100},
    ytick={0,20,40,60,80,100,120},
    legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
]

\addplot[
        color=blue,
        mark=square,
        nodes near coords={$\pgfmathprintnumber\yvalue$ \\ 
            $C$: $\pgfmathprintnumber\cvalue$ \\ 
            $R$: $\pgfmathprintnumber\rvalue$ \\ 
            $S$: $\pgfmathprintnumber\svalue$},
        visualization depends on={y \as \yvalue},
        visualization depends on={\thisrow{c} \as \cvalue},
        visualization depends on={\thisrow{r} \as \rvalue},
        visualization depends on={\thisrow{s} \as \svalue},
        node near coord style={font=\scriptsize, align=left},
        coordinate style/.condition={
            \coordindex!=1 && \coordindex!=3
        }{below right},
    ]
    table {
        x   y    c   r      s
        0   23.1 600 200000 200
        10  27.5 600 200000 200
        20  32   600 200000 200
        30  37.8 600 200000 200
        40  44.6 600 200000 200
        60  61.8 600 200000 200
        80  83.8 600 200000 200
        100 114  600 200000 200
    };

\legend{CuSO\(_4\cdot\)5H\(_2\)O}
    
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相同,但没有值和非科学数字格式:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    title={Temperature dependence of CuSO\(_4\cdot\)5H\(_2\)O solubility},
    xlabel={Temperature [\textcelsius]},
    ylabel={Solubility [g per 100 g water]},
    xmin=0, xmax=100,
    ymin=0, ymax=120,
    xtick={0,20,40,60,80,100},
    ytick={0,20,40,60,80,100,120},
    legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
]

\addplot[
        color=blue,
        mark=square,
        nodes near coords={$C$: $\pgfmathprintnumber[fixed]\cvalue$ \\ 
            $R$: $\pgfmathprintnumber[fixed]\rvalue$ \\ 
            $S$: $\pgfmathprintnumber[fixed]\svalue$},
        visualization depends on={\thisrow{c} \as \cvalue},
        visualization depends on={\thisrow{r} \as \rvalue},
        visualization depends on={\thisrow{s} \as \svalue},
        node near coord style={font=\scriptsize, align=left},
        coordinate style/.condition={
            \coordindex!=1 && \coordindex!=3
        }{below right},
    ]
    table {
        x   y    c   r      s
        0   23.1 600 200000 200
        10  27.5 600 200000 200
        20  32   600 200000 200
        30  37.8 600 200000 200
        40  44.6 600 200000 200
        60  61.8 600 200000 200
        80  83.8 600 200000 200
        100 114  600 200000 200
    };

\legend{CuSO\(_4\cdot\)5H\(_2\)O}

\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容