我正在使用 pgfplots 创建一些带有对数轴的图。但是 Latex 会自动显示minor y ticks
其中一些,而不会显示其他一些。这是一个示例(当我增加第一个示例的高度时,它会显示小刻度):
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
height=5cm,
x tick label style={/pgf/number format/1000 sep=},
enlargelimits=0,
legend style={at={(0.5,0)},
anchor=north,legend columns=-1},
ymode=log,
]
\addplot coordinates {
(5,163843)
(10,163616)
(15,163640)
(20,159217)
(25,158341)
(30,162913)
(35,162779)
(40,160709)
(45,159894)
(50,163381)
};
\addplot coordinates {
(5,911)
(10,1206)
(15,1679)
(20,2291)
(25,3100)
(30,4076)
(35,5289)
(40,6591)
(45,8146)
(50,9874)
};
\addplot coordinates {
(5,783)
(10,739)
(15,754)
(20,775)
(25,778)
(30,761)
(35,781)
(40,762)
(45,751)
(50,790)
};
\addplot coordinates {
(5,2284680)
(10,2280025)
(15,2269464)
(20,2292492)
(25,2268460)
(30,2274311)
(35,2270791)
(40,2278593)
(45,2268868)
(50,2277766)
};
\addplot coordinates {
(5,1758)
(10,1758)
(15,1760)
(20,1762)
(25,1764)
(30,1765)
(35,1768)
(40,1768)
(45,1771)
(50,1772)
};
\addplot coordinates {
(5,105)
(10,107)
(15,110)
(20,112)
(25,112)
(30,107)
(35,110)
(40,111)
(45,110)
(50,112)
};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
height=5cm,
x tick label style={/pgf/number format/1000 sep=},
enlargelimits=0,
ymode=log,
]
\addplot coordinates {
(5,26465)
(10,26452)
(15,26579)
(20,26468)
(25,26464)
(30,26579)
(35,26410)
(40,26459)
(45,26406)
(50,26447)
};
\addplot coordinates {
(5,120)
(10,293)
(15,582)
(20,982)
(25,1497)
(30,2122)
(35,2864)
(40,3718)
(45,4693)
(50,5776)
};
\addplot coordinates {
(5,73)
(10,63)
(15,65)
(20,71)
(25,66)
(30,69)
(35,71)
(40,70)
(45,75)
(50,73)
};
\addplot coordinates {
(5,215668)
(10,216228)
(15,216175)
(20,214921)
(25,213931)
(30,215041)
(35,214770)
(40,213248)
(45,212755)
(50,215309)
};
\addplot coordinates {
(5,668)
(10,675)
(15,676)
(20,676)
(25,677)
(30,678)
(35,680)
(40,679)
(45,679)
(50,683)
};
\addplot coordinates {
(5,50)
(10,54)
(15,56)
(20,55)
(25,55)
(30,55)
(35,56)
(40,56)
(45,57)
(50,58)
};
\end{axis}
\end{tikzpicture}
\end{document}
我怎样才能解决这个问题并且minor y ticks
在不增加这个图的高度的情况下显示它?
答案1
如果连续主刻度之间的距离恰好是一个对数单位,则 PGFPlots 仅打印对数轴的次刻度。例如,考虑这个最小示例:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymode=log,
domain=0:5,
ymin=1e0, ymax=1e7,
title={\texttt ymin = 1e0, ymax = 1e7}
]
\addplot {10^x)};
\end{axis}
\end{tikzpicture}
\end{document}
如果将上限增加到ymax = 1e8
,主刻度会太接近,因此 PGFPlots 会跳过每个第二个主刻度标签并禁用其间的次要刻度。
您可以通过设置来告诉 PGFPlots 接受刻度标签之间较小的距离max space between ticks=20
(默认为35
):
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymode=log,
domain=0:5,
ymin=1e0, ymax=1e8,
title={\texttt ymin = 1e0, ymax = 1e8, max space between ticks=20},
max space between ticks=20
]
\addplot {10^x)};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
如果需要,您应该在轴选项中设置yminorticks=true
,如果不需要,则设置为 false。我还建议您手动设置ymin
、ymax
和ytick
。