
Ich versuche, ein Diagramm mit einem Gitter im Hintergrund zu erstellen. Ich möchte, dass es die Standardgröße von Windows hat, aber ich möchte nur Zahlen neben -10 und 10 auf der x
Achse und y
der Achse. Ich verwende diesen Code
\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}
Wenn ich xtick={-10,...,10},
das Raster ändere, verschwindet auch alles andere, was nicht -10
oder10
Wie kann ich erreichen, dass die Häkchen da sind, die Zahlen aber nicht?
Aktualisiert: Dies ist die aktualisierte Version, die das ursprüngliche Problem behoben hat, aber jetzt versuche ich, eine gute Platzierung für die Beschriftungen der X- und Y-Achse zu finden.
\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}
Antwort1
Sie können
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},
Code:
\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},
in den Achsenoptionen, um
Für die bearbeitete Frage müssen Sie xlabel
und angeben ylabel
.
xlabel=$x$,
ylabel=$y$,
xlabel style ={at={(1,0.5)},above right},
ylabel style ={at={(0.5,1)},above right},
Vollständiger Code, um Verwirrung zu vermeiden.
\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}