我有下面的 pgf 图,但显示效果不太好。我希望
- 将“解决时间(毫秒)”和 y 轴放在一起,
- 把字体大小调小我该怎么做?
右边的图表也存在数字抽搐的问题,有没有办法不显示每个数字,让数字不抽搐?
\documentclass[9pt]{sig-alternate}
% GRAPHICS
\usepackage{pgf}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{arrows,automata,positioning}
\begin{document}
\pgfplotsset{
xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
every axis/.append style={
font=\sffamily,
width=6.5cm,
height=4.9cm
}
}
\begin{figure*}[t]
\begin{minipage}{0.5\linewidth}
\centering
\scriptsize
\begin{tikzpicture}[font=\sffamily]
\begin{semilogyaxis}[title=\textbf{ Dataset 1},
legend pos=outer north east,
legend style={draw=none},
xtick={50,100,150,200,250,300,350,400,450,500},
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
]
\addplot plot coordinates{(50,77)(100,81)(150,109)(200,155)(250,112)(300,139)(350,175)(400,214)(450,206)(500,228)};
\addplot plot coordinates{(50,10)(100,1)(150,2)(200,2)(250,1)(300,1)(350,1)(400,2)(450,1)(500,1)};
\addplot plot coordinates{(50,2)(100,2)(150,2)(200,2)(250,2)(300,1)(350,1)(400,2)(450,1)(500,1)};
\addplot plot coordinates{(50,3)(100,1)(150,1)(200,1)(250,1)(300,1)(350,1)(400,1)(450,1)(500,1)};
\addplot plot coordinates{(50,5)(100,1)(150,2)(200,1)(250,1)(300,1)(350,1)(400,1)(450,1)(500,1)};
\legend{$a$,$b$,$c$,$d$,$e$}
\end{semilogyaxis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{0.5\linewidth}
\centering
\scriptsize
\begin{tikzpicture}[font=\sffamily]
\begin{semilogyaxis}[title=\textbf{ Dataset 2},
legend pos=outer north east,
legend style={draw=none},
xtick={500,1000,1500,2000,2500,3000,3500,4000,4500,5000},
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
]
\addplot plot coordinates{(500,35)(1000,1048)(1500,1668)(2000,2309)(2500,2918)(3000,3965)(3500,5008)(4000,5569)(4500,5833)(5000,6680)};
\addplot plot coordinates{(500,855)(1000,1613)(1500,1878)(2000,2228)(2500,2738)(3000,2480)(3500,2512)(4000,3263)(4500,3746)(5000,4676)};
\addplot plot coordinates{(500,80)(1000,90)(1500,62)(2000,77)(2500,54)(3000,49)(3500,33)(4000,45)(4500,34)(5000,68)};
\addplot plot coordinates{(500,101)(1000,633)(1500,302)(2000,151)(2500,138)(3000,35)(3500,41)(4000,57)(4500,20)(5000,42)};
\addplot plot coordinates{(500,20)(1000,66)(1500,79)(2000,74)(2500,81)(3000,45)(3500,57)(4000,45)(4500,27)(5000,17)};
\legend{$a$,$b$,$c$,$d$,$e$}
\end{semilogyaxis}
\end{tikzpicture}
\end{minipage}
\end{figure*}
\end{document}
答案1
以下是代码的输出
我改变了一些东西,你会看到我标记了% new bit
- 我进入
\pgfplotsset
了序言 - 我删除了一些多余的包裹
pgfplots
——tikz
、pgf
和graphicx
,因此不需要明确加载它们 - 我删除了
\scriptsize
从每张图片中删除,然后将其放入,\pgfplotsset
以便更改是全局的 - 我删除了
textbf
从你们的个人标题中删除了它们,并在序言中创建了一种风格pgfplotsset
(这将简化未来的全球变化) - 我删除了
[font=\sffamily]
它,\begin{tikzpicture}[font=\sffamily]
因为它现在在序言中全局指定 - 我改变了
xtick
每张图片,让标签看起来不那么杂乱 - 我
ylabel
使用ylabel shift=-2pt
,这需要compat=1.3
或更新 - 我
%
在第一个 之后添加了一个\end{minipage}
;这非常重要,因为它会删除 插入的额外空间minipage
,并删除Overfull hbox
您收到的警告
代码
\documentclass[9pt]{sig-alternate}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.3,
xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
every axis/.append style={
font=\sffamily,
label style={font=\scriptsize\sffamily}, % new bit
legend style={font=\scriptsize\sffamily},% new bit
title style={font=\bfseries\sffamily}, % new bit
width=6.5cm,
height=4.9cm,
ylabel shift=-2pt, % new bit
}
}
\begin{document}
\begin{figure*}[t]
\begin{minipage}{0.5\linewidth}
\centering
\begin{tikzpicture}
\begin{semilogyaxis}[title=Dataset 1,
legend pos=outer north east,
legend style={draw=none},
xtick={50,150,...,500}, % 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
]
\addplot plot coordinates{(50,77)(100,81)(150,109)(200,155)(250,112)(300,139)(350,175)(400,214)(450,206)(500,228)};
\addplot plot coordinates{(50,10)(100,1)(150,2)(200,2)(250,1)(300,1)(350,1)(400,2)(450,1)(500,1)};
\addplot plot coordinates{(50,2)(100,2)(150,2)(200,2)(250,2)(300,1)(350,1)(400,2)(450,1)(500,1)};
\addplot plot coordinates{(50,3)(100,1)(150,1)(200,1)(250,1)(300,1)(350,1)(400,1)(450,1)(500,1)};
\addplot plot coordinates{(50,5)(100,1)(150,2)(200,1)(250,1)(300,1)(350,1)(400,1)(450,1)(500,1)};
\legend{$a$,$b$,$c$,$d$,$e$}
\end{semilogyaxis}
\end{tikzpicture}
\end{minipage}% new bit
\begin{minipage}{0.5\linewidth}
\centering
\begin{tikzpicture}
\begin{semilogyaxis}[title=Dataset 2,
legend pos=outer north east,
legend style={draw=none},
xtick={500,1500,...,4500}, % 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
]
\addplot plot coordinates{(500,35)(1000,1048)(1500,1668)(2000,2309)(2500,2918)(3000,3965)(3500,5008)(4000,5569)(4500,5833)(5000,6680)};
\addplot plot coordinates{(500,855)(1000,1613)(1500,1878)(2000,2228)(2500,2738)(3000,2480)(3500,2512)(4000,3263)(4500,3746)(5000,4676)};
\addplot plot coordinates{(500,80)(1000,90)(1500,62)(2000,77)(2500,54)(3000,49)(3500,33)(4000,45)(4500,34)(5000,68)};
\addplot plot coordinates{(500,101)(1000,633)(1500,302)(2000,151)(2500,138)(3000,35)(3500,41)(4000,57)(4500,20)(5000,42)};
\addplot plot coordinates{(500,20)(1000,66)(1500,79)(2000,74)(2500,81)(3000,45)(3500,57)(4000,45)(4500,27)(5000,17)};
\legend{$a$,$b$,$c$,$d$,$e$}
\end{semilogyaxis}
\end{tikzpicture}
\end{minipage}
\end{figure*}
\end{document}
最后要说的是,这两处地块有很多共同的特点,比如
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,
如果你在本文档中绘制的每个图中都是如此,那么你可能想考虑将它们放入你的全局pgfplotsset
。
一般来说,尽可能地尝试使用 -styles
它既简化了代码的可读性又简化了全局更改,这是使用tikz
:)