我在半对数图中遇到了一些额外的 x 刻度问题。我想在 x 轴上添加一些额外的刻度,但 x 刻度会与额外的刻度 10^ 潜在值重叠。
以下是代码:
\documentclass{article}
\usepackage{tikz}
\usepackage[graphics, active, tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\usetikzlibrary{arrows}
\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}
\usetikzlibrary{shapes}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{pgfplots.groupplots}
%
\usepackage{lipsum}
\usetikzlibrary{matrix,positioning}
\usepackage{relsize}
\tikzset{fontscale/.style = {font=\relsize{#1}}
}
\usepackage{pdflscape}
\usepackage{pgfplotstable}
\begin{document}
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\begin{semilogxaxis}[
xmin=0.06 ,xmax = 60, domain = 0.2:60,
height = 8 cm ,
width = 8 cm,
xlabel = {Sieve opening, (mm)},
ylabel ={Sieve passing, (\%)},
grid = both,
%
yticklabel pos=left,
x tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd
},
extra x tick style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd,
every tick label/.style={
font=\tiny
}
},
xmode=log,
log ticks with fixed point,
ymax = 100,ymin = 0,
ytick = {0,10,...,100},
ticklabel style = {font=\tiny},
scaled x ticks = false,
extra x ticks = {0.06,0.2,0.6,2,60},
]
\addplot [color = black, mark=none,thick, smooth]
coordinates
{
(2, 100)
(1.18, 99.19899337)
(0.8, 97.38828873)
(0.6, 94.17812423)
(0.425, 74.5948932)
(0.3, 38.14755708)
(0.212, 14.63908667)
(0.15, 4.364105082)
(0.063, 1.242941321)
};
\end{semilogxaxis}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
您可以使用以下方法覆盖对数轴刻度标签的默认格式:
log number format code/.code={%
\pgfset{number format/fixed}%
\pgfmathparse{exp(#1)}%
${\pgfmathprintnumber{\pgfmathresult}}$%
}
完整代码:
\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{semilogxaxis}[
xmin = 0.06, xmax = 60, xmode=log, domain = 0.2:60,
height = 8 cm ,
width = 8 cm,
xlabel = {Sieve opening, (mm)},
ylabel = {Sieve passing, (\%)},
grid = both,
yticklabel pos=left,
ymin = 0, ymax = 100,
ytick = {0,10,...,100},
ticklabel style = {font=\tiny},
extra x ticks = {0.06,0.2,0.6,2,60},
log number format code/.code={%
\pgfset{number format/fixed}%
\pgfmathparse{exp(#1)}%
${\pgfmathprintnumber{\pgfmathresult}}$%
},
% extra x tick style={tick label style={yshift=-1ex}},
]
\addplot [color=black, mark=none, thick, smooth]
coordinates
{
(2, 100)
(1.18, 99.19899337)
(0.8, 97.38828873)
(0.6, 94.17812423)
(0.425, 74.5948932)
(0.3, 38.14755708)
(0.212, 14.63908667)
(0.15, 4.364105082)
(0.063, 1.242941321)
};
\end{semilogxaxis}
\end{tikzpicture}
\end{document}
如果你想将额外的刻度标签向下移动一点,只需取消注释包含以下内容的行:
extra x tick style={tick label style={yshift=-1ex}},
输出将变成如下形式: