
背景にグリッドのあるグラフを作成しようとしています。標準のウィンドウサイズにしたいのですが、x
軸とy
軸の両方で -10 と 10 の横に数字だけを表示したいです。このコードを使用しています。
\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}