![pgfplots:如何将装饰路径剪辑到视口限制并使“文本对齐”使用其新的限制?](https://linux22.com/image/471545/pgfplots%EF%BC%9A%E5%A6%82%E4%BD%95%E5%B0%86%E8%A3%85%E9%A5%B0%E8%B7%AF%E5%BE%84%E5%89%AA%E8%BE%91%E5%88%B0%E8%A7%86%E5%8F%A3%E9%99%90%E5%88%B6%E5%B9%B6%E4%BD%BF%E2%80%9C%E6%96%87%E6%9C%AC%E5%AF%B9%E9%BD%90%E2%80%9D%E4%BD%BF%E7%94%A8%E5%85%B6%E6%96%B0%E7%9A%84%E9%99%90%E5%88%B6%EF%BC%9F.png)
无需明确设置 x 域键domain
,如何将装饰路径剪裁到视口 y 限制,ymin = 0.5, ymax = 2.5
以便\pgfdecoratedpathlength
在屏幕上进行测量?
换句话说,text align = {left indent = {0.75\dimexpr\pgfdecoratedpathlength\relax}}
应该将文字排版text
在靠近右下角的位置。
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{decorations.text, math, intersections}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymin = 0.5, ymax = 2.5,
]
%
\addplot [
variable = \Fbr,
postaction = {
decoration = {
text along path,
text = {text},
text align = {left indent = {0.75\dimexpr\pgfdecoratedpathlength\relax}},
}, decorate,
},
] {1 - \Fbr};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
如果您使用clip=false
、 和standalone
,您可以看到文本的位置:
使用默认域 (-5:5) 构建线,然后进行剪辑。
也许你想要以下内容(我限制了情节的范围):
\documentclass{standalone}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\usetikzlibrary{decorations.text, math, intersections}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymin = 0.5, ymax = 2.5,
domain = -1.5:0.5,
% clip=false,
]
%
\addplot [
variable = \Fbr,
postaction = {
decoration = {
text along path,
text = {text},
text align = {left indent = {0.75\dimexpr\pgfdecoratedpathlength\relax}},
}, decorate,
},
] {1 - \Fbr};
\end{axis}
\end{tikzpicture}
\end{document}
或者,如果您只想指定垂直域,让其余部分单独存在,您应该绘制使用 y 作为变量:
\documentclass{standalone}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\usetikzlibrary{decorations.text, math, intersections}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain = 2.5:0.5,
]
%
\addplot [
variable = \Fbr,
postaction = {
decoration = {
text along path,
text = {text},
text align = {left indent = {0.75\dimexpr\pgfdecoratedpathlength\relax}},
}, decorate,
},
] ({1 - \Fbr}, \Fbr);
\end{axis}
\end{tikzpicture}
\end{document}
...但是你需要一个域;它是pgfplots
迭代查找功能点的地方。
PD:我想您的只是一个例子,您使用装饰是因为您在更复杂的情节中需要它们,否则:
\documentclass{standalone}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain = 2.5:0.5,
]
%
\addplot [variable=\Fbr] ({1 - \Fbr}, \Fbr) node[above, sloped, pos=0.75]{text};
\end{axis}
\end{tikzpicture}
\end{document}
给出几乎相同的输出: