Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to add minor yticks on my axis based on the end values of a ybar stacked plot. Here is where I'm at:

\documentclass[tikz]{standalone}
\usepackage{pgfplotstable}
\pgfplotstableread{
Year    Far           Near      Sd
2012    1.7786e+01    31.762    88
2013    6.2690e+01    153.828   48
2014    2.9644e+01    25.0714   13
}\datatableD
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ymin=0,
    enlarge x limits=0.15,
    enlarge y limits={upper, value=0.15},
    ybar stacked, bar width=1.5em,
    point meta=explicit,
    xtick=data,
    every node near coord/.style={
        yshift=6pt
    },
    nodes near coords align=center,
    yticklabel style={xshift=-10pt},
    minor ytick=data,
    grid = minor
]
\addplot table [y=Far] \datatableD;
\addplot table [y=Near] \datatableD;
\addplot[nodes near coords*={\footnotesize $(\pgfmathprintnumber\pgfplotspointmeta)$}, white, color=black, draw=none] table [y expr=0, meta=Sd] \datatableD;
\end{axis}
\end{tikzpicture}
\end{document}

Unfortunately, it looks like minor ytick=data returns a list of values from the column Far, but not for the sum Far + Near, any ideas ?

In the MWE, 3 minor ticks are added for y = 17, 29, 62. I would need the minor ticks to be added at y = 17 + 31, 29 + 25, 62 + 153 instead.

share|improve this question
    
Would you mind showing a mock-up of your desired final result? Thanks! –  Alenanno Oct 17 '13 at 9:33
    
I edited the original post, I hope it is more clear now. –  BigDawg Oct 17 '13 at 9:39
add comment

1 Answer

I can give a statement to explain the issue. Others may contribute work-arounds.

By design, minor ytick=data results in tick labels for y coordinates of the first plot (only).

While this is reasonable for normal plots, it is ... unexpected (and perhaps wrong) for stacked plots.

Nevertheless, you need to create the list of required tick labels manually; the magic value data is of no use in this context.

I'll take a note on my todo list for pgfplots to reconsider ytick=data in stacked plots.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.