我如何才能获取轴标签的坐标并将其锚定到该轴标签上?

我如何才能获取轴标签的坐标并将其锚定到该轴标签上?

我想绘制一个与轴标签相关的箭头,如“x —>”。箭头应为一条线,带有指向轴方向的自定义箭头。

提前感谢大家的支持。弗兰克

答案1

以下选项使用pin空标签选项:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[
  label arrow/.style={
    pin={[pin edge={->,thin,draw=black}]0:},
  },
]
\begin{axis}[
  width=100mm,
  height=80mm,
  xmin=0, xmax=.5,
  xlabel=$x$,
  x label style={label arrow},
  ymin = 0, ymax=.5,
  ylabel=$y$,
  y label style={label arrow},
]
\end{axis}
\end{tikzpicture}
\end{document}

结果

箭头线的长度可以通过以下方式配置pin distance

label arrow/.style={
  pin={[pin distance=7mm, pin edge={->,thin,draw=black}]0:},
},

答案2

例如:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
             xlabel=$x$,
             x label style={alias=thexlabel} % <-- makes thexlabel a name for the xlabel node
            ]
\end{axis}
\draw [-stealth] (thexlabel.east) -- +(1cm,0);
\end{tikzpicture}
\end{document}

在此处输入图片描述

使用scope用于缩放axis和箭头,这似乎不太有效。晚上太晚了,无法认真思考这个问题,但一个简单的解决方法可能是这样的:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\scalefactor}{1.5}
\begin{axis}[width=\scalefactor*100mm,height=\scalefactor*80mm, xmin = 0,xmax = 0.5, xlabel=$x$, x label style={alias=xlbl}, ymin = 0,ymax = 0.5, ylabel=$y$, y label style={rotate=-90,alias=ylbl}]
\end{axis} 
\begin{scope}[scale=\scalefactor]
\draw [->] (xlbl.east) -- +(7mm,0);
\draw [->] (ylbl.north) -- +(0,7mm);
\end{scope}
\end{tikzpicture} 
\end{document}

答案3

非常感谢大家。我的问题解决了。这是最后一个示例,其中的箭头和图表框架设置(箭头、线宽、刻度长度)符合 DIN 规范。此致 Frank

\documentclass[fontsize=11pt,a4paper]{scrartcl}

\usepackage[usenames,dvipsnames]{xcolor}
%-----TikZ--------------------------------
\usepackage{tikz}
\usetikzlibrary{arrows, positioning, calc}
\usepackage{pgf}
%-----pgfplots----------------------------
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%-----Color Definition -------------------
\definecolor{DarkRed}{rgb}{0.65,0.00,0.00}
%-----DIN Arrow Head----------------------
\pgfarrowsdeclare{DIN}{DIN}{
  \arrowsize=10\pgflinewidth
  \advance\arrowsize by -10\pgflinewidth
  \pgfarrowsleftextend{-10\pgflinewidth}
  \pgfarrowsrightextend{.5\pgflinewidth}
}{\arrowsize=10\pgflinewidth
\advance\arrowsize by .5\pgflinewidth
\pgfsetdash{}{0pt} %  do not dash
\pgfsetroundjoin   %  fix join
\pgfsetroundcap    %  fix cap
\pgfpathmoveto{\pgfpoint{0}{0}}
\pgfpathlineto{\pgfpoint{-1\arrowsize}{0.13165\arrowsize}}
\pgfpathlineto{\pgfpoint{-1\arrowsize}{-0.13165\arrowsize}}
\pgfpathlineto{\pgfpoint{0}{0}}
\pgfpathclose
\pgfusepathqfillstroke
 %\pgfusepathqstroke
\pgfpathmoveto{\pgfpointorigin}
\pgfusepathqstroke}
%=================================================*
\begin{document}
%-------------------------------------------------
begin{center}
\begin{tikzpicture}[
xlabel arrow/.style={
    pin={[pin distance=7mm, pin edge={-DIN,line width=0.25mm,draw=black}]0:},},
ylabel arrow/.style={
    pin={[pin distance=7mm, pin edge={-DIN,line width=0.25mm,draw=black}]90:}}]
\pgfplotsset{every axis/.append style={line width=0.35mm,
tick style={minor tick num=1,line width=0.18mm,minor tick length = 1.25mm, major tick length = 2.5mm, color=Black}}}
\begin{scope}[scale=1.00]
\begin{axis}[width=100mm,height=80mm,
    clip mode=individual,
    xmin = -1.5,xmax = 1.5,
        xlabel=$x$,
        xlabel style = {alias=xlbl, xlabel arrow},
    xticklabel style={/pgf/number format/.cd,fixed,fixed zerofill,precision=1,use comma,/tikz/.cd},
    ymin = 0,ymax = 1,
             ylabel=$p$,
             y label style={rotate=-90,alias=ylbl, ylabel arrow},
    yticklabel style={/pgf/number format/.cd,fixed,fixed zerofill,precision=1,use comma,/tikz/.cd},
             ]
\addplot[DarkRed,line width = 0.7mm,samples=201,smooth,line cap=round,domain=-1.5:1.5]{((1/(0.425*sqrt(2*pi)))*exp(-0.5*((x-0.2)/0.425)^2)};
\end{axis}
\end{scope}
\end{tikzpicture}
\end{center}
%-------------------------------------------------
\end{document}
%=================================================*

相关内容