评论

评论

在正确的 pgfplots 中,我希望它可以有 (0, 10000,20000,30000,40000,50000)[in normal scale],而不是(1000,10000) [in log scale]现在,我该怎么做? 在此处输入图片描述

这是代码

\begin{minipage}{0.5\linewidth}
\centering
\scriptsize
 \begin{tikzpicture}[font=\sffamily]
\begin{semilogyaxis}[title=Random Dataset,
                legend pos=outer north east,
                legend style={draw=none},
                xtick={1,2,...,9}, % new bit
                scaled ticks=false,
                log ticks with fixed point={1000 sep=},
                axis x line=bottom,
                axis y line=left,
                axis line style=-,
                minor tick style={draw=none},
                enlargelimits,
                ylabel = Solving Time (ms),
                xlabel = Number of Constraints,
                every axis legend/.append style={xshift=-10pt}
                ]
\addplot+[mark=triangle] plot coordinates{(1,7112)(2,11330)(3,4574)(4,5036)(5,14003)(6,11445)(7,7478)(8,8973)(9,10895)};
\addplot plot coordinates{(1,4499)(2,4816)(3,3201)(4,2903)(5,5912)(6,4896)(7,7536)(8,6998)(9,4786)};
\addplot+[draw opacity=0.5, thick, mark=square] plot coordinates{(1,78)(2,62)(3,41)(4,44)(5,120)(6,96)(7,133)(8,133)(9,91)};
%\addplot plot coordinates{(1,81)(2,62)(3,48)(4,47)(5,101)(6,90)(7,129)(8,159)(9,168)};
%\legend{$\exact$,$\kmeansskyline$,$\DROO$,$\DROSkyline$}
\legend{$\exact$,$\kmeans$,$\DROO$}
\end{semilogyaxis}
\end{tikzpicture}
\end{minipage}% new bit
\begin{minipage}{0.5\linewidth}
\centering
\scriptsize
 \begin{tikzpicture}[font=\sffamily]
\begin{semilogyaxis}[title=Random Dataset,
                legend pos=outer north east,
                legend style={draw=none},
                xtick={500,1500,...,5000}, % new bit
                scaled ticks=false,
                log ticks with fixed point={1000 sep=},
                axis x line=bottom,
                axis y line=left,
                axis line style=-,
                minor tick style={draw=none},
                enlargelimits,
                ylabel = Solving Time (ms),
                xlabel = Service Class Size,
                every axis legend/.append style={xshift=-10pt}
                ]
\addplot+[mark=triangle] plot coordinates{(500,1518)(1000,1431)(1500,1459)(2000,1346)(2500,1381)(3000,1474)(3500,1425)(4000,1508)(4500,1460)(5000,1389)};
\addplot plot coordinates{(500,37318)(1000,42496)(1500,38965)(2000,38415)(2500,34268)(3000,32102)(3500,30805)(4000,29453)(4500,33075)(5000,46871)};
\addplot+[draw opacity=0.5, thick, mark=square] plot coordinates{(500,8798)(1000,9953)(1500,13899)(2000,10810)(2500,11588)(3000,10397)(3500,9437)(4000,8202)(4500,6698)(5000,5635)};
%\addplot plot coordinates{(500,61)(1000,105)(1500,89)(2000,107)(2500,86)(3000,64)(3500,102)(4000,80)(4500,85)(5000,128)};
%\legend{$\exact$,$\kmeansskyline$,$\DRONP$,$\DROSkyline$}
\legend{$\exact$,$\kmeans$,$\DRO$}
\end{semilogyaxis}
\end{tikzpicture}
\end{minipage}

答案1

评论

将你的第二个情节括在\begin{axis}...\end{axis}而不是中\begin{semilogyaxis}...\end{semilogyaxis}(就像杰克的评论中所说的那样)。

我还稍微缩进了你的代码,并通过使用该类使 MWE 兼容standalone

我不得不改变图例,因为宏的定义在你的代码中缺失了\exact\kmeans\DROO

执行

\documentclass[tikz]{standalone} 
\usepackage{pgfplots}
\begin{document} 
\scriptsize

\begin{tikzpicture}[font=\sffamily]
    \begin{semilogyaxis}[title=Random Dataset,
            legend pos=outer north east,
            legend style={draw=none},
            xtick={1,2,...,9}, % new bit
            scaled ticks=false,
            log ticks with fixed point={1000 sep=},
            axis x line=bottom,
            axis y line=left,
            axis line style=-,
            minor tick style={draw=none},
            enlargelimits,
            ylabel = Solving Time (ms),
            xlabel = Number of Constraints,
            every axis legend/.append style={xshift=-10pt}
        ]
        \addplot+[mark=triangle] plot coordinates{(1,7112)(2,11330)(3,4574)(4,5036)(5,14003)(6,11445)(7,7478)(8,8973)(9,10895)};
        \addplot plot coordinates{(1,4499)(2,4816)(3,3201)(4,2903)(5,5912)(6,4896)(7,7536)(8,6998)(9,4786)};
        \addplot+[draw opacity=0.5, thick, mark=square] plot coordinates{(1,78)(2,62)(3,41)(4,44)(5,120)(6,96)(7,133)(8,133)(9,91)};
        %\addplot plot coordinates{(1,81)(2,62)(3,48)(4,47)(5,101)(6,90)(7,129)(8,159)(9,168)};
        %\legend{$\exact$,$\kmeansskyline$,$\DROO$,$\DROSkyline$}
        %\legend{$\exact$,$\kmeans$,$\DROO$}
        \legend{Exact,KMeans,DRO}
    \end{semilogyaxis}
\end{tikzpicture}

\begin{tikzpicture}[font=\sffamily]
    \begin{axis}[title=Random Dataset,
            legend pos=outer north east,
            legend style={draw=none},
            xtick={500,1500,...,5000}, % new bit
            scaled ticks=false,
            log ticks with fixed point={1000 sep=},
            axis x line=bottom,
            axis y line=left,
            axis line style=-,
            minor tick style={draw=none},
            enlargelimits,
            ylabel = Solving Time (ms),
            xlabel = Service Class Size,
            every axis legend/.append style={xshift=-10pt}
        ]
        \addplot+[mark=triangle] plot coordinates{(500,1518)(1000,1431)(1500,1459)(2000,1346)(2500,1381)(3000,1474)(3500,1425)(4000,1508)(4500,1460)(5000,1389)};
        \addplot plot coordinates{(500,37318)(1000,42496)(1500,38965)(2000,38415)(2500,34268)(3000,32102)(3500,30805)(4000,29453)(4500,33075)(5000,46871)};
        \addplot+[draw opacity=0.5, thick, mark=square] plot coordinates{(500,8798)(1000,9953)(1500,13899)(2000,10810)(2500,11588)(3000,10397)(3500,9437)(4000,8202)(4500,6698)(5000,5635)};
        %\addplot plot coordinates{(500,61)(1000,105)(1500,89)(2000,107)(2500,86)(3000,64)(3500,102)(4000,80)(4500,85)(5000,128)};
        %\legend{$\exact$,$\kmeansskyline$,$\DRONP$,$\DROSkyline$}
        %\legend{$\exact$,$\kmeans$,$\DRO$}
        \legend{Exact,KMeans,DRO}
    \end{axis}
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容