
Estou tentando fazer um gráfico com uma grade em segundo plano. Quero que seja o tamanho padrão do Windows, mas só quero números próximos a -10 e 10 no x
eixo e y
no eixo. Estou usando esse 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}
Quando mudo xtick={-10,...,10},
a grade também desaparece e todos os outros ticks que não estão -10
ou10
Como posso fazer com que os ticks estejam lá, mas os números não?
Atualizado: esta é a versão atualizada que corrigiu o problema original, mas agora estou tentando descobrir um bom posicionamento para as etiquetas do eixo x e eixo 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}
Responder1
Você pode 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},
nas opções do eixo para obter
Para a pergunta editada, você deve especificar xlabel
e 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 remover confusão.
\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}