2

With some effort, I was able to find a way to mark the intersection points between the Gaussian bell and the straight line. Leaving aside the first point, I would need to project the two intersection points onto the abscissa axis. My idea is this: extract the x coordinate of the intersection point, called e.g. x_1, and create a node at point (x_1,0).

Is it possible to accomplish such a thing?

Here my MWE

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\newcommand*{\ShowIntersection}[2]{
\fill 
    [name intersections={of=#1 and #2, name=i, total=\t}] 
    [red, opacity=1, every node/.style={above left, black, opacity=1}] 
    \foreach \s in {1,...,\t}{(i-\s) circle (2pt)
        node [above left] {\s}};
}
\begin{document}

\begin{figure}
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            yticklabels=\empty, xticklabels=\empty,
            width=8cm,
            height=6cm,
            domain=-2:3, ymin = 0.07, xmin = -2, enlargelimits=upper,
            xtick=\empty, ytick=\empty,
            clip mode=individual,
            xlabel={$T$}, ylabel={$\Delta T$},
            ]
            \addplot[smooth,red,samples=50,domain=-2:3,name path=gaussian]{8 * gauss(1,0.75)};
            \addplot[smooth,blue,name path=line]{x*1.13 + 1.36};
            \ShowIntersection{gaussian}{line}
        \end{axis}
    \end{tikzpicture}
\end{figure}

\end{document}

enter image description here

2
  • If you just want the projection from 2 or 3 to the axis, something like \draw (i-2)--(i-2|-0,0); will do it. If you want to write the T value, it's another question.
    – Ignasi
    Commented Oct 21, 2022 at 12:18
  • Not related to the question but why repeating node [above left] when you already said every node is above left?
    – SebGlav
    Commented Oct 21, 2022 at 12:38

1 Answer 1

2

This solution draws the projection of the intercepts onto the x-axis and retrieves the value x using \pgfplotspointgetcoordinates

y

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfmathdeclarefunction{gauss}{2}{%
    \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
    
\newcommand*{\ShowIntersection}[2]{
\draw [
name intersections={of=#1 and #2,name=i, total=\t}, thin, dotted] 
[every node/.style={black,font=\tiny}]  
\foreach \s in {1,...,\t}
{(i-\s)  node[above left] {\s} % dysplay number of the intersection
    node[fill,red,circle,inner sep=0,minimum size=4pt]{} % big dot in the intercection
    (i-\s |- i-\s) -- (i-\s |- current axis.south) % line to projet from intesection to x-axis
    node [below,font=\tiny] {\pgfplotspointgetcoordinates{(i-\s)} % recover x-y coordinates of the intesection
        $\pgfmathprintnumber[fixed]{\pgfkeysvalueof{/data point/x}}$} % and put x below the line    
};
}

\begin{document}
    
\begin{figure}
        \centering
\begin{tikzpicture}
\begin{axis}[
    yticklabels=\empty, xticklabels=\empty,
    width=8cm,
    height=6cm,
    domain=-2:3, ymin = 0.07, xmin = -2, enlargelimits=upper,
    xtick=\empty, ytick=\empty,
    clip mode=individual,
    xlabel={$T$}, ylabel={$\Delta T$},
    ]
    \addplot[smooth,red,samples=50,domain=-2:3,name path=gaussian]{8 * gauss(1,0.75)};
    \addplot[smooth,blue,name path=line]{x*1.13 + 1.36};
    \ShowIntersection{gaussian}{line}
\end{axis}
\end{tikzpicture}
\end{figure}
    
\end{document}

Now it's easy to add the y-intercepts

z

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfmathdeclarefunction{gauss}{2}{%
    \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
    
\newcommand*{\ShowIntersection}[2]{
\draw [
name intersections={of=#1 and #2,name=i, total=\t}, thin, dotted] 
[every node/.style={black,font=\tiny}]  
\foreach \s in {1,...,\t}
{(i-\s)  node[above left] {\s} % dysplay number of the intersection
    node[fill,red,circle,inner sep=0,minimum size=4pt]{} % big dot in the intercection
    (i-\s |- i-\s) -- (i-\s |- current axis.south) % line to projet from intesection to x-axis
    node [below,font=\tiny] {\pgfplotspointgetcoordinates{(i-\s)} % recover x-y coordinates of the intesection
        $\pgfmathprintnumber[fixed]{\pgfkeysvalueof{/data point/x}}$} % and put x below the line
    ( i-\s|- i-\s)--    (current axis.west |- i-\s)% line to projet from intesection to y-axis
    node [left,font=\tiny] {\pgfplotspointgetcoordinates{(i-\s)} % do it again
        $\pgfmathprintnumber[fixed]{\pgfkeysvalueof{/data point/y}}$}   % and put y left of the line
};
}

\begin{document}
    
\begin{figure}
        \centering
\begin{tikzpicture}
\begin{axis}[
    yticklabels=\empty, xticklabels=\empty,
    width=8cm,
    height=6cm,
    domain=-2:3, ymin = 0.07, xmin = -2, enlargelimits=upper,
    xtick=\empty, ytick=\empty,
    clip mode=individual,
    xlabel={$T$}, ylabel={$\Delta T$},
    ]
    \addplot[smooth,red,samples=50,domain=-2:3,name path=gaussian]{8 * gauss(1,0.75)};
    \addplot[smooth,blue,name path=line]{x*1.13 + 1.36};
    \ShowIntersection{gaussian}{line}
\end{axis}
\end{tikzpicture}
\end{figure}
    
\end{document}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.