TikZ/PGFPlots:避免在 x 轴上缩放超过 99,999 的数字

TikZ/PGFPlots:避免在 x 轴上缩放超过 99,999 的数字

使用以下代码,x 轴上的数字开始缩放超过 99,999 的值。

\documentclass[border=1mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        xbar, 
        xmin=0,
        width=10cm,
        height=7cm,
        %enlarge y limits=0.5,
        xlabel={Datensätze},
        %ylabel={Unternehmen},
        symbolic y coords={Commerzbank,Fraport,Gazprom,Tesla,Apple,Microsoft,Berkshire Hathaway,Deutsche Bank},
        ytick=data,
        nodes near coords,
        nodes near coords align={horizontal},
        legend style={at={(0.5,-0.2)},anchor=north, legend columns=-1},
        x tick label style={rotate=45,anchor=east},
        scaled x ticks=false,
        %xtick={0,25000,...,125000},
        xmax=150000,
        xtick align=outside,
        ]
        \addplot coordinates{
            (14587,Deutsche Bank)
            (10464,Berkshire Hathaway)
            (22842,Microsoft)
            (117851,Apple)
            (59088,Tesla)
            (8127,Gazprom)
            (2822,Fraport)
            (2345,Commerzbank)
        };
    \end{axis}
\end{tikzpicture}

\end{document}

生成此输出。

输出

启用xtick={0,25000,...,150000},将导致错误I can't work with sizes bigger than about 19 feet.

您是否对此有任何想法,以防止 x 轴和图内的缩放?非常感谢您的帮助。

答案1

如果你想实现排版为

xtick={0,25000,...,150000},

您可以使用

xticklabel style={/pgf/number format/fixed},

避免使用这样的10^...符号,

xtick distance=25000,

将后续 x 刻度之间的距离设置为25000

\documentclass[border=1mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        xbar, 
        xmin=0,
        width=10cm,
        height=7cm,
        %enlarge y limits=0.5,
        xlabel={Datens\"atze},
        %ylabel={Unternehmen},
        symbolic y coords={Commerzbank,Fraport,Gazprom,Tesla,Apple,Microsoft,Berkshire Hathaway,Deutsche Bank},
        ytick=data,
        nodes near coords,
        nodes near coords align={horizontal},
        legend style={at={(0.5,-0.2)},anchor=north, legend columns=-1},
        x tick label style={rotate=45,anchor=east},
        scaled x ticks=false,
        xticklabel style={/pgf/number format/fixed},
        xtick distance=25000,
        %xtick={0,25000,...,125000},
        xmax=150000,
        xtick align=outside,
        ]
        \addplot coordinates{
            (14587,Deutsche Bank)
            (10464,Berkshire Hathaway)
            (22842,Microsoft)
            (117851,Apple)
            (59088,Tesla)
            (8127,Gazprom)
            (2822,Fraport)
            (2345,Commerzbank)
        };
    \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

nodes near coords如果你还想将这些样式应用于

xticklabel style={/pgf/number format/fixed},
nodes near coords style={/pgf/number format/fixed},

或者直接设置

/pgf/number format/fixed

在轴上全局。

\documentclass[border=1mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        xbar, 
        xmin=0,
        width=10cm,
        height=7cm,
        %enlarge y limits=0.5,
        xlabel={Datens\"atze},
        %ylabel={Unternehmen},
        symbolic y coords={Commerzbank,Fraport,Gazprom,Tesla,Apple,Microsoft,Berkshire Hathaway,Deutsche Bank},
        ytick=data,
        nodes near coords,
        nodes near coords align={horizontal},
        legend style={at={(0.5,-0.2)},anchor=north, legend columns=-1},
        x tick label style={rotate=45,anchor=east},
        scaled x ticks=false,
        /pgf/number format/fixed,
        xtick distance=25000,
        %xtick={0,25000,...,125000},
        xmax=150000,
        xtick align=outside,
        ]
        \addplot coordinates{
            (14587,Deutsche Bank)
            (10464,Berkshire Hathaway)
            (22842,Microsoft)
            (117851,Apple)
            (59088,Tesla)
            (8127,Gazprom)
            (2822,Fraport)
            (2345,Commerzbank)
        };
    \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容