将轴原点置于 xmin 和 ymin

将轴原点置于 xmin 和 ymin

我怎样才能将轴的原点放在x=-20, y=2000

\begin{tikzpicture}
    \begin{axis}[
            legend pos=outer north east,
            legend cell align={left},
            grid=none,
            xticklabel style={rotate=90, anchor=near xticklabel},
            xmin=-20,xmax=20,
            ymin=2000,ymax=2300,
            axis lines = middle,
            %y axis line style = {stealth-},
            extra x ticks={0},
            width=8cm,
            height=8cm,
            set layers,
            x label style={at={(1,0)},right},
            y label style={at={(0,1)},above},
            y tick label style={/pgf/number format/.cd,%
                scaled y ticks = false,
                set thousands separator={},
            fixed},
            x tick label style={/pgf/number format/.cd,%
                scaled x ticks = false,
                set thousands separator={},
            fixed},
            xlabel={$m$},ylabel={$\bar{\nu}$\;(\unit{cm^{-1}})}, 
            style={thick}
        ]              
        \addlegendentry{$f(x) = 3.82379x + 2141.56$};
        \addplot[only marks, mark=*,scatter,domain=0:2000] coordinates {                
            (15,2081.78)
            %more and more coords
            (-15,2196.52)
        };
        \addlegendimage{green,mark=square}
        \addlegendentry{$R^2 = 0.998779$}
    \end{axis}
\end{tikzpicture}

答案1

很难判断你的意思是(1)移动-轴移到图表左侧,或者 (2) 您想要经典的 PGFPlots 框,图表周围有黑色边框。如果您指的是 (1),那么您可以更改axis lines = left而不是middle。如果您指的是 (2),您可以直接删除axis lines整个。

两个图表并排显示。左侧图表的 y 轴和 x 轴均源自图表的左下方。右侧图表的 y 轴和 x 轴是围绕整个图表的框的一部分。两个图表的内容相同:一个红点和一个蓝点。两个图表上的轴标签也相同。

\documentclass{standalone}
\usepackage{pgfplots,siunitx}
\begin{document}

\begin{tikzpicture}
    \begin{axis}[
            title=\fbox{\Large With \texttt{axis lines = left}},
            legend pos=outer north east,
            legend cell align={left},
            grid=none,
            xticklabel style={rotate=90, anchor=near xticklabel},
            xmin=-20,xmax=20,
            ymin=2000,ymax=2300,
            axis lines = left,
            extra x ticks={0},
            width=8cm,
            height=8cm,
            set layers,
            x label style={at={(1,0)},right},
            y label style={at={(0,1)},above},
            y tick label style={/pgf/number format/.cd,%
                scaled y ticks = false,
                set thousands separator={},
                fixed
            },
            x tick label style={/pgf/number format/.cd,%
                scaled x ticks = false,
                set thousands separator={},
                fixed
            },
            xlabel={$m$},ylabel={$\bar{\nu}$\;(\unit{cm^{-1}})}, 
            style={thick}
        ]
        \addplot[only marks, mark=*,scatter,domain=0:2000] coordinates {                
            (15,2081.78)
            %more and more coords
            (-15,2196.52)
        };
    \end{axis}
\end{tikzpicture}


\begin{tikzpicture}
    \begin{axis}[
            title=\fbox{\Large Deleting \texttt{axis lines} entirely},
            legend pos=outer north east,
            legend cell align={left},
            grid=none,
            xticklabel style={rotate=90, anchor=near xticklabel},
            xmin=-20,xmax=20,
            ymin=2000,ymax=2300,
            extra x ticks={0},
            width=8cm,
            height=8cm,
            set layers,
            x label style={at={(1,0)},right},
            y label style={at={(0,1)},above},
            y tick label style={/pgf/number format/.cd,%
                scaled y ticks = false,
                set thousands separator={},
                fixed
            },
            x tick label style={/pgf/number format/.cd,%
                scaled x ticks = false,
                set thousands separator={},
                fixed
            },
            xlabel={$m$},ylabel={$\bar{\nu}$\;(\unit{cm^{-1}})}, 
            style={thick}
        ]
        \addplot[only marks, mark=*,scatter,domain=0:2000] coordinates {                
            (15,2081.78)
            %more and more coords
            (-15,2196.52)
        };
    \end{axis}
\end{tikzpicture}

\end{document}

相关内容