我正在使用tikz
以下图像重新创建
我想要做的是绘制一个“延伸”且“平滑”的梯形。我的代码是
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%axes
\draw[very thick] (0,0)--(8,0);
\draw[very thick] (0,0)--(0,5) coordinate (y);
\draw (8,0) node[below] {\eng{Energy}};
\node [draw=none,rotate=90, yshift=0.3cm] at (0,5) {\eng{Counts}};
%1st peak
\draw[thick,blue] (7.3,0)--(7,3)--(5,4)--(4.7,0);
\draw[blue,dashed] (7,0)--(7,3);
\draw[blue,dashed] (5,4)--(5,0);
\draw[blue] (7,3) node[above,right] {$4$};
\draw[blue] (5,4) node[above,left] {$3$};
\draw[blue] (6,4.5) node[above] {$\delta E$};
%2nd peak
\draw[thick,red] (3.3,0) -- (3,2.5) -- (1,3.5) -- (0.7,0);
\draw[red,dashed] (3,0)--(3,2.5);
\draw[red,dashed] (1,0)--(1,3.5);
\draw[red] (3,2.5) node[above,right] {$1$};
\draw[red] (1,3.5) node[above,left] {$2$};
\draw[red] (2,4.5) node[above] {$\delta E$};
\end{tikzpicture}
\end{document}
我的输出是
我想做的是使角度 1、2、3、4 更平滑。我还想使与 x 轴相切的红线和蓝线更平滑一些(比如有一条小尾巴)。如何实现这些?
答案1
我不太清楚你说的“延伸两条垂直于 x 轴线的线”是什么意思,但至少可以用贝塞尔曲线画出一条平滑的线。
在直线上,(a) -- (b)
你可以添加(多个)控制点 x 来创建平滑的曲线(a) .. controls (x) .. (b)
(取自这里)
编辑:感谢您编辑您的问题:)让我修改我的答案......
实际上,绘图有一个“平滑”修饰符。此外,我在末尾和开头添加了另一个坐标,并增加了相邻坐标的 y 值:
\draw[thick, green] plot [smooth] coordinates {(3.5,0) (3.3,0.5) (3,2.5) (1,3.5) (0.7,0.5) (0.5,0)};
为了进行比较,Harish Kumar 的答案(均以绿色覆盖),还增加了两个节点以实现沿 x 轴的平滑。
\draw[thick,green, rounded corners=4mm ] (7.7,0) -- (7.3,0)--(7,3)--(5,4)--(4.7,0) -- (4.3,0);
答案2
您可以使用rounded corners
:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%axes
\draw[very thick] (0,0)--(8,0);
\draw[very thick] (0,0)--(0,5) coordinate (y);
\draw (8,0) node[below] {Energy};
\node [draw=none,rotate=90, yshift=0.3cm] at (0,5) {Counts};
%1st peak
\draw[thick,blue,rounded corners=4mm] (7.3,0)--(7,3)--(5,4)--(4.7,0);
\draw[blue,dashed] (7,0)-- node[pos=1.1,above,right] {$4$}(7,2.6);
\draw[blue,dashed] (5.1,0)-- node[pos=1.1,above,left] {$3$}(5.1,3.7);
\draw[blue] (6,4.5) node[above] {$δE$};
%2nd peak
\draw[thick,red,rounded corners=4mm] (3.3,0) -- (3,2.5) -- (1,3.5) -- (0.7,0);
\draw[red,dashed] (2.9,0)-- node[pos=1.1,above,right] {$1$}(2.9,2.3);
\draw[red,dashed] (1.1,0)-- node[pos=1.1,above,left] {$2$}(1.1,3.25);
\draw[red] (2,4.5) node[above] {$δE$};
\end{tikzpicture}
\end{document}
我还对节点 1、2、3 和 4 的代码做了一些简化。