坐标轴刻度线与箭头距离太近,增大xmax或ymax时坐标轴并没有延长相应的单位长度

发布于 2025-07-13 14:41:06

1c47233eb09b1c8e1db65804653ed287.png

...
    xmin = -0.05, xmax = 1.1,
    ymin = -0.05, ymax = 1.4,
...

image.png

...
    xmin = -0.05, xmax = 1.1,
    ymin = -0.05, ymax = 1.3,
...

test.tex

完整代码

\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}

查看更多

关注者
0
被浏览
68
1 个回答
Sagittarius Rover
Sagittarius Rover 5小时前
我要成为Typst糕手/(ㄒoㄒ)/~~

0.请有简化你问题的意识,不要让别人看一大堆与你问题无关的代码。

明明下面的十几行就可以完全反映你的问题,为什么要上传七八十行的代码(?) 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}

1.比较简陋的做法

坐标轴刻度线与箭头距离太近,增大xmaxymax时坐标轴并没有延长相应的单位长度

指定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}

image.png

2.使用tikzarrow提供的shorten >=功能调整「箭头末端」的长度:

文档

image.png

\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的同时得到:

image.png

请务必简化你的代码,不要一发发一大堆,其中大部分内容与你的问题无关。还有,若代码较短,请用「markdown代码块」而不是「上传附件」给出。

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览