我想显示用于绘制曲线的所有点的坐标。为此,我手动为所有点创建了单独的节点,有没有更好的方法?我查看了 tikz-pgf 的文档,但找不到解决方案。
以下是剧情:
\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{pgfplots,tikz,siunitx,float,amsfonts,amsmath,amssymb}
\pgfplotsset{compat=1.16}
\usetikzlibrary{intersections, positioning, calc, math}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\begin{axis}[
axis lines=left, thick, grid=both,
width=0.8\textwidth, height=0.8\textwidth,
xmin=0,xmax=110, ymin=0,ymax=150, y=0.06cm,
xlabel={Upper Limits}, ylabel={Cumulative Frequency}
]
\addplot[color = black,smooth,very thick,mark=*,name path=h1] coordinates {
(10,3)(20,7)(30,19)(40,37)(50,57)(60,82)(70,94)(80,102)(90,108)(100,110)
};
\legend{Less-Than type Ogive Curve}
\draw (10,3) node [above]{$(10,3)$};
\draw (20,7) node [above]{$(20,7)$};
\draw (30,19) node [above]{$(30,19)$};
\draw (40,37) node [above]{$(40,37)$};
\draw (50,57) node [above]{$(50,57)$};
\draw (60,82) node [above]{$(60,82)$};
\draw (70,94) node [right]{$(70,94)$};
\draw (80,102) node [above]{$(80,102)$};
\draw (90,108) node [below]{$(90,108)$};
\draw (100,110) node [above]{$(100,110)$};
\end{axis}
\end{tikzpicture}
\caption{Less-Than type Ogive Curve.}
\end{figure}
\end{document}
答案1
通过使用,nodes near coords
您可以获得非常接近所需结果的图:
\documentclass{standalone}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=1.16}
\usetikzlibrary{intersections, positioning, calc, math}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=left, thick, grid=both,
width=0.8\textwidth, height=0.8\textwidth,
xmin=0,xmax=110, ymin=0,ymax=150, y=0.06cm,
xlabel={Upper Limits},
ylabel={Cumulative Frequency},
nodes near coords=,
]
\addplot[color = black,smooth,very thick,mark=*,name path=h1, scatter] coordinates {
(10,3)(20,7)(30,19)(40,37)(50,57)(60,82)(70,94)(80,102)(90,108)(100,110)
};
\legend{Less-Than type Ogive Curve}
\end{axis}
\end{tikzpicture}
您可以使用参数自定义创建的节点的内容nodes near coords
:
nodes near coords={
$(\pgfmathprintnumber{\pgfkeysvalueof{/data point/x}},
\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}})$
},
其中键/data point/x
和/data point/y
允许您访问数据点,并且命令\pgfmathprintnumber
格式化浮点数。