15

How can I show xaxis labels for every second data in this dataset. I want a bar for each tick, but not a label.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{filecontents}% http://ctan.org/pkg/filecontents
\usepackage{silence}% http://ctan.org/pkg/silence
\WarningFilter{latex}{Overwriting file}% Remove LaTeX warnings starting with "Overwriting file"
\begin{filecontents*}{data.csv}
_MINPT_,_OBSPCT_
0,99.198665453
10,11.622687291
20,7.279344859
30,4.6982104944
40,3.4728541098
50,1.5862905672
60,2.0837124659
70,1.0433727631
80,1.313315135
90,0.8462238399
100,0.7703973309
110,0.5125872005
120,0.8826205641
130,0.4458598726
140,0.4185623294
150,0.4519259933
160,0.5065210798
170,0.2183803458
180,0.3973309069
190,0.2274795268
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar interval,
    enlarge x limits=false,
    xmin=0.1,ymax=100,ymin=0.1,
    xtick=data
]
\addplot+ table [x, y, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}

I don't want to manually specify the xticks because I've a series of histograms to produce! The last observation (190) is also missing. How can I ensure it's included?

1
  • so you don't want something like, xtick={0,20,...,180} and would prefer something like xtick=<every other point>?
    – cmhughes
    Commented Feb 22, 2014 at 20:03

1 Answer 1

5

I gave it a try. I set minor xtick to draw all the missing ticks and set several values, esp. xmin, x upper limit+5, ymin and ymax. Upper limits for major and minor xticks are set to a huge number to be able to draw all the necessary ticks. I preferred basic ybar graph over ybar interval, it saved me some time during setting parameters.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{filecontents}
\usepackage{silence}\pagestyle{empty}
\WarningFilter{latex}{Overwriting file}
\begin{filecontents*}{data.csv}
_MINPT_,_OBSPCT_
0,99.198665453
10,11.622687291
20,7.279344859
30,4.6982104944
40,3.4728541098
50,1.5862905672
60,2.0837124659
70,1.0433727631
80,1.313315135
90,0.8462238399
100,0.7703973309
110,0.5125872005
120,0.8826205641
130,0.4458598726
140,0.4185623294
150,0.4519259933
160,0.5065210798
170,0.2183803458
180,0.3973309069
190,0.2274795268
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  ybar,
  enlarge x limits={abs value=5, upper}, 
  enlarge y limits=false, 
  xmin=-5, ymax=100, ymin=0,
  xtick pos=left, ytick pos=left,
  grid=both, ymajorgrids=false,
  minor xtick={10, 30, ..., 1000},
  xtick={0, 20, ..., 1000},
  x tick label style={black},
  width=10cm, height=7cm,
 ] \addplot+ table [x, y, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .