4 带有 pgfplots 的 x 轴

4 带有 pgfplots 的 x 轴

我想在同一个图上放置 4 个 x 轴,但具有不同的比例。y 轴相同。

我尝试放置几个\begin{axis} ... \end{axis},但它们出现在同一个位置。在这里,我尝试放置一些假的 x 轴,但很难做好。

如果有必要,我可以在我的数据上应用一个因素。

有人有主意可以帮助我吗?

\documentclass[10pt]{article}

\usepackage{pgfplots}
\usepackage{subcaption}

\begin{document}

\begin{figure}[p]
\centering
    \begin{tikzpicture}
        \tikzstyle{every node}=[font=\small]
        \begin{axis}[height=0.8\textwidth,width=0.8\textwidth,
            axis lines=left, enlarge x limits=false,ymax=10,ymin=-0.08,
            xlabel={$x_1$},
            ylabel={$y$},
            legend entries={$x_1$,$x_2$,$x_3$,$x_4$},
            ]
            \addplot[draw=black,mark=o,line width=1.5pt] coordinates{(0,0)(2,2)(5,5)(8,8)(10,10)};

            \addplot[,draw=red,mark=star,line width=1.5pt] coordinates{(0,0)(5,3)(10,4)(20,7)(30,10)};

            \addplot[draw=blue,mark=square,line width=1.5pt] coordinates{(0,10)(10,6)(30,5)(60,3)(70,2)};

            \addplot[draw=green,mark=triangle,line width=1.5pt] coordinates{(0,7)(15,10)(30,7)(100,0)};
        \end{axis}

        \draw[->](0,-1.5)--(8,-1.5);
        \node[below] at (4,-1.5) {$x_2$};

        \draw[->](0,-2.5)--(8,-2.5);
        \node[below] at (4,-2.5) {$x_2$};

        \draw[->](0,-3.5)--(8,-3.5);
        \node[below] at (4,-3.5) {$x_2$};
    \end{tikzpicture}
\end{figure}
\vfill
\end{document}

输出

答案1

我用链接回答了这个问题控制 pgfplots 轴标签(感谢 Pier 提供的链接):

我为论坛发布了更正后的 ECM:

            \documentclass[10pt]{article}

                        \usepackage{pgfplots}
                        \usepackage{subcaption}
                        \pgfplotsset{compat=1.10}

                        \begin{document}


            \begin{figure}[p]
            \centering
                \begin{tikzpicture}
                    \tikzstyle{every node}=[font=\small]
                    \begin{axis}[height=0.8\textwidth,width=0.8\textwidth,
            xlabel={$x_1$},
            ylabel={y},
            color=black,
            scale only axis,
            xmin=0,xmax=10,
            x axis line style={black},
            xtick style={black},
            xticklabel style={black},
            xtick={0,2,4,6,8,10},
            xticklabels={0,2,4,6,8,10},
            ymin=0,ymax=10,
            ytick={0,2,4,6,8,10},
            yticklabels={0,2,4,6,8,10},
            axis x line*=bottom,
            axis y line*=left,    
            tick align = outside]
            \addplot[draw=black,mark=o,line width=1.5pt] coordinates{(0,0)(2,2)(5,5)(8,8)(10,10)};
            \end{axis}

            \begin{axis}[height=0.8\textwidth,width=0.8\textwidth,
            xlabel={$x_2$},
            ylabel={y},
            color=red,
            scale only axis,
            xmin=0,xmax=30,
            x axis line style={red},
            xtick style={red},
            xticklabel style={red},
            xtick={0,5,10,15,20,25,30},
            xticklabels={0,5,10,15,20,25,30},
            ymin=0,ymax=10,
            ytick={0,2,4,6,8,10},
            yticklabels={0,2,4,6,8,10},
            hide y axis,
            axis x line*=bottom,
            axis y line*=none,    
            tick align = outside]
            \pgfplotsset{every outer x axis line/.style={yshift=-1.5cm}, every tick/.style={yshift=-1.5cm}, every x tick label/.style={yshift=-1.5cm} }
            \addplot[,draw=red,mark=star,line width=1.5pt] coordinates{(0,0)(5,3)(10,4)(20,7)(30,10)};
            \end{axis}


            \begin{axis}[height=0.8\textwidth,width=0.8\textwidth,
            xlabel={$x_3$},
            ylabel={y},
            color=blue,
            scale only axis,
            xmin=0,xmax=70,
            x axis line style={blue},
            xtick style={blue},
            xticklabel style={blue},
            xtick={0,20,40,60,80},
            xticklabels={0,20,40,60,80},
            ymin=0,ymax=10,
            ytick={0,2,4,6,8,10},
            yticklabels={0,2,4,6,8,10},
            hide y axis,
            axis x line*=bottom,
            axis y line*=none,    
            tick align = outside]
            \pgfplotsset{every outer x axis line/.style={yshift=-3cm}, every tick/.style={yshift=-3cm}, every x tick label/.style={yshift=-3cm} }
            \addplot[draw=blue,mark=square,line width=1.5pt] coordinates{(0,10)(10,6)(30,5)(60,3)(70,2)};
            \end{axis}


            \begin{axis}[height=0.8\textwidth,width=0.8\textwidth,
            xlabel={$x_4$},
            ylabel={y},
            color=green,
            scale only axis,
            xmin=0,xmax=100,
            x axis line style={green},
            xtick style={green},
            xticklabel style={green},
            xtick={0,20,40,60,80,100},
            ymin=0,ymax=10,
            ytick={0,2,4,6,8,10},
            hide y axis,
            axis x line*=bottom,
            axis y line*=none,    
            tick align = outside]
            \pgfplotsset{every outer x axis line/.style={yshift=-4.5cm}, every tick/.style={yshift=-4.5cm}, every x tick label/.style={yshift=-4.5cm}}
            \addplot[draw=green,mark=triangle,line width=1.5pt] coordinates{(0,7)(15,10)(30,7)(100,0)};
                        \end{axis} 

            \end{tikzpicture}
            \end{figure}

            \end{document}

在此处输入图片描述

相关内容