pgfplots 旋轉整個頁面而不是僅旋轉軸

pgfplots 旋轉整個頁面而不是僅旋轉軸

在 pgfplots 中產生長條圖時,我遇到一個奇怪的問題。在我的圖表中,我在 x 軸上有很多標籤,我嘗試使用命令將其旋轉 90 度xticklabel style={rotate=90,anchor=east}。問題是,這實際上導致頁面旋轉 90 度,而不是只是旋轉標籤。

作為一個最小的範例,請考慮我在背面運行的以下程式碼。

\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} 

數據.txt 檔案:

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

結果如下:

在此輸入影像描述

請注意,pdf 的整個頁面都顯示為旋轉的。您知道為什麼會發生這種情況以及如何解決它嗎?

先感謝您。

答案1

你只需要定義

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

xticklabel style={rotate=90,anchor=east}是假的。

\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}

在此輸入影像描述

相關內容