x
我正在尝试制作一个带有网格背景的图表。我希望它是标准窗口大小,但我只希望轴和轴上的 -10 和 10 旁边有数字y
。我正在使用此代码
\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}
当我改变xtick={-10,...,10},
网格时,其他所有不-10
或的刻度也会消失10
我怎样才能使勾号存在但没有数字呢?
更新:这是修复原始问题的更新版本,但现在我正在尝试找出 x 轴、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}
答案1
您可以使用
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},
代码:
\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},
在轴选项中获取
对于编辑的问题,您必须指定xlabel
和ylabel
。
xlabel=$x$,
ylabel=$y$,
xlabel style ={at={(1,0.5)},above right},
ylabel style ={at={(0.5,1)},above right},
完整的代码以消除混淆。
\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}