我想使用 axis 环境绘制一个函数。到目前为止,轴的代码是
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
axis line style = {Stealth-Stealth, very thick},
xmin = -.1, xmax = 1.1, ymin = -4.5, ymax = 5.5,
xtick distance = 1/8,
ytick distance = 1,
xlabel = $\omega$,
ylabel = $f_1(\omega)$,
grid = major,
grid style = {thin, densely dotted, black!20}]
\end{axis}
\end{tikzpicture}
不幸的是,我不知道如何正确包含相应的图片。上述代码的问题是 xticklabels 四舍五入为两位数,即四舍五入为 0.13、0.25、0.38 等,这可能会造成混淆。因此,我想删除标签 0.13、0.25、...,同时保留 xticklabel 1。我知道我可以使用以下命令删除所有 xticklabels
xticklabel = \empty
但是是否还有一种方法可以指定我只想要一些 xticklabels?
答案1
您可以使用小勾号:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
axis line style = {Stealth-Stealth, very thick},
xmin = -.1, xmax = 1.1, ymin = -4.5, ymax = 5.5,
xtick distance = 1,% <- changed
minor x tick num=7,% <- added
ytick distance = 1,
xlabel = $\omega$,
ylabel = $f_1(\omega)$,
grid = both,% <- changed
grid style = {thin, densely dotted, black!20}]
\end{axis}
\end{tikzpicture}
\end{document}
或者与xtick distance=1/2
和minor x tick num=3
:
xtick distance=1/4
和minor x tick num=1
:
答案2
我画过各种函数,以我的经验,除了一些比较奇怪的函数(Weirstrass函数等),\draw plot
TikZ的命令已经足够了,也很灵活。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.5,x=10cm]
\draw[thin, densely dotted, black!20]
(-.1,-4.5) grid[xstep=.1] (1.1,5.5);
\draw[-stealth] (-.1,0)--(1.1,0) node[above]{$\omega$};
\draw[-stealth] (0,-4.5)--(0,5.5) node[right]{$f_1(\omega)$};
\foreach \j in {-4,...,-1,1,2,...,5}
\draw (0,\j) node[left=1mm]{$\j$}
--+(0:1.5mm)--+(180:1.5mm);
\draw (1,0) node[below=.5mm]{$1$}
--+(90:1.5mm)--+(-90:1.5mm);
\end{tikzpicture}
\end{document}