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.

This question was asked already here but not answered completely. I know of two approaches but they do not apply to my problem:

  1. ytick=data: In my example some of the tick labels will overlap.
  2. ytick={1000,...,6000}: Defining explicit ticks will cause problems when the data of each plot does not lie within the same range.

So my idea would be somelike the following:

ytick=NumOfTicks, whereas NumOfTicks can be any integer (e.g. ytick=5 would generate five ticks for every nextgrouplot).

Also interesting (but not applicable to my example) would be to write a macro which allows the following:

ytick={tickMin,tickMax,tJump}, whereas tJump can be any number (e.g. ytick={0,10000,2.5} would generate ticks starting at 0 and ending at 10000 with a space of 2.5 between each tick)

Note Changing the groupplot-argument footnotesize to any other size (e.g. small) also has an impact on the number of ticks when you leave the determination of the number of ticks to LaTeX.

Consider the following MWE:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}
\usetikzlibrary{pgfplots.groupplots}

\begin{document}


\begin{tikzpicture}
    \begin{groupplot}[
        group style={
            group name=my plots,
            group size=2 by 2,
            xlabels at=edge bottom,
            ylabels at=edge left,
    vertical sep= 1.5cm,
    horizontal sep= 2cm,
%   every axis y label/.style={at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel}
        },
        footnotesize,%changing footnotesize to small will affect the number of ticks
        width=5cm,
        height=5cm,
        %
        xlabel=xlabel,
        ylabel=very long label
%   ,ytick=data
]
    \nextgroupplot[title=\#1]
        \addplot coordinates{(42, 255) (43, 1584) (44, 1296) (45, 432) (46, 972) (47, 540) (48, 1104) (49, 0)};
    \nextgroupplot[title=\#2]
        \addplot coordinates{(42, 400) (43, 400) (44, 0) (45, 400) (46, 0) (47, 0) (48, 0) (49, 0)};
    \nextgroupplot[title=\#3]
        \addplot coordinates{(42, 1800) (43, 2100) (44, 1800) (45, 900) (46, 2100) (47, 2100) (48, 2100) (49, 0)};
    \nextgroupplot[title=\#4]
        \addplot coordinates{(42, 6800) (43, 2800) (44, 2800) (45, 2800) (46, 2000) (47, 2800) (48, 0) (49, 0)};
    \end{groupplot}
\end{tikzpicture}


\end{document}  
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Pgfplots has two parameters which control the selection of default ticks:

  1. max space between ticks
  2. try min ticks

The first parameter is the primary parameter, it is used to derive the number of ticks. If this number is below try min ticks, pgfplots increases the number.

Note that pgfplots only accepts specific tick locations, depending on the data range. For example, if the data range is [0,1500], if will not select 1250 as tick position (too detailed). If it does not find "suitable" tick positions, it will rather relax the parameter try min ticks than to select arbitrary numbers. In your example, it means that you will get either 4 or 5 ticks even though I requested try min ticks=5.

The overal solution here could be to set max space between ticks to some very huge value in the sense of "ignore this parameter" and force pgfplots to respect only the try min ticks argument:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}
\usetikzlibrary{pgfplots.groupplots}

\begin{document}


\begin{tikzpicture}
\begin{groupplot}[
group style={
    group name=my plots,
    group size=2 by 2,
    xlabels at=edge bottom,
    ylabels at=edge left,
    vertical sep= 1.5cm,
    horizontal sep= 2cm,
    %   every axis y label/.style={at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel}
},
    footnotesize,%changing footnotesize to small will affect the number of ticks
        max space between ticks=1000pt,
        try min ticks=5,
    width=5cm,
    height=5cm,
    %
    xlabel=xlabel,
    ylabel=very long label
    %   ,ytick=data
    ]
    \nextgroupplot[title=\#1]
        \addplot coordinates{(42, 255) (43, 1584) (44, 1296) (45, 432) (46, 972) (47, 540) (48, 1104) (49, 0)};
    \nextgroupplot[title=\#2]
        \addplot coordinates{(42, 400) (43, 400) (44, 0) (45, 400) (46, 0) (47, 0) (48, 0) (49, 0)};
    \nextgroupplot[title=\#3]
        \addplot coordinates{(42, 1800) (43, 2100) (44, 1800) (45, 900) (46, 2100) (47, 2100) (48, 2100) (49, 0)};
    \nextgroupplot[title=\#4]
        \addplot coordinates{(42, 6800) (43, 2800) (44, 2800) (45, 2800) (46, 2000) (47, 2800) (48, 0) (49, 0)};
    \end{groupplot}
\end{tikzpicture}


\end{document}  

enter image description here

Unfortunately, you can only set these parameters for all axes at once. Perhaps they should be configurable for individual axes.

Note that footnotesize also changes these parameters (as it ought to do).

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.