1

Taking this example, I build my gaussian bell

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{document}

\begin{figure} \centering \begin{tikzpicture} \begin{axis}[ yticklabels=\empty, xticklabels=\empty, width=8cm, height=6cm, xtick=\empty, ytick=\empty, clip mode=individual, xlabel={$T$}, ylabel={$\Delta T$}, ] \addplot[smooth,red,samples=50,domain=-2:3]{gauss(1,0.75)}; \end{axis} \end{tikzpicture} \end{figure} \end{document}

enter image description here

But if I add \addplot[smooth,blue]{x*1.33 + 1.36}; before or after the curve, my bell become

enter image description here

How can I fix it?

user3713179
  • 635
  • 2
  • 11

1 Answers1

1

What you have is the correct representation of the graph, so I am not sure what there is to be fixed here...

If you allow the plotting of the axis ticks labels, you can see that your gaussian has values in the [0..1] range and the straight line in the [-5..7+] range (I didn't calculate precisely; remember that the default domain is -5..5). You can limit the domain for everything, but still, the graph will be in scale.


\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{document}

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

a Gaussian and a straight line

If you want a quantitative (correct) graph and have a better vertical resolution for the bell curve, you can use a different axis for one of them.

The other option, if you want only a qualitative graph, is to scale one of the two, for example, multiply the Gaussian by, say, 8:

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{document}

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

enter image description here

...but pgfplots will show you the actual values of the functions, always.

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • What I need is the bell like the first pic I posted – user3713179 Oct 20 '22 at 14:49
  • 1
    @user3713179 I do not understand: the curves are correctly plotted; if you want the bell bigger, just multiply it by a number. But if you plot both function against the same axis, you have what you have: the bell has a maximum=1 and the straight line goes from about -1 to about 6. – Rmano Oct 20 '22 at 16:09
  • 1
    I added a plot that seems similar to the first one you posted, but notice that now the bell is 8 times bigger. Are you sure about your objective? I think it's a bit confused... – Rmano Oct 20 '22 at 16:16