我对这个图形有疑问。
圆圈没有聚焦于相应的数字。例如,在第一行中,您应该聚焦于数字 1,但圆圈的顶部刚好触及它。以下是它应该看起来的样子:
\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=0.75]
\begin{axis}[
axis lines=center,
grid={both}, grid style={solid,black!50},
clip=false,
y axis line style={very thick,-Stealth},
x axis line style={very thick,-Stealth},
xmin=-0.75,xmax=10.5, ymax=1.1,ymin=-0.12,
ytick={0,0.1,...,1.1},
xtick={0,1,...,10},
extra y ticks={-0.12,1.1},extra x ticks={-0.75,10.5},
extra y tick labels={},extra x tick labels={},
extra y tick style={ticklabel style={fill=none}},extra x tick style={ticklabel style={fill=none}},
%minor tick num=1, % added
ylabel={$|S(n\cdot \omega_{_{0}})|$}, xlabel={$f$},
ylabel style={above}, % changed
xlabel style={right}, % changed
yticklabel style={fill=orange!20,circle,inner sep=0.75pt},
xticklabel style={fill=orange!20,circle,inner sep=2pt},
scale only axis,
width=16cm,
height=7cm
]
\addplot[-*,ultra thick,blue] coordinates {(0,0)(0,1)};
\addplot[-*,ultra thick,red] coordinates {(1,0)(1,0.6366)};
\addplot[-*,ultra thick,red] coordinates {(2,0)(2,0.3183)};
\addplot[-*,ultra thick,red] coordinates {(3,0)(3,0.2122)};
\addplot[-*,ultra thick,red] coordinates {(4,0)(4,0.1591)};
\addplot[-*,ultra thick,red] coordinates {(5,0)(5,0.1273)};
\addplot[-*,ultra thick,red] coordinates {(6,0)(6,0.1061)};
\addplot[-*,ultra thick,red] coordinates {(7,0)(7,0.0909)};
\addplot[-*,ultra thick,red] coordinates {(8,0)(8,0.0795)};
\addplot[-*,ultra thick,red] coordinates {(9,0)(9,0.0707)};
\addplot[-*,ultra thick,red] coordinates {(10,0)(10,0.0636)};
\end{axis}
\end{tikzpicture}
\caption{Armónicos de la función $g_{(t)}$}
\end{figure}
提前致谢!!
答案1
使用包ycomb
中的宏pgfplots
:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=12cm, height=11cm,
axis lines=center,
grid={both},
axis line style={thick,-Stealth},
ycomb, % <---
xmin=-0.9,xmax=10.5, ymax=1.08,ymin=-0.1,
ytick={0,0.1,...,1.1},
ylabel=$|n\cdot\omega_{0}|$,
xlabel={$f$},
xlabel style={right}, % changed
ticklabel style={circle, fill=orange!20, font=\footnotesize,
minimum size=1.5em,inner sep=0pt},
every axis plot post/.append style={ultra thick}
]
\addplot+[blue] coordinates {(0,1)};
\addplot+[red, mark=*] coordinates {
(1,0.6366) (2,0.3183) (3,0.2122) (4,0.1591) (5,0.1273)
(6,0.1061) (7,0.0909) (8,0.0795) (9,0.0707) (10,0.0636)
};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
环境中的很多选项axis
让我眼花缭乱。Anh 这里是一个简单的 TikZ 解决方案。
\documentclass{article}
\usepackage{tikz,lipsum}
\begin{document}
\lipsum[1]
\begin{center}
\begin{tikzpicture}[yscale=6]
\draw[gray!50] (11,0) grid[ystep=1mm] (0,1.1);
\draw[-stealth] (0,0)--(11,0) node[below]{$f$};
\draw[-stealth] (0,0)--(0,1.1) node[above]{$|S(n\cdot\omega_0)|$};
\foreach \i/\ivalue in
{1/.6366,2/0.3183,3/0.2122,4/0.1591,5/0.1273,6/0.1061,7/0.0909,8/0.0795,9/0.0707,10/0.0636}
\draw[red,line width=1.5pt]
(\i,\ivalue) node[circle,fill,inner sep=2pt]{}--
(\i,0) node[below=3pt,circle,fill=pink,text=black,scale=.7,minimum size=22pt]{$\i$};
\draw[blue,line width=1.5pt]
(0,1) node[circle,fill,inner sep=2pt]{}--(0,0);
\foreach \j in {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1}
\path (0,\j) node[left=8pt,fill=pink,circle,scale=.7,minimum size=22pt,inner sep=1pt]{$\j$};
\end{tikzpicture}
\end{center}
\lipsum[10]
\end{document}
答案3
在您不完整的示例中,实心圆由箭头绘制(未显示其定义)。对于箭头,“圆的顶部刚好接触它”是预期的行为。
在以下示例中,实心圆由标记绘制(记录在手册pgfplots
,第 4.7.1 节),从而解决了问题。
为了进一步改善你的情节,
- 您可能需要
minimum size=...
使用yticklabel style
; - 一些明确指定的额外刻度看起来奇怪且无用。
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\begin{document}
\pgfplotsset{
x mark/.style={
mark=*,
mark indices=2
}
}
\begin{tikzpicture}[scale=0.75]
\begin{axis}[
axis lines=center,
grid={both}, grid style={solid,black!50},
clip=false,
y axis line style={very thick,-Stealth},
x axis line style={very thick,-Stealth},
xmin=-0.75,xmax=10.5, ymax=1.1,ymin=-0.12,
ytick={0,0.1,...,1.1},
xtick={0,1,...,10},
extra y ticks={-0.12,1.1},extra x ticks={-0.75,10.5},
extra y tick labels={},extra x tick labels={},
extra y tick style={ticklabel style={fill=none}},extra x tick style={ticklabel style={fill=none}},
%minor tick num=1, % added
ylabel={$|S(n\cdot \omega_{_{0}})|$}, xlabel={$f$},
ylabel style={above}, % changed
xlabel style={right}, % changed
yticklabel style={fill=orange!20,circle,inner sep=0.75pt},
xticklabel style={fill=orange!20,circle,inner sep=2pt},
scale only axis,
width=16cm,
height=7cm,
]
\addplot[x mark,ultra thick,blue] coordinates {(0,0)(0,1)};
\addplot[x mark,ultra thick,red] coordinates {(1,0)(1,0.6366)};
\addplot[x mark,ultra thick,red] coordinates {(2,0)(2,0.3183)};
\addplot[x mark,ultra thick,red] coordinates {(3,0)(3,0.2122)};
\addplot[x mark,ultra thick,red] coordinates {(4,0)(4,0.1591)};
\addplot[x mark,ultra thick,red] coordinates {(5,0)(5,0.1273)};
\addplot[x mark,ultra thick,red] coordinates {(6,0)(6,0.1061)};
\addplot[x mark,ultra thick,red] coordinates {(7,0)(7,0.0909)};
\addplot[x mark,ultra thick,red] coordinates {(8,0)(8,0.0795)};
\addplot[x mark,ultra thick,red] coordinates {(9,0)(9,0.0707)};
\addplot[x mark,ultra thick,red] coordinates {(10,0)(10,0.0636)};
\end{axis}
\end{tikzpicture}
\end{document}