如何将轴乘数移动到 PGFPlot 中的适当位置?

如何将轴乘数移动到 PGFPlot 中的适当位置?

使用下面的 MWE,我得到了 x 轴乘数以及 x 轴标签,如图所示。 在此处输入图片描述

但是,y 轴标签位于正确位置。如何将 x 轴乘数移动到与 PGFPlot 中当前 y 轴乘数匹配的适当位置?

平均能量损失

% used PGFPlots v1.14
\documentclass{article}
\usepackage{filecontents}
\usepackage{pgfplots}

\begin{filecontents*}{pgfplots.dat}
Level   Cost    Error   Fourth
1,7,8.471e-02,3
2,31,3.044e-02,5
3,111,1.022e-02,7
4,351,3.303e-03,9
5,1023,1.038e-03,11
6,2815,3.196e-04,13
7,7423,9.657e-05,15
8,18943,2.873e-05,17
9,47103,8.437e-06,19
\end{filecontents*}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}[
        xlabel = Cost,
        ylabel = Error,
        ]
        \addplot table[x index=1, y index=2, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 1}
        \addplot table[x index=1, y index=0, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 2}
        \addplot table[x index=1, y index=3, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 3}     
        \addplot table[x index=3, y index=1, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 4}
        \addplot table[x index = 0, y index=1, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 5}
        \addplot table[x index=3, y index=3, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 6}
        \addplot table[x index=3, y index=0, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 7}
        \addplot table[x index=2,y index=1, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 8}
        \addplot table[x index = 0, y index=3, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 9}
        \addplot table[x index = 0, y index=2, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 10}
        \addplot table[x index=2, y index=2, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 11}
        \addplot table[x index=2, y index=0, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 12}
    \end{axis}
\end{tikzpicture}
\caption{PGFPLOT graph}
\end{figure}
\end{document}

答案1

看 :在 pgfplots 中放置刻度刻度标签

下面我做了以下尝试:

    every x tick scale label/.style={at={(rel axis cs:1,0)},anchor=south west,inner sep=1pt},

(左和右)

    every x tick scale label/.style={at={(xticklabel cs:1)},anchor=south west},

输出

在此处输入图片描述

代码

\documentclass{standalone}
\usepackage{filecontents}
\usepackage{pgfplots}
\begin{filecontents*}{pgfplots.dat}
Level   Cost    Error   Fourth
1,7,8.471e-02,3
2,31,3.044e-02,5
3,111,1.022e-02,7
4,351,3.303e-03,9
5,1023,1.038e-03,11
6,2815,3.196e-04,13
7,7423,9.657e-05,15
8,18943,2.873e-05,17
9,47103,8.437e-06,19
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xlabel = Cost,
        ylabel = Error,
        every x tick scale label/.style={at={(rel axis cs:1,0)},anchor=south west,inner sep=1pt},
        ]
        \addplot table[x index=1, y index=2, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 1}
        \addplot table[x index=1, y index=0, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 2}
        \addplot table[x index=1, y index=3, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 3}     
        \addplot table[x index=3, y index=1, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 4}
        \addplot table[x index = 0, y index=1, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 5}
        \addplot table[x index=3, y index=3, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 6}
        \addplot table[x index=3, y index=0, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 7}
        \addplot table[x index=2,y index=1, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 8}
        \addplot table[x index = 0, y index=3, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 9}
        \addplot table[x index = 0, y index=2, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 10}
        \addplot table[x index=2, y index=2, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 11}
        \addplot table[x index=2, y index=0, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 12}
    \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
    \begin{axis}[
        xlabel = Cost,
        ylabel = Error,
        every x tick scale label/.style={at={(xticklabel cs:1)},anchor=south west},
        ]
        \addplot table[x index=1, y index=2, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 1}
        \addplot table[x index=1, y index=0, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 2}
        \addplot table[x index=1, y index=3, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 3}     
        \addplot table[x index=3, y index=1, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 4}
        \addplot table[x index = 0, y index=1, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 5}
        \addplot table[x index=3, y index=3, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 6}
        \addplot table[x index=3, y index=0, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 7}
        \addplot table[x index=2,y index=1, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 8}
        \addplot table[x index = 0, y index=3, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 9}
        \addplot table[x index = 0, y index=2, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 10}
        \addplot table[x index=2, y index=2, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 11}
        \addplot table[x index=2, y index=0, col sep=comma] {pgfplots.dat};
        \addlegendentry{Case 12}
    \end{axis}
\end{tikzpicture}

相关内容