# Customizing a point label style

There are some points labels that overlap on one another if the points were near an axis or close to one another, because the table is relatively long to be written horizontally.

How can I writ a point label like 1A,B2,C3,D4 above a point vertically, such that 1A comes above B2 which comes above C3, etc. So that labels do not overlap even. (Assumption: in this figure points cannot come above one another)

Here is how the label showed appear above a point.

\documentclass{IEEEtran}
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{%
pointStyle/.style args={#1}{%
color=#1,
mark=*,
only marks,
mark size=4pt,
point meta=explicit symbolic,
}
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line = bottom,
axis y line = left,
scaled y ticks = false,
enlarge x limits=0.1,
nodes near coords,
]

coordinates {(1, 4) [\footnotesize{1A,B2,C3,D4}]};
coordinates {(2, 9) [\footnotesize{1A}]};
coordinates {
(3, 6) [\footnotesize{1A,B2,C3}]
(2.9, 6) [\footnotesize{4A,B,C3}]
};
\end{axis}
\end{tikzpicture}
\end{document}


You could make the anchor a function of the \coordindex. 2nd EDIT: The simplest option in my opinion is if you do the line breaks yourself, i.e. replace the commas by \\. If you think the nodes are too tight, you could increase outer sep (for instance).

\documentclass{IEEEtran}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{%
pointStyle/.style args={#1}{%
color=#1,
mark=*,
only marks,
mark size=4pt,
point meta=explicit symbolic,
}
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line = bottom,
axis y line = left,
scaled y ticks = false,
enlarge x limits=0.1,
nodes near coords={\pgfplotspointmeta\vspace*{0.3\baselineskip}},
nodes near coords style={font=\footnotesize,anchor=-90,
align=left
},
%nodes near coords align={vertical},
]

coordinates {(1, 4) [1A\\ B2\\ C3\\ D4]};
coordinates {(2, 9) [1A]};
anchor=-90+180*\coordindex,
}]
coordinates {
(3, 6) [1A\\ B2\\ C3]
(2.9, 6) [4A\\ B\\ C3]
};
\end{axis}
\end{tikzpicture}
\end{document}


Everything else is much more hacky.

1st EDIT: Sorry, I was confused by the question, hope it is closer to what you want.

\documentclass{IEEEtran}
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{%
pointStyle/.style args={#1}{%
color=#1,
mark=*,
only marks,
mark size=4pt,
point meta=explicit symbolic,
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line = bottom,
axis y line = left,
scaled y ticks = false,
enlarge x limits=0.1, % \begin{tabular}\end{tablue}
nodes near coords={\vspace*{0.1\baselineskip}
\foreach \X [count=\Y] in \pgfplotspointmeta
{\X\newline} \vspace*{-0.7\baselineskip}
},
nodes near coords style={font=\footnotesize,anchor=-90,text
width=4mm,align=center,},
%nodes near coords align={vertical},
]

coordinates {(1, 4) [1A,B2,C3,D4]};
coordinates {(2, 9) [1A]};
anchor=-90+180*\coordindex,
}]
coordinates {
(3, 6) [1A,B2,C3]
(2.9, 6) [4A,B,C3]
};
\end{axis}
\end{tikzpicture}
\end{document}


In order to center the texts, you may do

\documentclass{IEEEtran}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{%
pointStyle/.style args={#1}{%
color=#1,
mark=*,
only marks,
mark size=4pt,
point meta=explicit symbolic,
}
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line = bottom,
axis y line = left,
scaled y ticks = false,
enlarge x limits=0.1,
nodes near coords={\vspace*{0.1\baselineskip}
\foreach \X in \pgfplotspointmeta%
{\centerline{\X}\newline}%
\vspace*{-0.7\baselineskip}
},
nodes near coords style={font=\footnotesize,anchor=-90,
text width=1cm
},
%nodes near coords align={vertical},
]

coordinates {(1, 4) [1A,B2,C3,D4]};
coordinates {(2, 9) [1A]};
anchor=-90+180*\coordindex,
}]
coordinates {
(3, 6) [1A,B2,C3]
(2.9, 6) [4A,B~~,C3]
};
\end{axis}
\end{tikzpicture}
\end{document}


If you want everything centered, remove the ~~ after B. It is amazing how much hackery is required here, basically because one cannot easily have a \\ inside a \foreach loop. There are ways to avoid this, e.g. here but they are fairly complicated and, in what I tried, destroyed the coloring, and so does trivlist. Crazy...

• Well, but in my case, I want the labels to be written vertically above the point like the second picture I have attached. Your solution is little bit confusing because I don't know which label belongs to which point in the two blue points. An other thing the purple point label overlap the x-axis. – Taha Magdy Sep 4 '18 at 1:04
• @TahaMagdy Better now? – user121799 Sep 4 '18 at 1:37
• @marmort, there is a small issue though, the vertical label lines are aligned to the left; how can I make every line centered. Here is a image – Taha Magdy Sep 4 '18 at 2:06
• @TahaMagdy I added a few options. The top one would be my personal favorite. You can finetune parameters like outer seo in order to shift the text around. – user121799 Sep 4 '18 at 2:47
• My question is completely solved now. Thank You @marmot – Taha Magdy Sep 4 '18 at 2:57