5

I am using tikz to recreate the following image

enter image description here

What I am trying to do is draw an "extended" and "smooth" trapezoidal shape. My code is

\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}

and my output is

enter image description here

What I'd like to do is make the angles 1,2,3,4 smoother. Also I'd like to make a bit smoother-like having a small tail-the red and blue lines that touch the x-axis. How can these be achieved?

4
  • I'm a bit confused. Isn't the shape you request built from two seperate normal (Gaussian) curves? Why not connect the average of that with two controls key'd curves? It seems to me like that makes more sense.
    – 1010011010
    Aug 20, 2014 at 9:46
  • @1010011010 : Thank's for your comment! It's not necessarily a Gaussian curve. Actually it's not a Gaussian curve. The dashed lines in the first image, are perpendicular to the x axis.
    – Thanos
    Aug 20, 2014 at 9:49
  • Maybe my eyes are going bad, but the dashed lines in the first image don't look perpendicular to the x-axis to me. :-) Aug 20, 2014 at 11:48
  • 1
    @PaulGessler : Your eyes are working perfectly fine! They're supposed to be, but they're not! It's just a bad image!
    – Thanos
    Aug 20, 2014 at 11:56

2 Answers 2

4

I'm not quite sure what you mean with "extend the two perpendicular to the x-axis lines" but at least drawing a smooth line can be achieved with Bezier curves.

On a straight line like (a) -- (b) you can add (multiple) control point(s) x to create a smooth curve with (a) .. controls (x) .. (b)

(Taken from here)

EDIT: Thanks for editing your question :) let me then revise my answer...

Actually there is a "smooth" modifier for plotting. Additionally, I added another coordinate at the end and at the beginning and increased the y-value of the neighboring coordinates:

\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)};

For comparison the answer of Harish Kumar (both overlaid in green), also with two additional nodes to achieve smoothing along the x-axis.

\draw[thick,green, rounded corners=4mm ] (7.7,0) -- (7.3,0)--(7,3)--(5,4)--(4.7,0) -- (4.3,0);

enter image description here

3
  • Thank's for your answer! It's not easy however to control point 2. \draw[thick,red] (3,0) .. controls (3,2.5) and (1,3.5) .. (1,0); imgur.com/4vOfKZe
    – Thanos
    Aug 20, 2014 at 9:54
  • @Thanos Yes, you probably need more points for that: \draw[thick,red] (3,0) .. controls (3,2.5) .. (2,3.0) .. controls (1,3.5) .. (1,0);
    – Harald
    Aug 20, 2014 at 10:03
  • I've edited my question! Thank you very much for your help and time!
    – Thanos
    Aug 20, 2014 at 10:16
5

You can use 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}

enter image description here

I have also made some simplifications in the code for nodes 1, 2, 3 and 4.

6
  • Thank you very much for you answer! It was a great help! I've picked Harald's answer for two reasons. Mainly because it consists of two answers(his and yours) and therefore it's more complete and secondly because he has less reputation :P Just for the record, I am using your suggested rounded corners option!
    – Thanos
    Aug 20, 2014 at 12:19
  • @Thanos Thank you! It even consists of three answers (the controls one, too) :P
    – Harald
    Aug 20, 2014 at 12:47
  • @Harald : Indeed it does! :P Thank's again!
    – Thanos
    Aug 20, 2014 at 12:50
  • @Thanos Oh No! ;-) Joking, it is OK. You can always upvote my other answers (as a compensation :P) if you like them.
    – user11232
    Aug 20, 2014 at 23:07
  • @HarishKumar I certainly did so after "borrowing" your answer :)
    – Harald
    Aug 21, 2014 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.