I'm using the dynamic dict from mail-archive.com
It generates automatically the data for the x axis.
I want only every second (or every third, …) tick and grid line. I've already managed to omit the labels for the ticks, but the grid lines are still there :/
Here's the MWE:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{ifthen}
\usepackage{intcalc}
\newcount\kencounter
\global\kencounter=0
\global\def\xdata{}
\pgfplotsset{
dynamic dict fewerticks/.style={
x coord trafo/.code={%
\pgfkeysifdefined{/ken/key ##1}{%
\pgfkeysgetvalue{/ken/key ##1}\pgfmathresult%
}{%
\ifthenelse{\equal{\intcalcMod{\the\kencounter}{#1}}{0}}{
\ifthenelse{\equal{\xdata}{}}
{\global\edef\xdata{##1}}
{\global\edef\xdata{\xdata,##1}}
}{}
\edef\pgfmathresult{\the\kencounter}%
\global\pgfkeyslet{/ken/key ##1}\pgfmathresult
\global\pgfkeyslet{/ken/key no \pgfmathresult}{##1}%
\global\advance\kencounter by 1
}%
},
x coord inv trafo/.code={%
\pgfmathint{##1}%
\pgfkeysifdefined{/ken/key no \pgfmathresult}{%
\pgfkeysgetvalue{/ken/key no \pgfmathresult}\pgfmathresult%
}{%
\PackageError{pgfplots}{Inverse trafo for \pgfmathresult\space failed: no such key!}{}%
}%
},
xticklabel={\ifthenelse{\equal{\intcalcMod{\ticknum}{#1}}{0}}{\tick}{}},
scaled x ticks=false,
plot coordinates/math parser=false
},
}
\begin{document}
My tries:
\begin{tikzpicture}%
\begin{axis}[width=7cm,dynamic dict fewerticks=2,grid=major, xtick=data,ylabel={\xdata}]%
\addplot coordinates { (1M,2) (2M,4) (3M,6) };
\end{axis}%
\end{tikzpicture}
%
\begin{tikzpicture}%
\begin{axis}[width=7cm,dynamic dict fewerticks=2,grid=major, xtick={1M,3M},ylabel={\xdata}]%
\addplot coordinates { (1M,2) (2M,4) (3M,6) };
\end{axis}%
\end{tikzpicture}
\vspace{1cm}How it should look like (ignore the missing M):\vspace{1cm}
\begin{tikzpicture}%
\begin{axis} [width=7cm,grid=major,xtick={1,3}]%
\addplot coordinates { (1,2) (2,4) (3,6) };
\end{axis}%
\end{tikzpicture}%
\end{document}
and why doesn't the upper right picture show the label "3M"?
Best Answer
This doesn't directly solve this question, but it solved my problem: I wanted a x axis with buffer sizes and units (B, KiB, MiB, GiB). For this the dynamic axis style worked, but there is a better solution: