0

I used \includegraphics[height=1.91in,width=5in]{L1F2.jpg} to insert an image in the document. B ut I would like to draw similar picture in latex and add my own text on it similar to what is included and change the arrows a little. What is the best way to do so?

enter image description here

Torbjørn T.
  • 206,688

2 Answers2

1

I'd use PSTricks. Here is a sample code:

\documentclass[12pt]{article}
\usepackage{pst-all,pst-infixplot,pst-blur}
\begin{document}
\begin{center}
\begin{pspicture}(-1,-1.5)(3.5,1.5)
 \psline{->}(0,0)(0,4)\rput[r](-0.1,3.8){$y$}
 \psline{->}(0,0)(4,0)\rput[t](3.8,-0.1){$x$}
 \psline[linecolor=orange]{-}(0,1)(4,3)
 \psset{plotpoints=1000}
 \infixtoRPN{0.4*2.7^(-10*x*x)}
 \psline(1,0.5)(1,2.5)
 \rput[l]{-90}(1,1.5){\psplot[linecolor=blue]{-0.8}{0.8}{\RPN}}
 \pnode(1,1.5){k1}
 \psline(2,1)(2,3)
 \rput[l]{-90}(2,2){\psplot[linecolor=blue]{-0.8}{0.8}{\RPN}}
 \pnode(2,2){k2}
 \psline(3,1.5)(3,3.5) 
 \rput[l]{-90}(3,2.5){\psplot[linecolor=blue]{-0.8}{0.8}{\RPN}}
 \pnode(3,2.5){k3}
 \pnode(3.2,2.8){p1}
 \rput[r]{0}(-0.2,2){\ovalnode[shadow=true,blur=true]{E}{$E[Y_1]=\beta_0+\beta_1\,X_1$}}
 \ncarc{->}{E}{k1}
 \rput[l]{0}(4,3){\ovalnode[shadow=true,blur=true]{dis}{Distribution of $\epsilon_3$}}
 \rput(1,0){$|$}\rput[t](1,-0.1){$x_1$}
 \rput(2,0){$|$}\rput[t](2,-0.1){$x_2$}
 \rput(3,0){$|$}\rput[t](3,-0.1){$x_3$}
 \ncarc{->}{dis}{p1}
 \end{pspicture}
\end{center}
\end{document}
\endinput

enter image description here

  • See also http://tex.stackexchange.com/questions/9559/drawing-on-an-image-with-tikz – John Kormylo Dec 31 '16 at 20:34
  • Could you turn this into a complete example, with the necessary packages? (And perhaps explain quickly how to compile it, as it doesn't work out of the box with pdflatex. Not everyone is familiar with PSTricks.) – Torbjørn T. Dec 31 '16 at 21:03
  • Thank you Muchael Ratz for the code. I tried running the code but it is not working. Could you please tell me if I can use this in article and what package i need to use – Falcon-StatGuy Dec 31 '16 at 21:22
  • I understand the problems but also think it is very inconvenient to always present all the LaTeX overhead such as \documentclass etc. I never got PSTricks to work with pdflatex, but it would be great if I could learn a way to make this work. (pdftricks does NOT work.) I `amended' my previous version by all the overhead. You need to latex it and then convert the dvi to eps or pdf. –  Jan 10 '17 at 16:48
0

There are several methods/packages for "programming" diagrams with LaTeX. Perhaps the most popular package these days is TikZ. There will also be multiple ways of doing this with TikZ, I present one option below, which produces this:

enter image description here

There are a few comments in the code, but they're by no means very detailed. The manual, which will seem very large and intimidating at first, is a very useful reference. It also starts out with a few tutorials, aimed at introducing new users to making diagrams with TikZ.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{
   arrows.meta, % supplies the Stealth arrow tip
   bending
}
\tikzset{
  distribution/.pic={ % define a small "picture" that can be used multiple times
    \draw [thick] (0,1) -- (0,-1);
    \draw [thin,dotted] (0,0) coordinate (-origin) -- (0.7,0);
    \draw [blue] (0.05,1) .. controls (0.08,0.2) and (0.6,0.3) .. 
                 coordinate[pos=0.5] (-left)
                 (0.6,0)  .. controls (0.6,-0.3) and (0.08,-0.2) .. 
                 (0.05,-1)
                 coordinate[pos=0.5] (-right);
    }
}
\begin{document}

\begin{tikzpicture}
% draw the axis with labels
\draw [Stealth-Stealth] (0,4) node[left]{$y$} |- (6,0) node[below] {$x$};
% draw the straight line plot
\draw [orange] plot[domain=0:6,samples=2](\x,1+\x*0.5);

% a loop to add the small distribution graphs and ticklabels on x-axis at three x-values
\foreach [count=\i] \x in {1.5,3,4.5} {
   \draw (\x,1+\x*0.5) pic (p\i) {distribution}; % pic{distribution} draws the small picture defined above
   \draw (\x,3pt) -- (\x,0) node[below] {$x_\i$}; % draw the tick and ticklabel
}

% draw arrows with annotations
\draw [-Stealth] (p3-right) to[out=-45,in=180] ++(0.8,-0.5) node[right] {Distribution of $\epsilon_3$};
\draw [Stealth-,shorten <=3pt] (p1-origin) -- ++(-1.7,0.2) node[left] {$E(Y_1) = \beta_0 + \beta_1X$};
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688