pgfplots 條形圖編號格式

pgfplots 條形圖編號格式

我只是想使用 pgfplots 將一些資料編譯成長條圖。事情似乎與以下情況不同:條形的註釋精度較低,即只有 3 位小數,顯示為“1.02 \cdot 10^6”。有沒有辦法將其更改為實際值(1022641)?

\begin{tikzpicture}
    \begin{axis}[
    xbar, xmin=500000,
    width=12cm,enlarge y limits=0.5,
    xlabel={Travel time [s]},
    symbolic y coords={hello},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    ]

    \addplot coordinates {(1022641,hello)};
    \end{axis}
\end{tikzpicture}

答案1

好吧,我最終做了以下事情:我首先在實際之外定義了一個樣式\tikzpicture

\pgfplotsset{
    default style/.style={
    xbar, xmin=0,
    width=12cm,enlarge y limits=0.5,
    xlabel={Travel time [s]},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    every node near coord/.append style={/pgf/number format/.cd, fixed,1000 sep={}}
    }
}

其中包含 percusse 和 Jake 建議的修改。實際繪圖使用定義的樣式:

\begin{tikzpicture}
    \begin{axis}[
    default style,
    symbolic y coords={hello}
    ]

    \addplot coordinates {(1022641,hello)};
    \end{axis}
\end{tikzpicture}

這樣樣式和資料就解耦了,而且樣式是可重複使用的。

相關內容