Graphics, Figures & Tablespgfplots : symbolic coordinates not displayed

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

pgfplots : symbolic coordinates not displayed

Post by cyrlang »

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

Code: Select all

\usepackage[usenames,svgnames]{xcolor}
\usepackage{pgf,tikz}
\usepackage{pgfplots,pgfplotstable}

%%%%%%%%%
\begin{document}
%%
\begin{figure}[!htbp]
\begin{center}
    \centering
    \begin{tikzpicture}[scale=1]
    \centering
        \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]     
    % Femmes, époque romaine
        \addplot[red,only marks] coordinates {
        (Fr,0.70831) 
        (Fr,0.708065) 
        (Fr,0.70814) 
        (Fr,0.708238) 
        (Fr,0.708198) 
        (Fr,0.708189)
        };   
       % Hommes, époque romaine   
        \addplot[blue,only marks,mark=square*] coordinates {
        (Hr,0.708289) 
        (Hr,0.708189)
        };
       % Hommes, époque byzantine        
        \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)} ;    
    % Femmes,époque byzantine    
        \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)} ;                               
        \end{axis}
    \end{tikzpicture}
\caption{Valeurs isotopiques du strontium obtenues sur les dents de squelettes exhumés dans les tombes de Hiérapolis, par époque et par sexe.}
\label{Hierapolis-Sr-2b}
\end{center}
\end{figure}
%%%%%%%%%
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

pgfplots : symbolic coordinates not displayed

Post by Stefan Kottwitz »

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:

Code: Select all

\newcommand{\dummy}{0.715}% some value in the y range
\addplot [white,only marks] coordinates {
  (Fr,\dummy) (Hr,\dummy) (Hb,\dummy) (Fb,\dummy)
};
Sztefan
LaTeX.org admin
Post Reply