6

I am attempting to draw two plots in the same axis environment. Both plots use symbolic X coordinates (and symbolic Y coordinates) but X values that don't appear in the first plot will not make it into the final plot's X axis labels, i.e. those X coordinates that appear only in the 2nd plot will not get an X tick label.

How can I make those labels show up for all my symbolic X coordinates? Using xticklabels does not seem to do the trick.

missing x tick labels rendering
b2 and c2 should appear on the X axis, too.

\documentclass{standalone}

\usepackage{filecontents}
\usepackage{pgfplots, pgfplotstable}

\pgfplotsset{compat=1.9}
\begin{filecontents}{dataI.csv}
xitem,yitem,val
a1,X,0.1
a2,Y,0.5% adding this will make the a2 label appear, but I don't want this value. And using `nan` will be plotted as 0.
a1,Z,0.3
b1,Y,0.5
b1,Z,0.6
c1,X,0.8
\end{filecontents}
\begin{filecontents}{dataII.csv}
xitem,yitem,val
a2,X,0.1
b2,Y,0.5
b2,Z,0.6
c2,Y,0.8
c2,Y,0.7
\end{filecontents}

\pgfplotstableread[col sep=comma]{dataI.csv}\datatableI
\pgfplotstableread[col sep=comma]{dataII.csv}\datatableII

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    xtick=data, ytick=data, unbounded coords=jump,
    symbolic x coords={a1,a2,b1,b2,c1,c2}, symbolic y coords={X,Y,Z},
    xticklabels={a1,a2,b1,b2,c1,c2},% has no effect
    y dir=reverse, axis line style={draw=none}, tick style=transparent,
    y tick label style={inner sep=0, font=\tiny,},
    x tick label style={inner sep=0, font=\tiny, rotate=90, anchor=east,},
    enlarge x limits={abs=1mm}, enlarge y limits={abs=1mm},
    x=2mm, y=2mm,
]
\addplot[
    mark=square*, mark size=1mm, only marks, scatter, mark options={outer sep=0}, scatter/use mapped color={fill=mapped color,draw opacity=0},
    point meta=explicit,
] table [col sep=comma, x=xitem, y=yitem, meta expr=\thisrow{val},]{\datatableI};
\addplot[ mark=diamond*, mark size=1mm, only marks, scatter, mark options={outer sep=0}, scatter/use mapped color={fill=mapped color,draw opacity=0},
    point meta=explicit,
] table [col sep=comma, x=xitem, y=yitem, meta expr=\thisrow{val},
] {\datatableII};
\end{axis}
\end{tikzpicture}
\end{document}
derabbink
  • 1,640

1 Answers1

6

xtick=data only uses the first \addplot command for determining the tick positions. You can get the desired result by using xtick={a1,a2,b1,b2,c1,c2}:

Jake
  • 232,450