y 刻度样式:科学计数法

y 刻度样式:科学计数法

10^3对 Y 轴的每个数字重复,如何删除10^3并在 Y 轴顶部添加一次。

enter image description here

\documentclass{article}
\usepackage{pgfplots}


\begin{document}

\begin{tikzpicture}
    \begin{axis}[
            symbolic x coords={X1, X2, X3, X4},
            xtick=data,
            ylabel style={font=\footnotesize},
            xticklabel style = {font=\footnotesize},
            enlargelimits=0.2,
            nodes near coords,
            y tick label style={/pgf/number format/sci}
          ]

      \addplot[mark=*, only marks,
        point meta=explicit symbolic] coordinates {
        (X1, 6000)
        (X2, 5000)
        (X3, 4000)
        (X4, 3000)
    };

    \end{axis}
\end{tikzpicture}


\end{document}

答案1

这是一种可能性。更多详细信息请参阅 pgfplots 手册第 4.15.3 节“刻度缩放 – 刻度中的常见因素”。

\documentclass{article}
\usepackage{pgfplots}


\begin{document}

\begin{tikzpicture}
    \begin{axis}[
            symbolic x coords={X1, X2, X3, X4},
            xtick=data,
            ylabel style={font=\footnotesize},
            xticklabel style = {font=\footnotesize},
            enlargelimits=0.2,
            nodes near coords,
             y tick label style={scaled ticks=base 10:-3},
          ]

      \addplot[mark=*, only marks,
        point meta=explicit symbolic] coordinates {
        (X1, 6000)
        (X2, 5000)
        (X3, 4000)
        (X4, 3000)
    };

    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

答案2

实现您想要的最简单的方法是将其设置scale ticks above exponent为较低的值(默认值为 3)。

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        symbolic x coords={X1, X2, X3, X4},
        xtick=data,
        enlargelimits=0.2,
        only marks,
        scale ticks above exponent=2,   % <-- added (use this value or lower)
    ]
        \addplot coordinates {
            (X1, 6000)
            (X2, 5000)
            (X3, 4000)
            (X4, 3000)
        };
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

答案3

y tick label style={/pgf/number format/sci}用以下方式替换您的选项scaled ticks=base 10:-3,并且不要忘记\pgfplotsset{compat=1.5.1}序言中的那行。

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

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
            scaled ticks=base 10:-3,
            symbolic x coords={X1, X2, X3, X4},
            xtick=data,
            ylabel style={font=\footnotesize},
            xticklabel style = {font=\footnotesize},
            enlargelimits=0.2,
            nodes near coords,
          ]    
      \addplot[mark=*, only marks,
        point meta=explicit symbolic] coordinates {
        (X1, 6000)
        (X2, 5000)
        (X3, 4000)
        (X4, 3000)
    };
    \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

相关内容