3

I want to obtain the figure as

enter image description here

Could you suggest to me the way to draw it? Thanks so much. Note that, the circle is a point (x,y).

Update: This is a simple data set for points(x,y)

(3,3.2)
(4,3.8)
(4,4.5)
(5,5.1)
(5.5,5.6)
(5.3,5.8)
(6.3,5.8)
(7, 7.4)
(7.3, 7.5)
(8.3, 8.5)
(9, 8.5)
(10, 11.0)
(11, 11.5)
(11.2, 11.6)
(11.5, 11.9)
(12.5, 12.9)
(13.5, 13.1)
(14, 13.8)
(15, 15.3)
(16, 16.5)
(17, 17.2)
(18, 18.4)
(19, 19.1)

This is my code based on suggestions:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xlabel=Weight (kg), % label x axis
ylabel=Height (cm), % label y axis
axis lines=left, %set the position of the axes
xmin=0, xmax=20, % set the min and max values of the x-axis
ymin=0, ymax=20, % set the min and max values of the y-axis
clip=false
]
\addplot[only marks,mark=o] coordinates {(3,3.2) (4,3.8) (4,4.5) (5,5.1) (5.5,5.6) (5.3,5.8) (6.3,5.8) (7, 7.4) (7.3, 7.5) (8.3, 8.5) (9, 8.5) (10, 11.0) (11, 11.5) (11.2, 11.6) (11.5, 11.9) (12.5, 12.9) (13.5, 13.1) (14, 13.8) (15, 15.3) (16, 16.5) (17, 17.2) (18, 18.4) (19, 19.1)};
\addplot [only marks] table {\loadedtable};
\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

marked as duplicate by Martin Scharrer tikz-pgf Jul 24 '18 at 5:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @percusse: I have updated dataset – Jame Jul 23 '18 at 7:05
  • Thanks percusse. I have read your post but it is different. In my case, I draw the circle points from dataset and the line is y=x – Jame Jul 23 '18 at 7:09
  • 1
    \addplot [samples at={0,20}] {x}; – Torbjørn T. Jul 23 '18 at 7:15
  • ... and to get the circles you could do \addplot[only marks,mark=o] coordinates {(3,3.2) (4,3.8) (4,4.5) (5,5.1) (5.5,5.6) (5.3,5.8) (6.3,5.8) (7, 7.4) (7.3, 7.5) (8.3, 8.5) (9, 8.5) (10, 11.0) (11, 11.5) (11.2, 11.6) (11.5, 11.9) (12.5, 12.9) (13.5, 13.1) (14, 13.8) (15, 15.3) (16, 16.5) (17, 17.2) (18, 18.4) (19, 19.1)};... – user121799 Jul 23 '18 at 7:22
  • Great. So. where is the line y=x? Thanks – Jame Jul 23 '18 at 7:24
3

\addplot [samples at={0,20}] {x}; gives you a black line for y=x from x=0 to x=20.

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
xlabel=Weight (kg), % label x axis
ylabel=Height (cm), % label y axis
axis lines=left, %set the position of the axes
xmin=0, xmax=20, % set the min and max values of the x-axis
ymin=0, ymax=20, % set the min and max values of the y-axis
]
\addplot[only marks,mark=o] coordinates {(3,3.2) (4,3.8) (4,4.5) (5,5.1) (5.5,5.6) (5.3,5.8) (6.3,5.8) (7, 7.4) (7.3, 7.5) (8.3, 8.5) (9, 8.5) (10, 11.0) (11, 11.5) (11.2, 11.6) (11.5, 11.9) (12.5, 12.9) (13.5, 13.1) (14, 13.8) (15, 15.3) (16, 16.5) (17, 17.2) (18, 18.4) (19, 19.1)};
\addplot [samples at={0,20}] {x};
\end{axis}

\end{tikzpicture}
\end{document}

Not the answer you're looking for? Browse other questions tagged or ask your own question.