LaTeX forum ⇒ Graphics, Figures & Tablespgfplots : symbolic coordinates not displayed

Information and discussion about graphics, figures & tables in LaTeX documents.
cyrlang
Posts: 5
Joined: Fri Jul 27, 2012 6:49 pm

pgfplots : symbolic coordinates not displayed

Postby cyrlang » Mon Jun 04, 2018 10:35 pm

Hello,

I'm trying to draw a plot using pgfplots with symbolic x coordinates and y data, as explain in the pgfplots manual. My Tex installation is the latest MacTeX 2018. The plot is quite good, except for the x coordinates, where only the first one is drawn. If I change the order of the \addplot commands, only the first one has it x label on the x-axis.
I don't see where's the problem. Could it be a bug in pgfplots ?

Thanks for help,
Cyril
  1. \usepackage[usenames,svgnames]{xcolor}
  2. \usepackage{pgf,tikz}
  3. \usepackage{pgfplots,pgfplotstable}
  4.  
  5. %%%%%%%%%
  6. \begin{document}
  7. %%
  8. \begin{figure}[!htbp]
  9. \begin{center}
  10. \centering
  11. \begin{tikzpicture}[scale=1]
  12. \centering
  13. \begin{axis}[width=0.8\textwidth,symbolic x coords={Fr,Hr,Fb,Hb}, xtick=data, yticklabel style={/pgf/number format/.cd,fixed,precision=5}, ylabel={\ce{^{87}Sr/^{86}Sr}},ylabel near ticks]
  14. % Femmes, époque romaine
  15. \addplot[red,only marks] coordinates {
  16. (Fr,0.70831)
  17. (Fr,0.708065)
  18. (Fr,0.70814)
  19. (Fr,0.708238)
  20. (Fr,0.708198)
  21. (Fr,0.708189)
  22. };
  23. % Hommes, époque romaine
  24. \addplot[blue,only marks,mark=square*] coordinates {
  25. (Hr,0.708289)
  26. (Hr,0.708189)
  27. };
  28. % Hommes, époque byzantine
  29. \addplot[SteelBlue,only marks,mark=square*] coordinates {(Hb,0.707382) (Hb,0.707977) (Hb,0.708635) (Hb,0.709092) (Hb,0.708234) (Hb,0.711956) (Hb,0.707212) (Hb,0.707306) (Hb,0.707501) (Hb,0.707566) (Hb, 0.708286) (Hb, 0.708396) (Hb,0.708467) (Hb,0.708853) (Hb,0.710657) (Hb, 0.714964)} ;
  30. % Femmes,époque byzantine
  31. \addplot[DarkRed,only marks] coordinates {(Fb, 0.707421) (Fb, 0.707988) (Fb,0.708305) (Fb,0.707244) (Fb,0.707246) (Fb,0.70732) (Fb,0.708023) (Fb,0.708176) (Fb,0.708206) (Fb,0.708439) (Fb,0.709156) (Fb,0.709572)} ;
  32. \end{axis}
  33. \end{tikzpicture}
  34. \caption{Valeurs isotopiques du strontium obtenues sur les dents de squelettes exhumés dans les tombes de Hiérapolis, par époque et par sexe.}
  35. \label{Hierapolis-Sr-2b}
  36. \end{center}
  37. \end{figure}
  38. %%%%%%%%%
  39. \end{document}

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 8905
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Tue Jun 05, 2018 3:01 pm

Hi Cyril!

pgfplots takes the symbolic x coordinates of (only) the first plot as labels. So either have a first plot that uses all symbolic x coordinates, or (maybe easier) add a dummy plot that prints nothing (such as color white) with an y value that doesn't affect the y range.

For example, right before the other \addplot commands:

  1. \newcommand{\dummy}{0.715}% some value in the y range
  2. \addplot [white,only marks] coordinates {
  3. (Fr,\dummy) (Hr,\dummy) (Hb,\dummy) (Fb,\dummy)
  4. };


Sztefan
Site admin


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 1 guest