Graphics, Figures & Tablespgfplots | Missing Bar in Barplot

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
heartlet
Posts: 3
Joined: Sat Jul 21, 2012 10:53 am

pgfplots | Missing Bar in Barplot

Post by heartlet »

Hi again everybody, sorry to be a pain.

I was just curious if you can set up a bar graph with the xbar labels the name of the month.

My code works, however it is missing the last month (december) it could be a scaling problem but I do not think so. xmax=20 doesn't make the last numbers come up. It just scales the graph to about half (as 11/20 is almost half)

The file contains
Month Rain
January 22
... ...

But the problem is not with the file. I get the same problem with the following:

\addplot coordinates {(1,1)(2,2)(3,3)(4,4)(5,5)(6,6)(7,7)(8,8)(9,9)(10,10)(11,11)(12,12)};

Here is my code anyway, I commented out the words to make it easier.

Code: Select all

\begin{tikzpicture}[scale=1.5]
\begin{axis}[ybar, bar width=1, x tick label style={rotate=90}, ybar interval=1]
\addplot table [x=Month, y=Rain, col sep=comma] {data/AverageClimate.csv};
\addplot table[x=Month, y=Evaporation, col sep=comma] {data/AverageClimate.csv};
\end{axis}
\end{tikzpicture}

%symbolic x coords={February, March, April, May, June, July, August, September, October, November, December}
%xtick=data
 
I tried xmax=20

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

heartlet
Posts: 3
Joined: Sat Jul 21, 2012 10:53 am

Re: pgfplots | Missing Bar in Barplot

Post by heartlet »

Okay figured it out. I added a fake data at the end in which it skips.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pgfplots | Missing Bar in Barplot

Post by localghost »

It works better if you just drop the ybar interval option and let the xtick specification do the job.

Code: Select all

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      ybar,
      bar width=10pt,
      x tick label style={rotate=90},
      symbolic x coords={January,February,March,April,May,June,July,August,September,October,November,December},
      xtick=data
    ]
      \addplot coordinates {
        (January,22)
        (February,31)
        (March,46)
        (April,29)
        (May,53)
        (June,17)
        (July,9)
        (August,18)
        (September,34)
        (October,48)
        (November,59)
        (December,71)
      };
%      \addplot coordinates {(1,1)(2,2)(3,3)(4,4)(5,5)(6,6)(7,7)(8,8)(9,9)(10,10)(11,11)(12,12)};
%      \addplot table [x=Month, y=Rain, col sep=comma] {data/AverageClimate.csv};
%      \addplot table[x=Month, y=Evaporation, col sep=comma] {data/AverageClimate.csv};
    \end{axis}
  \end{tikzpicture}
\end{document}
Attachments
The obtained output.
The obtained output.
pgfplots-barplot.png (9.93 KiB) Viewed 5283 times
Post Reply