0

I would like the labels of the points in this figure:

\documentclass[tikz,margin=2mm]{standalone}

\usepackage[utf8]{inputenc} \usepackage{pgfplots} \usepackage{pgfplotstable}

\begin{document}

\begin{tikzpicture} \begin{axis}[enlargelimits=0.2, grid=both, grid style = {lightgray!45}, % xlabel = {Detection Precision}, % BX xlabel = {Punch Detection Accuracy}, % BR ylabel = {Clustering Accuracy}, % CB scale=1.3, % scale only axis=true, % legend style={at={(0.02,0.95)},anchor=north west}, % legend pos = south east, % legend cell align={left}, % xtick={0.6,0.65,...,1}, xmax=1, ] \addplot[ scatter/classes={a={blue}, b={red}}, scatter, mark=, only marks, scatter src=explicit symbolic, nodes near coords={\Label}, visualization depends on={value \thisrow{label} \as \Label} %<- added value ] table [meta=class] { x y class label 0.863 1 a S1 0.981 0.981 a S2 0.932 0.833 a S3 0.947 0.947 a S4 0.91 0.989 a S5 0.875 0.982 a S6 0.972 0.921 a S7 0.833 0.882 a S8 0.649 0.787 a S9 0.816 0.816 a S10 0.615 0.615 a S11 0.942 0.98 a S12 };

% Linear regression
\addplot[
    thick,
    red
] table[
    x = BR,
    y = {create col/linear regression={y=CB}}
] {result.dat};


\end{axis} \end{tikzpicture}

\end{document}

enter image description here

not to overlap, e.g., S1, S6, S4.

and the result.dat file is a text file with this content:

BR  CB
0.863   1
0.981   0.981
0.932   0.833
0.947   0.947
0.91    0.989
0.875   0.982
0.972   0.921
0.833   0.882
0.649   0.787
0.816   0.816
0.615   0.615
0.942   0.98

I have tried to scale the plot, which separates de points. However, the figure becomes smaller (font sizes become small) and looks worse.

I would like to reduce the font size of the point label or move the label around the point and make the figure clearer to appear in one column of a two-column page.

user1993416
  • 1,046

1 Answers1

3

One solution can be write nodes of marks "S4" and "S6" below them:

enter image description here

For clarity of suggestion are nodes S4 and S6 as well their marks, colored. In real document this colors can/should be removed.

\RequirePackage{filecontents}
\begin{filecontents}{result.dat}
    BR      CB
    0.863   1
    0.981   0.981
    0.932   0.833
    0.947   0.947
    0.91    0.989
    0.875   0.982
    0.972   0.921
    0.833   0.882
    0.649   0.787
    0.816   0.816
    0.615   0.615
    0.942   0.98
\end{filecontents}

\documentclass[tikz,margin=2mm]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{pgfplotstable}

\begin{document} \begin{tikzpicture} \begin{axis}[ grid, grid style = {lightgray!45}, enlargelimits={0.1, upper}, xlabel = {Punch Detection Accuracy}, % BR ylabel = {Clustering Accuracy}, % CB tick label style = {font=\small}, xmin=0.6, ymin=0.6, % scatter, mark=, scatter/classes={a={blue}, b={teal}}, scatter src=explicit symbolic, nodes near coords style = {font=\scriptsize, inner xsep=-1pt} % nodes near coords={\Label}, visualization depends on={value \thisrow{label} \as \Label}, ] \addplot[ nodes near coords style = {text=blue, anchor=south west},% in real doc. remove text color only marks ] table [meta=class] { x y class label 0.863 1 a S1 0.981 0.981 a S2 0.932 0.833 a S3 % 0.947 0.947 a S4 0.91 0.989 a S5 % 0.875 0.982 a S6 0.972 0.921 a S7 0.833 0.882 a S8 0.649 0.787 a S9 0.816 0.816 a S10 0.615 0.615 a S11 0.942 0.98 a S12 }; \addplot[ nodes near coords style = {text=teal, anchor=north east},% in real doc. remove text color only marks ] table [meta=class] { x y class label 0.947 0.947 b S4 0.875 0.982 b S6 }; %%%% Linear regression \addplot[thick, red, no marks] table[ x = BR, y = {create col/linear regression={y=CB}} ] {result.dat}; \end{axis} \end{tikzpicture} \end{document}

Zarko
  • 296,517