0

The Grid goes beyond the graph, as you can see in the screenshot below. What do i have to change, to make the grid align with the graph? It should only be inside the coordinate system.

\usepackage{tkz-euclide}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
\usetikzlibrary{positioning}

\begin{figure}
\begin{center}
\begin{tikzpicture}
\tkzInit[ymax=6, xmin=-6, ymin=-1]
\tkzGrid[xmax=6, ymax=6]
%\tkzAxeXY
\begin{axis}[
    xlabel=x, 
    ylabel={y}, % max(0, x)
    legend pos=north west,
    legend cell align=left
]
\addplot[color=blue]{max(0, x)};
\addplot[color=red]{1/(1+exp(-x))};
\addplot[color=green]{(exp(x)-exp(-x))/(exp(x)+exp(-x))};
\addlegendentry{ReLu(x)}
\addlegendentry{sigmoid(x)}
\addlegendentry{tanh(x)}
\end{axis}
\end{tikzpicture}
\caption{Relu und sigmoid function}
\end{center}
\end{figure}

    

enter image description here

1
  • 2
    It seems like you are mixing two packages. pgfplots works on its own and also uses its own coordinates system, so it's better to use this package's options: - Remove the \tkzInit and \tkzGrid commands - To add a grid in the axis environment, just add the option grid. If you want to change the axis limits, you can add the options 'xmin=...` in the axis environment. You can read the documentation for more details
    – Morshu3
    Aug 3 at 21:01

1 Answer 1

2
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xlabel=x, 
    ylabel=y,
    legend pos=north west,
    legend cell align=left,
    grid,
    ytick distance=1,
]
\addplot[blue] {max(0, x)};
\addplot[red] {1/(1+exp(-x))};
\addplot[green] {(exp(x)-exp(-x))/(exp(x)+exp(-x))};
\addlegendentry{ReLu(x)}
\addlegendentry{sigmoid(x)}
\addlegendentry{tanh(x)}
\end{axis}
\end{tikzpicture}
\end{document}

Graph with grid lines

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.