You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PGFPlots的patch磁滞回线图中添加流向箭头?

问题描述

无法在patch绘制的磁滞回线图中添加箭头指示回线流向,post action装饰无法生效。已尝试两种方法均失败:

  • 在背景层手动添加箭头,无法仅绘制箭头头部,定位操作笨拙且效果一般
  • 使用spath记忆路径,但路径为空

求可行的实现技巧。

当前LaTeX代码
\documentclass[tikz,margin=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usepackage{helvet}
\usepackage{amsmath}
\usepackage[czech]{babel}
\usepackage{pgfplots, pgfplotstable}

\pgfplotsset{compat=1.18}
\usepgfplotslibrary{patchplots}
\usepgfplotslibrary{fillbetween}

\usetikzlibrary{babel, calc}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{arrows.meta, spath3}

\renewcommand{\familydefault}{\sfdefault}

\iflanguage{czech}{}

\begin{document}

\begin{tikzpicture} [
    guide/.style={thin, dashed, themeGrey},
    flow arrow/.style={-{Latex[scale=0.75]}, thick, themeBlue!60, shorten >=1pt, } %shorten <=3pt
]

\definecolor{themeBlue}{RGB}{1, 103, 143}
\definecolor{themeOrange}{RGB}{221, 109, 16}
\definecolor{themeTeal}{RGB}{18, 54, 69}
\definecolor{themeGrey}{RGB}{120, 121, 124}

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground} 

\begin{axis}[
    width=10cm, height=10cm, samples = 100,
    ymin=-5, ymax=5,
    xmin=-5, xmax=5,
    enlargelimits=false, clip=false, 
    axis on top, axis lines*=middle, axis line style = {semithick, -latex},
    yticklabel style={text width=1.75em, align=left},
%
    xlabel={$\text{H}$},
    xtick={1.5, 4}, 
    xticklabels={$\text{+H}_{\text{c}}$, $\text{+H}_{\text{m}}$},
    extra x ticks={-4, -1.5},
    extra x tick labels={$\text{-H}_{\text{m}}$, $\text{-H}_{\text{c}}$},
    extra x tick style={
        xticklabel style={yshift=0.5ex, anchor=south}
    },
%
    ylabel={$\text{B}$},
    ytick={2.5, 4}, 
    yticklabels={$\text{+B}_{\text{r}}$, $\text{+B}_{\text{m}}$},
    extra y ticks={-4, -2.5},
    extra y tick labels={$\text{-B}_{\text{m}}$, $\text{-B}_{\text{r}}$},
    extra y tick style={
        yticklabel style={xshift=5ex, text width=1.5em, align=left}
    },
%
    every axis plot/.style={thick},
    axis x line=middle,    % put the x axis in the middle
    axis y line=middle,
    every axis x label/.style={at={(ticklabel* cs:1.01)}, anchor=west},
    every axis y label/.style={at={(ticklabel* cs:1.01)}, anchor=south,},
]

\addplot [mesh, patch type=quadratic spline, themeBlue, dashed] coordinates {
   (0,0) (4,4) (1.5,1)% first segment
};

\addplot [patch, patch type=quadratic spline, themeBlue] coordinates {
   (-4,-4) (-1.5,0) (-2.5,-2.8) % first segment
   (-1.5,0) (4,4) (0,2.5) % second segment
};

\addplot [mark=*, only marks, ultra thin, themeBlue] plot coordinates {
    (4, 4) (-4, -4)
    (1.5, 0) (-1.5, 0)
    (0, -2.5) (0, 2.5)
};

\addplot [patch, patch type=quadratic spline, themeBlue] coordinates {
     (-4,-4) (1.5,0) (0,-2.5) % left, right, middle-> first segment
     (1.5,0) (4,4) (2.5,2.8) % left, right, middle-> second segment
};

% Adding arrows to indicate flow direction
\begin{pgfonlayer}{background}
\end{pgfonlayer}

\addplot [guide] plot coordinates { (0, 4) (4, 4) (4, 0) };

\end{axis}
\end{tikzpicture}
\end{document}
当前效果图

当前磁滞回线效果图

内容的提问来源于stack exchange,提问作者jr.root.cs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 03:15:58