跨两列的 Tikz yy 图表

跨两列的 Tikz yy 图表

我想在 X 轴上添加更多数据点,但图表似乎已固定。有没有办法让它跨越两列?在此处输入图片描述

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
    \pgfplotsset{
        scale only axis,
        scaled x ticks=base 10:3,
    }
    \begin{axis}[
      axis y line*=left,
      ymin=85, ymax=100,
      ymajorgrids = true,
        legend style={at={(0.5,-0.10)},
          anchor=north,legend columns=-1},
      symbolic x coords={3x3\\Filter, Dsmp\\ (1/2),Integer,Dsmp\\ + Int, Dsmp\\ + 3X3,Dsmp\\ + 3X3\\ + Int},
        xtick=data,
        nodes near coords,
        nodes near coords style={anchor=east,rotate=90,inner xsep=5pt},
        x tick label style={font=\small,align=center},
      ylabel=Accuracy(\%),
    ]
    \addplot[smooth,mark=x,brown]
      coordinates{
        (3x3\\Filter,98.98)
        (Dsmp\\ (1/2),97.62)
        (Integer,95.86)
        (Dsmp\\ + Int,91.52)
        (Dsmp\\ + 3X3,93.26)
        (Dsmp\\ + 3X3\\ + Int,90.18)
    }; \label{plot_one}
    \end{axis}
    
    \begin{axis}[
      axis y line*=right,
      axis x line=none,
          legend style={at={(0.5,-0.20)},
          anchor=north,legend columns=-1},
      symbolic x coords={3x3\\Filter, Dsmp\\ (1/2),Integer,Dsmp\\ + Int, Dsmp\\ + 3X3,Dsmp\\ + 3X3\\ + Int},
     xtick=data,
      nodes near coords,
        nodes near coords style={anchor=north,rotate=0,inner xsep=3pt},
      ymin=0, ymax=100,
      ylabel=Frames Per Second (FPS)
    ]
    \addlegendimage{/pgfplots/refstyle=plot_one}\addlegendentry{Accuracy}
    \addplot[smooth,mark=*,blue]
      coordinates{
        (3x3\\Filter,40)
        (Dsmp\\ (1/2),30)
        (Integer,20)
        (Dsmp\\ + Int,15)
        (Dsmp\\ + 3X3,10)
        (Dsmp\\ + 3X3\\ + Int,5)
    }; \addlegendentry{FPS}
    \end{axis}
    
    \end{tikzpicture}
\end{document}

答案1

您实际上想要实现什么以及为什么要将图重叠起来,这有点令人困惑,但您可以使用调整图的宽度,width=20cm然后必须在中添加点symbolic x coords={...}。在这里我添加了两个点 AddPoint1 和 AddPoint2。

对于独立类,不会发生此问题,因为它会自动调整大小。

下列内容也适用于 documentclass 文章:

