我们可以按如下方式设置网格的外观:
\pgfplotsset{
grid style = {
dash pattern = on 0.05mm off 1mm,
line cap = round,
black,
line width = 0.5pt
}
}
结果可能如下所示:
在 x 和 y 网格线的交叉处,这看起来不太好看。我喜欢看到的是这样的(只认识到在 x 和 y 方向上选择不同的虚线图案以很好地适应):
这将产生类似于第一幅图像的结果:
\documentclass[a4paper,10pt]{scrartcl}
\usepackage[greek,english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{
grid style = {
dash pattern = on 0.05mm off 1mm,
line cap = round,
black,
line width = 0.5pt
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid = major]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
一种方法是明确将绘图的单位向量长度设置为虚线图案周期的整数倍。如果另外将绘图的左边界和下边界设置为与虚线图案周期的整数倍相对应的值,则虚线图案将在交叉点处对齐:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
grid style = {
dash pattern = on 0.025mm off 0.95mm on 0.025mm off 0mm, % start with half a dot to get correct centering of the pattern
line cap = round,
black,
line width = 0.5pt
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid = major, xmin=2.2, ymin=-8.2, x=10mm, y=10mm]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\end{document}