...
xmin = -0.05, xmax = 1.1,
ymin = -0.05, ymax = 1.4,
...
...
xmin = -0.05, xmax = 1.1,
ymin = -0.05, ymax = 1.3,
...
完整代码
\documentclass[tikz,border=5pt]{standalone}
\usepackage[UTF8]{ctex} % 加载中文支持
\usepackage{pgfplots} % 核心绘图库
\usepackage{bm} % 或
\usepackage{amsmath}
\usepackage{silence}
% 定义 Times New Roman 字体命令
\WarningFilter{latexfont}{} % 过滤所有字体警告
\pgfplotsset{compat=1.18} % 版本兼容性设置
\usetikzlibrary{positioning,arrows.meta,angles,quotes,matrix,calc,fillbetween,patterns,patterns.meta}
\usepgfplotslibrary{fillbetween}
\usepackage{newtxtext, newtxmath} % Times 风格字体
\usepackage{bm} % 加粗数学符号
\newcommand{\bt}[1]{\bm{\mathit{#1}}} % 自定义加粗倾斜命令
\newcommand{\axisarrow}
{axis line style = {-{Triangle[length=8pt, width=3pt]}},} % 修正箭头语法
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
width=6cm, % 根据x轴范围计算宽度
height=6cm, % 根据y轴范围计算高度
%将标签定位在x轴的最末端(刻度坐标系中,1表示100%位置)
xlabel style={at={(ticklabel* cs:1)}, anchor=west, right=1pt},
ylabel style={at={(ticklabel* cs:1)}, anchor=south, above=1pt},
%
xmin = -0.05, xmax = 1.1,
ymin = -0.05, ymax = 1.3,
\axisarrow % 已经有逗号
xtick distance = 0.2, % x轴每1单位一个主刻度
ytick distance = 0.2, % y轴每0.5单位一个主刻度
% tick style={draw=none}, % 隐藏所有刻度线
every outer x axis line/.append style={shift={(0.5,0)}}, % 控制箭头位置(x偏移)
every outer y axis line/.append style={shift={(0,0.5)}} % 控制箭头位置(y偏移)
]%不能空行
% 抛物线 y = x²
\addplot[name path=A, domain=0:1.4, thick, blue, samples=100] {x^2};
\node[blue, anchor=west] at (rel axis cs:1.02,0.8) {\footnotesize$y = x^2$};
% 抛物线 x = y²(即 y = ±sqrt(x))
\addplot[name path=B, domain=0:1.4, thick, red, samples=100] {x^(1/2)};
\node[red, anchor=west] at (rel axis cs:1.02,0.2) {\footnotesize$x = y^2$};
% 填充两条抛物线围成的区域(第一象限)
% \addplot[gray, opacity=0.5]
% fill between [of=A and B, soft clip={domain=0:1}, split];
% 填充两条抛物线围成的区域(第一象限)
\addplot[lightgray, opacity=0.5]
fill between [of=A and B,
soft clip={domain=0:1},
split];
%条纹矩形
\draw[fill=white, line width=0.2pt] (axis cs:0.37,0.11) rectangle (axis cs:0.43,0.66);
\draw[
pattern = {Lines[angle=45, distance=1.5pt, line width=10pt]},
pattern color = gray!60
] (axis cs:0.37,0.11) rectangle (axis cs:0.43,0.66);
\end{axis}
\node[below=10pt of current bounding box.south, anchor=north]{图\,4.6};
\end{tikzpicture}
\end{document}
明明下面的十几行就可以完全反映你的问题,为什么要上传七八十行的代码(?) Tell Me Why?! Why?!
这给别人增加了很大的负担
\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
xmin = -0.05, xmax = 1.1,
ymin = -0.05, ymax = 1.4,
axis line style = {-{Triangle[length=8pt, width=3pt]}},
ytick distance = 0.2,
]
\addplot[domain=0:1.4, thick, blue, samples=100] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
坐标轴刻度线与箭头距离太近,增大xmax
或ymax
时坐标轴并没有延长相应的单位长度
指定ymax=1.35
不可以吗? 不是很清楚你的具体需求?
\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
xmin = -0.05, xmax = 1.1,
ymin = -0.05, ymax = 1.35,
axis line style = {-{Triangle[length=8pt, width=3pt]}},
ytick distance = 0.2,
]
\addplot[domain=0:1.4, thick, blue, samples=100] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
tikz
的arrow
提供的shorten >=
功能调整「箭头末端」的长度:读文档!
\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
xmin = -0.05, xmax = 1.1,
ymin = -0.05, ymax = 1.4,
axis line style = {-{Triangle[length=8pt, width=3pt]},shorten >=-.8cm},
ytick distance = 0.2,
]
\addplot[domain=0:1.4, thick, blue, samples=100] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
这将在保持使用ymax=1.4
的同时得到: