
Estoy intentando hacer un gráfico con una cuadrícula de fondo. Quiero que tenga el tamaño estándar de Windows, pero solo quiero números al lado de -10 y 10 tanto en el x
eje como en y
el eje. Estoy usando este código
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
xmin=-10,
xmax=10,
ymin=-10,
ymax=10,
xlabel=$x$,
ylabel=$y$,
xtick={-10,...,10},
ytick={-10,...,10},
tick style={very thick},
legend style={
at={(rel axis cs:0,1)},
anchor=north west,draw=none,inner sep=0pt,fill=gray!10}
]
\addplot[domain=-3:3,blue,thick,samples=100,<->] {x^2};
\addplot[holdot] coordinates{(0,0)(4,4)(6,-5)};
\addplot[soldot] coordinates{(4,16)(6,6)(10,-5)};
%%\addlegendentry{$y=x^2$}
%%\addplot[domain=0:4,blue,] {x*x};
\addplot[domain=4:6,blue,] {x};
\addplot[domain=6:10,blue] {-5};
\end{axis}
\end{tikzpicture}
Cuando cambio xtick={-10,...,10},
la grilla también desaparece y todos los demás ticks que no están -10
o10
¿Cómo puedo hacer para que las marcas estén ahí pero los números no?
Actualizado: esta es la versión actualizada que solucionó el problema original, pero ahora estoy tratando de encontrar una buena ubicación para las etiquetas del eje x y del eje y.
\begin{tikzpicture}
\centering
\begin{axis}[
axis lines=middle,
grid=major,
xmin=-10,
xmax=10,
ymin=-10,
ymax=10,
xlabel style ={at={(1,0.5)},above right},
ylabel style ={at={(0.5,1)},above right},
xtick={-10,...,10},
xticklabels={}, %% no x tick labels
ytick={-10,...,10},
yticklabels={}, %% no y tick labels
extra x ticks={-10,10},
extra x tick labels={-10,10},
extra y ticks={-10,10},
extra y tick labels={-10,10},
tick style={very thick},
legend style={
at={(rel axis cs:0,1)},
anchor=north west,draw=none,inner sep=0pt,fill=gray!10}
]
\addplot[domain=-10:10,blue,thick,samples=1000,->] {sqrt (x+4)};
%%\addplot[holdot] coordinates{(0,0)(4,4)(6,-5)};
\addplot[soldot] coordinates{(0,2)(5,3)};
%%\addlegendentry{$y=x^2$}
%%\addplot[domain=0:4,blue,] {x*x};
%%\addplot[domain=4:6,blue,] {x};
%%\addplot[domain=6:10,blue] {-5};
\end{axis}
\end{tikzpicture}
Respuesta1
Puedes usar
xticklabels={}, %% no x tick labels
yticklabels={}, %% no y tick labels
extra x ticks={-10,10},
extra x tick labels={-10,10},
extra y ticks={-10,10},
extra y tick labels={-10,10},
Código:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
xmin=-10,
xmax=10,
ymin=-10,
ymax=10,
xlabel=$x$,
ylabel=$y$,
xtick={-10,...,10},
xticklabels={}, %% no x tick labels
ytick={-10,...,10},
yticklabels={}, %% no y tick labels
extra x ticks={-10,10},
extra x tick labels={-10,10},
extra y ticks={-10,10},
extra y tick labels={-10,10},
tick style={very thick},
legend style={
at={(rel axis cs:0,1)},
anchor=north west,draw=none,inner sep=0pt,fill=gray!10}
]
\addplot[domain=-3:3,blue,thick,samples=100,<->] {x^2};
\addplot coordinates{(0,0)(4,4)(6,-5)};
\addplot coordinates{(4,16)(6,6)(10,-5)};
%%\addlegendentry{$y=x^2$}
%%\addplot[domain=0:4,blue,] {x*x};
\addplot[domain=4:6,blue,] {x};
\addplot[domain=6:10,blue] {-5};
\end{axis}
\end{tikzpicture}
\end{document}
xlabel style ={at={(1,0.5)},above right},
ylabel style ={at={(0.5,1)},above right},
en las opciones del eje para obtener
Para la pregunta editada, debe especificar xlabel
y ylabel
.
xlabel=$x$,
ylabel=$y$,
xlabel style ={at={(1,0.5)},above right},
ylabel style ={at={(0.5,1)},above right},
Código completo para eliminar la confusión.
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\centering
\begin{axis}[
axis lines=middle,
grid=major,
xmin=-10,
xmax=10,
ymin=-10,
ymax=10,
xlabel=$x$,
ylabel=$y$,
xlabel style ={at={(1,0.5)},above right},
ylabel style ={at={(0.5,1)},above right},
xtick={-10,...,10},
xticklabels={}, %% no x tick labels
ytick={-10,...,10},
yticklabels={}, %% no y tick labels
extra x ticks={-10,10},
extra x tick labels={-10,10},
extra y ticks={-10,10},
extra y tick labels={-10,10},
tick style={very thick},
legend style={
at={(rel axis cs:0,1)},
anchor=north west,draw=none,inner sep=0pt,fill=gray!10},clip=false
]
\addplot[domain=-10:10,blue,thick,samples=1000,->] {sqrt (x+4)};
%%\addplot[holdot] coordinates{(0,0)(4,4)(6,-5)};
\addplot coordinates{(0,2)(5,3)};
%%\addlegendentry{$y=x^2$}
%%\addplot[domain=0:4,blue,] {x*x};
%%\addplot[domain=4:6,blue,] {x};
%%\addplot[domain=6:10,blue] {-5};
\end{axis}
\end{tikzpicture}
\end{document}