\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
        \pgfplotsset{
            scale only axis,
            scaled x ticks=base 10:3,
        }
        \begin{axis}[   
            axis y line*=left,
            ymin=85, ymax=100,
            ymajorgrids = true,
            legend style={at={(0.5,-0.10)},
                anchor=north,legend columns=-1},
            symbolic x coords={3x3\\Filter, Dsmp\\ (1/2),Integer,Dsmp\\ + Int, Dsmp\\ + 3X3,Dsmp\\ + 3X3\\ + Int, AddPoint1, AddPoint2},
            xtick=data,
            nodes near coords,
            nodes near coords style={anchor=east,rotate=90,inner xsep=5pt},
            x tick label style={rotate=90,font=\small,align=center},
            ylabel=Accuracy(\%),
            ]
            \addplot[smooth,mark=x,brown]
            coordinates{
                (3x3\\Filter,98.98)
                (Dsmp\\ (1/2),97.62)
                (Integer,95.86)
                (Dsmp\\ + Int,91.52)
                (Dsmp\\ + 3X3,93.26)
                (Dsmp\\ + 3X3\\ + Int,90.18)
                (AddPoint1,95)
                (AddPoint2,99)
            }; \label{plot_one}
        \end{axis}
        
        \begin{axis}[
            axis y line*=right,
            ylabel near ticks, 
            yticklabel pos=right,
            axis x line=none,
            legend style={at={(0.5,-0.20)},
                anchor=north,legend columns=-1},
            symbolic x coords={3x3\\Filter, Dsmp\\ (1/2),Integer,Dsmp\\ + Int, Dsmp\\ + 3X3,Dsmp\\ + 3X3\\ + Int, AddPoint1, AddPoint2},
            xtick=data,
            nodes near coords,
            nodes near coords style={anchor=north,rotate=0,inner xsep=3pt},
            ymin=0, ymax=100,
            ylabel=Frames Per Second (FPS)
            ]
            \addlegendimage{/pgfplots/refstyle=plot_one}\addlegendentry{Accuracy}
            \addplot[smooth,mark=*,blue]
            coordinates{
                (3x3\\Filter,40)
                (Dsmp\\ (1/2),30)
                (Integer,20)
                (Dsmp\\ + Int,15)
                (Dsmp\\ + 3X3,10)
                (Dsmp\\ + 3X3\\ + Int,5)
                (AddPoint1,6)
                (AddPoint2,7)
            }; \addlegendentry{FPS}
        \end{axis}
        
    \end{tikzpicture}
\end{document}

在此处输入图片描述

在不旋转 x 轴的情况下将宽度强制为某个值:

\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
    \pgfplotsset{
        scale only axis,
        scaled x ticks=base 10:3,
    }
    \begin{axis}[
        width=20cm,
        axis y line*=left,
        ymin=85, ymax=100,
        ymajorgrids = true,
        legend style={at={(0.5,-0.10)},
            anchor=north,legend columns=-1},
        symbolic x coords={3x3\\Filter, Dsmp\\ (1/2),Integer,Dsmp\\ + Int, Dsmp\\ + 3X3,Dsmp\\ + 3X3\\ + Int, AddPoint1, AddPoint2},
        xtick=data,
        nodes near coords,
        nodes near coords style={anchor=east,rotate=90,inner xsep=5pt},
        x tick label style={font=\small,align=center},
        ylabel=Accuracy(\%),
        ]
        \addplot[smooth,mark=x,brown]
        coordinates{
            (3x3\\Filter,98.98)
            (Dsmp\\ (1/2),97.62)
            (Integer,95.86)
            (Dsmp\\ + Int,91.52)
            (Dsmp\\ + 3X3,93.26)
            (Dsmp\\ + 3X3\\ + Int,90.18)
            (AddPoint1,95)
            (AddPoint2,99)
        }; \label{plot_one}
    \end{axis}
    
    \begin{axis}[
        width=20cm,
        axis y line*=right,
       ylabel near ticks, 
       yticklabel pos=right,
        axis x line=none,
        legend style={at={(0.5,-0.20)},
            anchor=north,legend columns=-1},
        symbolic x coords={3x3\\Filter, Dsmp\\ (1/2),Integer,Dsmp\\ + Int, Dsmp\\ + 3X3,Dsmp\\ + 3X3\\ + Int, AddPoint1, AddPoint2},
        xtick=data,
        nodes near coords,
        nodes near coords style={anchor=north,rotate=0,inner xsep=3pt},
        ymin=0, ymax=100,
        ylabel=Frames Per Second (FPS)
        ]
        \addlegendimage{/pgfplots/refstyle=plot_one}\addlegendentry{Accuracy}
        \addplot[smooth,mark=*,blue]
        coordinates{
            (3x3\\Filter,40)
            (Dsmp\\ (1/2),30)
            (Integer,20)
            (Dsmp\\ + Int,15)
            (Dsmp\\ + 3X3,10)
            (Dsmp\\ + 3X3\\ + Int,5)
            (AddPoint1,6)
            (AddPoint2,7)
        }; \addlegendentry{FPS}
    \end{axis}
    
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容