如何使用 Tikz Pgf 中的文本列绘制散点图和标签点

问题描述 投票:0回答:1

我想使用从记事本粘贴的表格中选取的文本来绘制散点图和标签点。

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest} 
\usepackage{pgfplotstable}

\begin{document}

\pgfplotstableread[]{
x   y   label  
23  9.6 Jan
46  11.3 Feb
60  12.8 Mar
54  9.8 Apr
}\advdata

\begin{figure}[H]
\begin{center}
\caption{Scatterplot of Advertising versus Sales Data}
\vspace*{15mm}
\scalebox{1}{
\begin{tikzpicture}[]
\begin{axis}[
axis lines = left,
xlabel = {Advertising (x)}, ylabel = {Sales (y)}
]
\addplot[
mark=*,only marks,
point meta =explicit symbolic,
nodes near coords* = {\label},
]
table[x=x,y=y, meta =label]{\advdata};
\end{axis}
\end{tikzpicture}
}
\end{center}
\end{figure}
\end{document}

我收到此错误:!包 PGF 数学错误:无法将输入“Jan”解析为浮点数 r,抱歉。无法阅读的部分位于“Jan”附近..

我怎样才能让这个东西发挥作用?

latex pgfplots
1个回答
0
投票

仅使用

nodes near coords

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest} 
\usepackage{pgfplotstable}
\usepackage{float}

\begin{document}

\pgfplotstableread[]{
x   y   label
23  9.6 Jan
46  11.3 Feb
60  12.8 Mar
54  9.8 Apr
}\advdata

\begin{figure}[H]
\centering
\caption{Scatterplot of Advertising versus Sales Data}
\begin{tikzpicture}[]
\begin{axis}[
axis lines = left,
xlabel = {Advertising (x)}, ylabel = {Sales (y)}
]
\addplot[
mark=*,only marks,
point meta =explicit symbolic,
nodes near coords,
]
table[x=x,y=y, meta =label]{\advdata};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

© www.soinside.com 2019 - 2024. All rights reserved.