剧情存在线条相互冲突且格式不正确的问题

剧情存在线条相互冲突且格式不正确的问题
\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{figure}[hbpt!]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            scale only axis=true,
            width=0.7\textwidth,
            height=0.4\textwidth,
            xlabel={\textbf{Duration [Minutes]}},
            ylabel={\textbf{Temperature [$^{\circ}$C]}},
            xmin=0, xmax=750,
            ymin=0 , ymax=2500,
            xtick={ 10, 35, 215, 335, 695},
            ytick={},
            legend pos=north west,
            xmajorgrids=true,
            grid style=dashed,
            nodes near coords = {\pgfmathfloatifflags{\pgfplotspointmeta}{0}{}{\pgfmathprintnumber{\pgfplotspointmeta}}}
            ]
            \addplot[
            color=black,
            mark=square,
            ]
            coordinates {(0,0)(35,1419)(215,1431)(335,1430)(695,1400)
            };
            \addlegendentry {Trial  5}
            \addplot[
            color=black,
            mark=square,
            ]
            coordinates {(0,0)(30,1400)(197,1448)(200,1440)(270,1400)(380,1401)
            };
            \addlegendentry {Trial  6}
        \end{axis}
    \end{tikzpicture}
    \caption{Activity and temperature profile for trial 5 and trial 6}
    \label{Temperature Profile}
\end{figure}
\end{document}

在此处输入图片描述

答案1

我做了以下事情来解决你的问题:

  1. 我缩小了标签的字体大小nodes near coords style={font=\tiny}
  2. 使用nodes near coords align={above}可选参数,addplot您可以分离标签。
  3. 其中一个标签仍然重叠,因为它们太靠近了。因此,我制作了另一个addplot只有一个标记的标签,并用nodes near coords align={yshift=10pt}
\documentclass{article}
\usepackage{pgfplots}

\begin{document}
    \begin{figure}[hbpt!]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            scale only axis=true,
            width=0.7\textwidth,
            height=0.4\textwidth,
            xlabel={\textbf{Duration [Minutes]}},
            ylabel={\textbf{Temperature [$^{\circ}$C]}},
            xmin=0, xmax=750,
            ymin=0 , ymax=2500,
            xtick={ 10, 35, 215, 335, 695},
            ytick={},
            legend pos=north west,
            xmajorgrids=true,
            grid style=dashed,
            nodes near coords style={font=\tiny},
            nodes near coords = {\pgfmathfloatifflags{\pgfplotspointmeta}{0}{}{\pgfmathprintnumber{\pgfplotspointmeta}}}
            ]
            \addplot[
            color=black,
            mark=square,
            nodes near coords align={below},
            ]
            coordinates {(0,0)(35,1419)(215,1431)(335,1430)(695,1400)
            };
            \addlegendentry {Trial  5}
            \addplot[
            nodes near coords align={above},
            color=black,
            mark=square,
            ]
            coordinates {(0,0)(30,1400)(200,1440)(270,1400)(380,1401)
            };
            \addlegendentry {Trial  6}
            \addplot[
            nodes near coords align={yshift=10pt},
            color=black,
            mark=square,
            ]
            coordinates {(197,1448)
            };      
        \end{axis}
    \end{tikzpicture}
    \caption{Activity and temperature profile for trial 5 and trial 6}
    \label{Temperature Profile}
\end{figure}
\end{document}

在此处输入图片描述

相关内容