latex画折线图的几种方法。以下有使用tikz。
1 最简单的描点,使用draw命令
\draw (x1,y2)..(x2,y2)..(xn,yn);
当点数较少时,可以直接使用\draw。
2 使用axis环境,或者semilogyaxis,semilogxaxis,loglogaxis
\usepackage{pgfplots}
\pgfplotsset{every axis legend/.style={%
cells={anchor=west},
inner xsep=3pt,inner ysep=2pt,nodes={inner sep=2pt,text depth=0.15em},
anchor=north east,%
shape=rectangle,%
%fill=white,%
draw=black,
at={(0.98,0.98)}
}}
\begin{tikzpicture}
\begin{semilogyaxis}[
height=11cm,
width=14cm,
xlabel=SNR(dB),
ylabel=BER,
xmin=-4,
xmax=16,
ymin=1e-4,
ymax=1,
ytick pos=left
]
\addplot coordinates {
(-4,0.25076)
(0,0.15076)
(4,0.0633)
(8,0.015545)
};
\addlegendentry{Codebook $N_b=4$}
\addplot coordinates {
(-4,0.22467)
(0,0.12395)
(4,0.044426)
(8,0.008952)
};
\addlegendentry{Codebook $N_b=16$}
\addplot coordinates {
(-4,0.21325)
(0,0.11331)
(4,0.039755)
(8,0.00826)
};
\addlegendentry{Matched bound}
\end{semilogyaxis}
\end{tikzpicture}
3 如果数据较多,可以保存在文本文件中,使用datavisualization
\usetikzlibrary{datavisualization}
\begin{tikzpicture}
\datavisualization[scientific axes,
x axis={attribute=data size,
length=10cm,
% 对数坐标,以便显示范围很大的坐标轴
logarithmic,
% 对数坐标默认情况下ticks不满足要求,major at可以手工指定显示哪些ticks
ticks={major at={10,100,200,500,1000,2000,5000,10000,30000}},
label={数据尺寸(bytes)}},
y axis={attribute=tps,
length=5cm,
% include value决定了y轴的起步数值
include value=500,
ticks={many},
% 显示网格线,默认minor steps between steps=8,可以修改此值改变网格的密度
grid,grid={minor steps between steps,major={style=red}},
label={吞吐率(q/s)}},
%
visualize as smooth line/.list={tcpip100,tcpip1000},
style sheet=strong colors,
legend={below,rows=2},
tcpip100={label in legend={text=TCPIP(100M)}},
tcpip1000={label in legend={text=TCPIP(1000M)}},
data/format=table
]
data[set=tcpip100, headline={data size,tps},read from file="redis-set-benchmark-tcpip-100M.dat"]
data[set=tcpip1000, headline={data size,tps},read from file="redis-set-benchmark-tcpip-1000M.dat"]
\end{tikzpicture}
mugongsima 发布了5 篇原创文章 · 获赞 0 · 访问量 1281 私信 关注