0

I'm facing a weird problem when generating a bar chart in pgfplots. In my chart I have a lot of labels in the x axis, which I try to rotate 90 degrees using the command xticklabel style={rotate=90,anchor=east}. The problem is that, instead of only rotating the labels, this actually results in the page being rotated 90 degrees.

As a minimal example, consider the following code that I ran in overleaf.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\usepgfplotslibrary{statistics}

\begin{document}

\pgfplotsset{width=12cm, height=10cm}
\begin{figure}[htb!]
    \centering
    \begin{tikzpicture}
        \begin{axis}
            [
                axis y line=left,
                axis x line*=bottom,
                ymajorgrids,
                ymax = 35,
                ymin=0,
                xmin= 0,
                xmax=10,
                x tick label style={font=\tiny},
                xtick align=outside,
                xtick=data,
                xticklabels from table={data.txt}{group},
                xticklabel style={rotate=90,anchor=east}
            ]

            \addplot+[
                ybar,
                bar width=3pt,
                mark=none,
                color=blue,
                fill=blue
            ] table[x=id,y=val] {data.txt};
        \end{axis}

    \end{tikzpicture}
    \caption{Caption}
    \label{fig:label}
\end{figure}

\end{document} 

The data.txt file:

id  group    val
1   DSDSJ   26.0
2   ABSDS   26.0
3   BB      31.0
4   CCCCC   25.0
5   DDDDS   21.0
6   DDDDD   19.0
7   DDDDD   19.0
8   DDDDD   19.0

This results in the following:

enter image description here

Note that the whole page of the pdf is displaying rotated. Do you have any idea of why this is happening and how to fix it?

Thank you in advance.

1

you need to define only

  x tick label style={font=\tiny,rotate=90,anchor=east},

the xticklabel style={rotate=90,anchor=east} is false.

\RequirePackage{filecontents}
    \begin{filecontents}{data.dat}
id  group    val
1   DSDSJ   26.0
2   ABSDS   26.0
3   BB      31.0
4   CCCCC   25.0
5   DDDDS   21.0
6   DDDDD   19.0
7   DDDDD   19.0
8   DDDDD   19.0
    \end{filecontents}

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\usepgfplotslibrary{statistics}

\begin{document}

\pgfplotsset{width=12cm, height=10cm}
\begin{figure}[htb!]
    \centering
    \begin{tikzpicture}
        \begin{axis}
            [
                axis y line=left,
                axis x line*=bottom,
                ymajorgrids,
                ymax = 35,
                ymin=0,
                xmin= 0,
                xmax=10,
                x tick label style={font=\tiny,rotate=90,anchor=east},
                xtick align=outside,
                xtick=data,
                xticklabels from table={data.dat}{group},
             ]

            \addplot+[
                ybar,
                bar width=3pt,
                mark=none,
                color=blue,
                fill=blue
            ] table[x=id,y=val] {data.dat};
        \end{axis}

    \end{tikzpicture}
    \caption{Caption}
    \label{fig:label}
\end{figure}

\end{document}

enter image description here

  • I ran your code on overleaf and I still get the same result. However I noticed something interesting. If I compile using pdflatex it works and I get the expected result, but If I use Latex -> dvips -> ps2pdf (which is what I need because of other things in my document) it still rotates the whole page. Any insights? – BrunoB Feb 18 at 17:20
  • @BrunoB, natural way for compiling is pdflatex or xelatex. your route usualy make problems as you reported. problems is dvi which is not able to correct render images (my dvi not rotate page but screw-up image completely). i do not see any reasons that you should stick to route latex -- dvips -- ps2pdf. all can be done with pdflatex (as far as know). – Zarko Feb 18 at 17:30
  • Hm, I changed to XeLatex and it also works, thanks! – BrunoB Feb 18 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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