2
\documentclass[a4paper,11pt,fleqn]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgf,tikz}
\usepackage{graphicx}
\usepackage{array}
\usepackage[ngerman]{babel}
\usepackage{gauss}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{positioning,fit,calc}

\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}[scale only axis,
         axis lines =middle,
                     ylabel style = {align=left},
         inner axis line style={=>},
                 width=10cm,height=6cm,
                     ymin=0,ymax=0.45,
                     xmin=496,xmax=504,
                     axis line style = thick,
                     xtick={497,498,499,500,501,502,503},
                     ytick={0.1,0.2,0.3,0.4},
                 every axis x label/.style={at={(current axis.right of origin)},anchor=west},
         every axis y label/.style={at={(current axis.north)},above=0.5mm},
                 xlabel={$x$},
                 ylabel={$f(x)$},
                     axis on top]
\addplot [domain=496:504,samples=500,red,thick] {gauss(500,16/16)};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

My problem: Try to produce two different plots

  1. First plot the y-axis should intersect the x-axis at 496, thus on the left side and the label should be on top of the y-axis (picture)

  2. Second plot the y-axis should intersect the x-axis at its middle (500) and the label should be on top

enter image description here

Torbjørn T.
  • 206,688
user150752
  • 155
  • 2
  • 11
  • You need both plots in the same tikzpicture or in separate ones? if in the same, it reduces the problem just to plot an extra y-axis in your original plot, right? – Cragfelt Dec 18 '17 at 10:17

2 Answers2

2

Your question is not clear in what you want, whether both plots in the same tikzpicture (coordinate system) or in separate ones.

Anyways, if in the same, it reduces the problem just to plot an extra y-axis in your original plot.

I am posting both alternatives:

Two separate plots

enter image description here

\documentclass[a4paper,11pt,fleqn]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgf,tikz}
\usepackage{graphicx}
\usepackage{array}
\usepackage[ngerman]{babel}
\usepackage{gauss}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{positioning,fit,calc}

\pgfmathdeclarefunction{gauss}{2}{\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}}

\begin{document}

% First Plot
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[%
        scale only axis,
        axis lines = middle,
        ylabel style = {align=left},
        inner axis line style={=>},
        width=6cm, height=6cm,
        ymin=0,ymax=0.45,
        xmin=500,xmax=504,
        axis line style = thick,
        xtick={500,501,502,503},
        ytick={0.1,0.2,0.3,0.4},
        every axis x label/.style={at={(current axis.right of origin)},anchor=west},
        every axis y label/.style={at={(current axis.north west)}, above=0.5mm},
        xlabel={$x$},
        ylabel={$f(x)$},
        ]
\addplot [domain=500:504,samples=500,red,thick] {gauss(500,16/16)};
\end{axis}
\end{tikzpicture}

% Second Plot

\begin{tikzpicture}
\begin{axis}[%
        scale only axis,
        axis lines =middle,
        ylabel style = {align=left},
        inner axis line style={=>},
        width=10cm,height=6cm,
        ymin=0,ymax=0.45,
        xmin=496,xmax=504,
        axis line style = thick,
        xtick={497,498,499,500,501,502,503},
        ytick={0.1,0.2,0.3,0.4},
        every axis x label/.style={at={(current axis.right of origin)},anchor=west},
        every axis y label/.style={at={(current axis.north west)}, above=0.5mm},
        xlabel={$x$},
        ylabel={$f(x)$},
        axis on top
        ]
\addplot [domain=496:504,samples=500,red,thick] {gauss(500,16/16)};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

Two y-axes in one plot.

enter image description here

\begin{tikzpicture}
\begin{axis}[%
        scale only axis,
        axis lines =middle,
        ylabel style = {align=left},
        inner axis line style={=>},
        width=10cm,height=6cm,
        ymin=0,ymax=0.45,
        xmin=496,xmax=504,
        axis line style = thick,
        xtick={497,498,499,500,501,502,503},
        ytick={0.1,0.2,0.3,0.4},
        every axis x label/.style={at={(current axis.right of origin)},anchor=west},
        every axis y label/.style={at={(current axis.north west)}, above=1mm},
        ymajorgrids,
        xlabel={$x$},
        ylabel={$f(x)$},
        axis on top
        ]
\addplot [domain=496:504,samples=500,red,thick] {gauss(500,16/16)};
\end{axis}

\draw[-stealth, thick] (5,0)--(5,6) node[label=above:$f(x)$]{};

\end{tikzpicture}
Cragfelt
  • 4,005
1

if i understand you correctly, than you looking for:

enter image description here

code for above image is based on my answer to your previous question:

\documentclass[a4paper,11pt,fleqn]{scrartcl}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\pgfmathdeclarefunction{gauss}{2}{%
    \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
                                }

\begin{document}
    \begin{figure}[htb]
    \centering
\begin{tikzpicture}% left picture
\begin{axis}[
    width=6cm,height=6cm,
        scale only axis,
        axis lines=center,
        ymin=0,ymax=0.45,
        axis line style = thick,
        xtick={500,501,502,503},
            extra x ticks={500},
            extra x tick label={500},
        x label style={anchor=west},
        y label style={anchor=south},
        xlabel={$x$},
        ylabel={$f(x)$},
        axis on top,
        samples=50]
\addplot [domain=500:504,red,thick] {gauss(500,16/16)};
\end{axis}
\end{tikzpicture}
    \hfill        
\begin{tikzpicture}% right picture
\begin{axis}[
    width=6cm,height=6cm,
        scale only axis,
        axis lines=center,
        xmin=-4,xmax=4,
        ymin=0,ymax=0.45,
        axis line style = thick,
        xtick={-3,-2,-1,1,2,3},
        xticklabels={497,...,503},
            extra x ticks={0},
            extra x tick label={500},
        x label style={anchor=west},
        y label style={anchor=south},
        xlabel={$x$},
        ylabel={$f(x)$},
        axis on top,
        samples=50]
\addplot [domain=-3:3,red,thick] {gauss(0,1)};
\end{axis}
\end{tikzpicture}
    \end{figure}
\end{document}

edit: with defining of common axis features by \pgfplotsset you will obtain shorter code (giving the same result as mwe above):

\documentclass[a4paper,11pt,fleqn]{scrartcl}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\pgfmathdeclarefunction{gauss}{2}{%
    \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
                                }

\begin{document}
    \begin{figure}[htb]
    \centering
\pgfplotsset{width=6cm,height=6cm,
             scale only axis,
             axis lines=middle,
             ymin=0,ymax=0.45,
             axis line style = thick,
             xlabel={$x$},
             ylabel={$f(x)$},
             x label style={anchor=west},
             y label style={anchor=south},
             axis on top,
             samples=50}
        \begin{tikzpicture}% left picture
\begin{axis}[
    xtick={500,501,502,503},
    extra x ticks={500},
    extra x tick label={500}
                ]
\addplot [domain=500:504,red,thick] {gauss(500,16/16)};
\end{axis}
\end{tikzpicture}
    \hfill
\begin{tikzpicture}% right picture
\begin{axis}[
    xmin=-4,xmax=4,
    xtick={-3,-2,-1,1,2,3},
    xticklabels={497,...,503}
            ]
\addplot [domain=-3:3,red,thick] {gauss(0,1)};
\end{axis}
\end{tikzpicture}
    \end{figure}
\end{document}
Zarko
  • 296,517