假设你想画一个图:
\documentclass[dvipsnames]{article}
\usepackage{pgfplots}
\usetikzlibrary{babel,calc,backgrounds,quotes,angles,patterns,decorations.markings,intersections,arrows,arrows.meta}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
axis line style = {-Latex[round],very thick},
% enlargelimits = true,
grid = both,
grid style={help lines},
xmin = -4,
ymin = -3.1,
xmax = 4,
ymax = 4,
xtick = {-3, ..., 3},
ytick = {-3, ..., 3},
xlabel style={below right},
ylabel style={above left},
x tick label style={below left},
samples = 100,
axis on top=true,
xlabel = {$x$},
ylabel = {$y$},
]
\coordinate (O) at (0, 0);
\addplot[very thick, color=Mahogany] {-x^2 + 2};
\end{axis}
\end{tikzpicture}
\end{document}
结果是:
如何做出一些奇特的改变:
使 x 的右下方有勾号标签表示负 x,使 x 的左下方有勾号标签表示正 x;
仅显示这些点的刻度标签:(0, 0)、(1, 0)、(0, 1)、(-1, 0)、(0, -1)?如果我更改 xtick = {-3, ..., 3} 和 ytick = {-3, ..., 3},它将更改网格,但我希望将其保留为 {-3, ..., 3) 刻度。
答案1
编辑:
第一次尝试时,根据 OP 评论,显然我没有理解问题。第二次尝试是基于猜测,但我不确定想要的结果是什么...
\documentclass[dvipsnames, margin=3mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta,
%
babel % for languages issues, not needed in this MWE
} % other libraries are not used
\pgfplotsset{compat=1.17}
%\usepgfplotslibrary{fillbetween} % not used
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=9cm, % enlarged image width
axis lines = middle,
axis line style = {-Latex[round], very thick},
% grid,
xmin = -3.5, xmax = 3.5,
ymin = -3.5, ymax = 3.5,
xtick = {-3,...,3},
% added, for tick labels placements
tick style = {major tick length=3mm,
semithick,
color=black},
xticklabels={,,$-1$, , , , },
xticklabel style = {inner sep=2pt,
anchor=north west,
font=\footnotesize},
extra x ticks={0,1},
extra x tick labels={0,1},
extra x tick style={tick label style={xshift=-0.9em}},
yticklabels=\empty,
extra y ticks={-1,1},
xlabel = {$x$},
ylabel = {$y$},
xlabel style={below right},
ylabel style={above left},
axis on top,
samples = 100, %
]
\addplot[very thick, color=Mahogany] {-x^2 + 2};
\end{axis}
\end{tikzpicture}
\end{document}