latex的图例latex
时间: 2025-01-15 14:15:02 浏览: 45
创建和自定义LaTeX中的图表图例
在LaTeX中创建和自定义图表图例通常涉及使用pgfplots
包,这是一个基于TikZ/PGF的强大工具,用于绘制高质量的科学图形[^1]。
使用 pgfplots
包创建基本图例
为了创建带有图例的基本图表,可以按照如下方式设置文档:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend pos=north west, % 设置图例位置
xlabel={X轴标签},
ylabel={Y轴标签}]
\addplot[color=red,mark=x] coordinates {
(0,0)
(1,2)
(2,3)
(3,5)
};
\addlegendentry{数据系列一}; % 添加图例条目
\addplot[color=blue,mark=o] coordinates {
(0,1)
(1,3)
(2,4)
(3,6)
};
\addlegendentry{数据系列二};
\end{axis}
\end{tikzpicture}
\end{document}
此代码片段展示了如何通过\addlegendentry
命令为每个绘图添加对应的图例描述,并利用legend pos
选项调整图例的位置。
自定义图例外观
对于更复杂的定制需求,可以通过修改legend style
属性来自定义图例样式。例如改变边框颜色、背景填充以及字体大小等特性:
\begin{axis}[
...
legend style={
draw=none,
fill=gray!10,
font=\footnotesize,
at={(0.5,-0.2)},
anchor=north,
legend columns=-1
}
]
...
\end{axis}
上述配置移除了默认边框(draw=none
),设置了浅灰色背景(fill=gray!10
),并缩小了文字尺寸(font=\footnotesize
);同时还将图例放置于坐标系下方中心位置(at={(0.5,-0.2)},anchor=north
),并将多个图列项水平排列(legend columns=-1
)。
阅读全文
相关推荐


















