5

I have the following code:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1]

\def\normalt{\x,{4*1/exp(((\x-3)^2)/2)}}

\def\y{2}


\def\fy{4*1/exp(((\y-3)^2)/2)}


\fill [fill=orange!60] (2.0,0)--(2.0,2.5) plot[domain=2:4](\normalt) --(4,0)-- (4,2.5)-- cycle;


\draw[color=black,domain=0:6] plot (\normalt) node[right] {};


\node[below] at (3.0,0) {\tiny{51800}};
\draw[dashed] (2.0,2.5) -- (2.0 ,0) node[below] {\tiny{51300}};
\draw[dashed] (4.0,2.5) -- (4.0 ,0) node[below] {\tiny{52300}};


\draw[dashed] ({\y},{\fy}) -- ({\y},0) node[below] {$y$};
\draw[color=black,domain=0:6] plot[samples=1000] (\normalt) node[right] {};



\draw[->] (-3,0) -- (9,0) node[right] {$\overline{x}$};


\end{tikzpicture}
\end{document}

I want to shade the area between the dotted lines as shown below, but I am stuck. Can somebody help me? Note: My problem is here

\fill [fill=orange!60] (2.0,0)--(2.0,2.5) plot[domain=2:4](\normalt) --(4,0)-- (4,2.5)-- cycle;

within the code. I am not very well familiar with \fill command.

enter image description here

5
5
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[scale=1]
\def\normalt{\x,{4*1/exp(((\x-3)^2)/2)}}
\def\y{2}
\def\fy{4*1/exp(((\y-3)^2)/2)}



\node[below] at (3.0,0) {\tiny{51800}};


\path[domain=0:6,name path = plot] plot (\normalt);
\path[name path= r] (4.0,0) --+ (0,2.75);
\path[name intersections={of=r and plot}];                         
\coordinate(R) at (intersection-1);


\fill [fill=orange!60]plot[domain=2:4](\normalt)-- cycle;
\fill [fill=orange!60](2,0)rectangle(R);


\draw[dashed] (2.0,0) node[below] {\tiny{51300}} --+ (0,2.75);
\draw[dashed,name path= r] (4.0,0) node[below] {\tiny{52300}} --+ (0,2.75);


\node at ({\y},-0.5) {$y$};
\draw[color=black,domain=0:6] plot[samples=1000] (\normalt) node[right] {};
\draw[->] (-3,0) -- (9,0) node[right] {$\overline{x}$};
\end{tikzpicture}
\end{document}

Maybe try this one - i've calculated the intersection of the right line with the plot and then filled a rectangle from the starting point of the left line to the intersection. Also filled the plot between 2 and 4.

Also changed the "y"-node so it does not interfere with the "51300" and made some other minor adjustments.

enter image description here

Here's an easier solution - looks the same as the one above:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1]
\def\normalt{\x,{4*1/exp(((\x-3)^2)/2)}}
\def\y{2}
\def\fy{4*1/exp(((\y-3)^2)/2)}

%Fill
\fill [fill=orange!60](2,0)--plot[domain=2:4](\normalt)--(4.0,0)-- cycle;

%Descriptions
\draw[dashed] (2.0,0) node[below] {\tiny{51300}} --+ (0,2.75);
\node[below] at (3.0,0) {\tiny{51800}};
\draw[dashed] (4.0,0) node[below] {\tiny{52300}} --+ (0,2.75);

%Plot
\draw[color=black,domain=0:6] plot[samples=1000] (\normalt) node[right] {};

%Axes
\node at ({\y},-0.5) {$y$};
\draw[->] (-3,0) -- (9,0) node[right] {$\overline{x}$};
\end{tikzpicture}
\end{document}
5
  • Have you run the codes? It seems there are some errors.
    – Hassan
    Jul 17 '13 at 6:36
  • The second code is just the repetition of mine.
    – Hassan
    Jul 17 '13 at 6:39
  • I've run both (with the current version of MikTeX on Win7 64). The difference in the second version is in this line: \fill [fill=orange!60]plot[domain=2:4](\normalt)-- cycle; where you have \fill [fill=orange!60] (2.0,0)--(2.0,2.5) plot[domain=2:4](\normalt) --(4,0)-- (4,2.5)-- cycle; Also: Do you want to paint the whole area? Misinterpreted the question - i'll fix my answers, be patient.
    – oerpli
    Jul 17 '13 at 6:43
  • I've updated it - I hope this version does what you want to do.
    – oerpli
    Jul 17 '13 at 6:49
  • yes. It is alright now. I must used used the package from tikzlibrary (intersection). Thanks @oerpli, you have saved me.
    – Hassan
    Jul 17 '13 at 6:58

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.