我想使用倒数第二个刻度标签作为我的单位的位置,如下所示。有办法替换它吗?
梅威瑟:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel={$x$}, ylabel={$y$}]
\end{axis}
\end{tikzpicture}
\end{document}
编辑:我尝试将它应用到我的具有以下 x 和 y 范围的数据中,但尺寸似乎太大了?
\begin{tikzpicture}
\begin{axis}[
scaled x ticks = false,
xmin=0,
xmax=20000,
ymin=0,
ymax=3000,
ytick={0,500,...,3000},
xticklabel={\ifdim\tick pt=18000pt Hz \else \axisdefaultticklabel\fi},
yticklabel={\ifdim\tick pt=2500pt - \else \axisdefaultticklabel\fi},
]
\addplot coordinates {(19000,2000)};
\end{axis}
\end{tikzpicture}
EDIT2:使用任一命令都会搞乱半符号刻度。
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{semilogyaxis}[
xmin=0,
xmax=2000,
log ticks with fixed point,
ymin=0.0001,
ymax=0.1,
xticklabel={\pgfmathparse{int(\tick)} \ifnum \pgfmathresult=1500 test \else \axisdefaultticklabel\fi},
% yticklabel={\ifdim\tick pt=0.01pt \unit{\newton} \else \axisdefaultticklabel\fi},
yticklabel={\pgfmathparse{int(\tick)} \ifnum \pgfmathresult=0.01 test \else \axisdefaultticklabel\fi},
]
\end{semilogyaxis}
\end{tikzpicture}
\结束{文档}
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$}, ylabel={$y$},
xmin=0, xmax=4,
ymin=-0.45, ymax=0.05,
xtick distance=0.5, ytick distance=0.05,
x tick label style={/pgf/number format/.cd, fixed, fixed zerofill, precision=1},
y tick label style={/pgf/number format/.cd, fixed, fixed zerofill, precision=2},
xticklabel={\ifdim\tick pt=3.5pt mm \else \axisdefaultticklabel\fi},
yticklabel={\ifdim\tick pt=0.0pt mm \else \axisdefaultticklabel\fi},
]
\end{axis}
\end{tikzpicture}
\end{document}
编辑:适用于更高数字的版本
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=\textwidth, height=0.5\textwidth,
scaled x ticks=false,
xmin=0, xmax=20000,
ymin=0, ymax=3000,
xtick distance=2000, ytick distance=500,
xticklabel={\pgfmathparse{int(\tick)} \ifnum \pgfmathresult=18000 Hz \else \axisdefaultticklabel\fi},
yticklabel={\pgfmathparse{int(\tick)} \ifnum \pgfmathresult=2500 Hz \else \axisdefaultticklabel\fi},
]
\end{axis}
\end{tikzpicture}
\end{document}
答案2
作为骨架,函数的绘制留给你:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
grid,
xlabel = {$x$},
ylabel = {$y$},
xmin=0, xmax=4,
xtick = {0,0.5,...,4},
xticklabels = {0,0.5,1,1.5,2,2.5,3,mm,4},
ymin=-0.45, ymax=0,
ytick = {-0.45,-0.40,..., 0.0},
yticklabels = {-0.45,-0.40,-0.35,-0.25,-0.20,-0.15,-0.10,-0.05, mm, 0.0},
]
%\addplot [domain=0:4] {1};
\end{axis}
\end{tikzpicture}
\end{document}