![pgfplots:对数中的 x 轴 | 防止对额外的 x 刻度进行缩放(科学计数法)](https://linux22.com/image/374953/pgfplots%EF%BC%9A%E5%AF%B9%E6%95%B0%E4%B8%AD%E7%9A%84%20x%20%E8%BD%B4%20%7C%20%E9%98%B2%E6%AD%A2%E5%AF%B9%E9%A2%9D%E5%A4%96%E7%9A%84%20x%20%E5%88%BB%E5%BA%A6%E8%BF%9B%E8%A1%8C%E7%BC%A9%E6%94%BE%EF%BC%88%E7%A7%91%E5%AD%A6%E8%AE%A1%E6%95%B0%E6%B3%95%EF%BC%89.png)
- 我正在研究1/3 倍频程滤波器应用。
- 我想要生成一个带有对数 x 轴的图。
- 评论:黑色/灰色网格显示中心頻率。
- 评论:红色网格显示角落頻率。
问题 1(主要问题)
如何避免使用科学计数法表示额外的 x 刻度(见屏幕截图)?我添加了一个线性 x 轴版本,并找到了解决方案:
xticklabel style = {
/pgf/number format/fixed,
/pgf/number format/precision = 0,
},
scaled x ticks = false
一种解决方法是使用 手动设置(额外的 x)标签extra x tick labels
。
问题 2(小问题)——> 已解决
我怎样才能制作额外的 x 刻度的刻度标签大胆的?(\bfseries
)我猜问题在于刻度数字是在数学模式下排版的。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
%% x axis is log
%
\begin{tikzpicture}
\begin{axis}[
width = 200mm,
height = 60mm,
grid = both,
xlabel = {Frequency in Hz},
ylabel = {SPL in dB},
axis y line = left,
axis x line = middle,
xmin = 150,
xmax = 20000,
xticklabel style = {
% /pgf/number format/fixed,
% /pgf/number format/precision = 0,
font = \tiny\sffamily,
},
%scaled x ticks = false,
xtick = {200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000},
extra x ticks = {180, 224, 280, 355, 450, 560, 710, 899, 1120, 1410, 1800, 2240, 2800, 3550, 4500, 5600, 7100, 9000, 11200, 14100, 18000, 22400},
extra x tick style = {
major grid style = red,
tick align = outside,
tick style = {red, thin},
major tick length = 5mm,
},
ymin = 0,
ymax = 10,
xmode = log,
log ticks with fixed point,
]
\end{axis}
\end{tikzpicture}
%% x axis is linear
%
\begin{tikzpicture}
\begin{axis}[
width = 200mm,
height = 60mm,
grid = both,
xlabel = {Frequency in Hz},
ylabel = {SPL in dB},
axis y line = left,
axis x line = middle,
xmin = 150,
xmax = 20000,
xticklabel style = {
/pgf/number format/fixed,
/pgf/number format/precision = 0,
font = \tiny\sffamily,
},
scaled x ticks = false,
xtick = {200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000},
extra x ticks = {180, 224, 280, 355, 450, 560, 710, 899, 1120, 1410, 1800, 2240, 2800, 3550, 4500, 5600, 7100, 9000, 11200, 14100, 18000, 22400},
extra x tick style = {
major grid style = red,
tick align = outside,
tick style = {red, thin},
major tick length = 5mm,
},
ymin = 0,
ymax = 10,
% xmode = log,
% log ticks with fixed point,
]
\end{axis}
\end{tikzpicture}
\end{document}
有关的
答案1
由于某些我现在想不起来的原因,额外刻度标签的默认样式会激活一种特殊的刻度格式化功能,这会让您感到困惑。
更准确地说,违规的默认设置是
/pgfplots/every extra x tick/.style={
/pgfplots/log identify minor tick positions=true,
/pgfplots/hide obscured x ticks=false,
},
因此,一个简单的解决方法是添加
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
%% x axis is log
%
\begin{tikzpicture}
\begin{axis}[
width = 200mm,
height = 60mm,
grid = both,
xlabel = {Frequency in Hz},
ylabel = {SPL in dB},
axis y line = left,
axis x line = middle,
xmin = 150,
xmax = 20000,
xticklabel style = {
/pgf/number format/fixed,
/pgf/number format/precision = 0,
font = \tiny\sffamily,
},
%scaled x ticks = false,
xtick = {200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000},
extra x ticks = {180, 224, 280, 355, 450, 560, 710, 899, 1120, 1410, 1800, 2240, 2800, 3550, 4500, 5600, 7100, 9000, 11200, 14100, 18000, 22400},
extra x tick style = {
major grid style = red,
tick align = outside,
tick style = {red, thin},
major tick length = 5mm,
log identify minor tick positions=false,
},
ymin = 0,
ymax = 10,
xmode = log,
log ticks with fixed point,
]
\end{axis}
\end{tikzpicture}
\end{document}
我想知道这是否实际上是一个错误而不是一个功能……不确定是否有人使用过它。此功能的想法是以一种特殊的方式识别对数图中的额外刻度标签,这些标签实际上是小刻度,例如“1* 10^1、2*10^1、3 * 10^1”。
答案2
我当然无法与 Christian Feuersänger 竞争,但是既然你 ping 了我,这就是我得到的。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
%% x axis is log
%
\begin{tikzpicture}
\begin{axis}[
width = 200mm,
height = 60mm,
grid = both,
xlabel = {Frequency in kHz},
ylabel = {SPL in dB},
axis y line = left,
axis x line = middle,
xmin = 150,
xmax = 20000,
xticklabel style = {
% /pgf/number format/fixed,
% /pgf/number format/precision = 0,
font = \tiny\sffamily,
},
xticklabel={\pgfmathsetmacro{\mytick}{exp(\tick-ln(1000))}
$\mathbf{\pgfmathprintnumber[fixed,fixed
zerofill,precision=2]{\mytick}}$},
%scaled x ticks = false,
xtick = {200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000},
extra x ticks = {180, 224, 280, 355, 450, 560, 710, 899, 1120, 1410, 1800, 2240, 2800, 3550, 4500, 5600, 7100, 9000, 11200, 14100, 18000, 22400},
extra x tick style = {
major grid style = red,
tick align = outside,
tick style = {red, thin},
major tick length = 5mm,
},
ymin = 0,
ymax = 10,
xmode = log,
log ticks with fixed point,
]
\end{axis}
\end{tikzpicture}
%% original
%
\begin{tikzpicture}
\begin{axis}[
width = 200mm,
height = 60mm,
grid = both,
xlabel = {Frequency in Hz},
ylabel = {SPL in dB},
axis y line = left,
axis x line = middle,
xmin = 150,
xmax = 20000,
xticklabel style = {
% /pgf/number format/fixed,
% /pgf/number format/precision = 0,
font = \tiny\sffamily,
},
%scaled x ticks = false,
xtick = {200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000},
extra x ticks = {180, 224, 280, 355, 450, 560, 710, 899, 1120, 1410, 1800, 2240, 2800, 3550, 4500, 5600, 7100, 9000, 11200, 14100, 18000, 22400},
extra x tick style = {
major grid style = red,
tick align = outside,
tick style = {red, thin},
major tick length = 5mm,
},
ymin = 0,
ymax = 10,
xmode = log,
log ticks with fixed point,
]
\end{axis}
\end{tikzpicture}
\end{document}
正如您所见,我通过切换到 kHz 稍微作弊,否则数字会变得太大。