Nodo en un sistema de coordenadas con tikz.

Nodo en un sistema de coordenadas con tikz.

Me gustaría crear un TikZcomando que cree un sistema de coordenadas. Hasta ahora, he creado este MWE:

\documentclass[12pt,a4paper, xcolor=dvipsnames]{scrartcl}
\PassOptionsToPackage{svgnames}{xcolor}

\usepackage{tikz}

\newcommand{\coordinatesystem}[4]{
    \begin{tikzpicture}
        \draw[step=1, gray!40] (#1,#2) grid (#3,#4);
        \draw[-stealth,very thick] (#1,0) -- (#3,0);
        \draw[-stealth,very thick] (0,#2) -- (0,#4);
        \foreach \x in {#1,...,#3}
        \foreach \y in {#2,...,#4}
        {
            \node[text=gray!30, below] at (\x,0) {$\x$};
            \node[text=gray!30, left] at (0,\y) {$\y$};     
        }
    \end{tikzpicture}
}

\begin{document}

\coordinatesystem{-5}{-5}{3}{4}

\end{document}

Me gustaría que los nodos del eje x estuvieran un poco más hacia la derecha para evitar una colisión con las líneas del sistema de coordenadas. De manera similar, me gustaría que los nodos del eje y fueran ligeramente más altos de lo que están ahora. es posible?

Respuesta1

Si no desea imprimir ceros en las escalas xy, modifique su código de esta manera:

\documentclass[12pt,a4paper]{scrartcl}

\usepackage{tikz}

\newcommand{\coordinatesystem}[4]{
    \begin{tikzpicture}
        \draw[step=1, gray!40] (#1,#2) grid (#3,#4);
        \draw[-stealth,very thick] (#1,0) -- (#3,0);
        \draw[-stealth,very thick] (0,#2) -- (0,#4);
        \foreach \x in {#1,...,#3}
        \foreach \y in {#2,...,#4}
        {
            \ifnum \x=0 
            \relax%
            \else %
            {\node[text=gray!30, below] at (\x,0)  {$\x$};}
            \fi
            
            \ifnum \y=0 
            \relax%
            \else %
            {\node[text=gray!30, left] at (0,\y) {$\y$};}
            \fi     
        }
        \node[text=gray!30] at (-.3,-.3) {$O$};
    \end{tikzpicture}
}

\begin{document}
    \noindent
    \coordinatesystem{-5}{-5}{3}{4}\,
    \coordinatesystem{-4}{-5}{4}{4}
    
\end{document}

Producción:

ingrese la descripción de la imagen aquí

AGREGAR: En cualquier caso, un sistema de coordenadas por sí solo es inútil. Con la respuesta anterior no puedes poner ningún gráfico o diagrama. Entonces necesitas tener el \begin{tikzpicture}y \end{tikzpicture}fuera de la definición \newcommand y tener, por ejemplo, algo como esto:

\documentclass[12pt,a4paper]{scrartcl}

\usepackage{tikz}

\newcommand{\coordinatesystem}[4]{
        \draw[step=1, gray!40] (#1,#2) grid (#3,#4);
        \draw[-stealth,very thick] (#1,0) -- (#3,0);
        \draw[-stealth,very thick] (0,#2) -- (0,#4);
        \foreach \x in {#1,...,#3}
        \foreach \y in {#2,...,#4}
        {
            \ifnum \x=0 
            \relax%
            \else %
            {\node[text=gray!30, below] at (\x,0)  {$\x$};}
            \fi
            
            \ifnum \y=0 
            \relax%
            \else %
            {\node[text=gray!30, left] at (0,\y) {$\y$};}
            \fi     
        }
        \node[text=gray!30] at (-.3,-.3) {$O$}; 
        }

\begin{document}
    \noindent
    \begin{tikzpicture}
    \coordinatesystem{-4}{-5}{4}{4}
    \clip (-4,-5) rectangle (4,4);
    \draw[cyan,line width=2pt] plot[domain=-4:4] (\x,-\x-1);
    \draw[magenta,line width=2pt] plot[domain=-4:4,smooth] (\x,\x*\x-4);
\end{tikzpicture}
\end{document}

Con el código anterior tienes este resultado:

ingrese la descripción de la imagen aquí

información relacionada