如何为 pst-plot 的分段函数中每个部分的任何自定义点添加自定义标签?

如何为 pst-plot 的分段函数中每个部分的任何自定义点添加自定义标签?

考虑以下例子这个答案

\documentclass[border=0bp]{standalone}

\usepackage{pst-plot}

\begin{document}

\psset{unit=1.5cm}
\begin{pspicture}[showgrid=false](-2.75,-0.75)(4,2)
    \psframe*[linecolor=yellow,opacity=0.5](-2.75,-0.75)(4,2)
    \psaxes[linecolor=lightgray]{->}(0,0)(-2.5,-0.5)(3.5,1.5)[$t$,0][$F(t)$,90]
    \psset{algebraic,linewidth=1.5pt,linecolor=red}
    \pscustom
    {
        \psplot{-2.5}{-1}{0}
        \psplot{-1}{0}{(x+1)/4}
        \psplot{0}{1}{1/2}
        \psplot{1}{2}{(x+7)/12}
        \psplot{2}{3.5}{1}
    }
\end{pspicture}

\end{document}

我想知道如何为这个分段函数的每个部分添加标签,使其看起来像 $f_1$ 到 $f_5$

如果我可以自由调整这些标签的坐标就太好了。一个愚蠢的方法是,我可以在图的某个坐标上添加一个“透明”点,然后为该点添加标签,但我甚至不知道该怎么做。

在此处输入图片描述

答案1

\documentclass[border=0bp]{standalone}

\usepackage{pst-plot}

\begin{document}
    
    \psset{unit=1.5cm}
    \begin{pspicture}[showgrid=false](-2.75,-0.75)(4,2)
        \psframe*[linecolor=yellow,opacity=0.5](-2.75,-0.75)(4,2)
        \psaxes[linecolor=lightgray]{->}(0,0)(-2.5,-0.5)(3.5,1.5)[$t$,0][$F(t)$,90]
        \psset{algebraic,linewidth=1.5pt,linecolor=red}
        \pscustom
        {
            \psplot{-2.5}{-1}{0}
            \psplot{-1}{0}{(x+1)/4}
            \psplot{0}{1}{1/2}
            \psplot{1}{2}{(x+7)/12}
            \psplot{2}{3.5}{1}
        }
        \pcline[linestyle=none](-2.5,0)(-1,0)\naput{$f_1$}
        \pcline[linestyle=none](-1,0)(0,0.25)\naput{$f_2$}
        \pcline[linestyle=none](0,0.5)(1,0.5)\naput{$f_3$}
        \pcline[linestyle=none](1,0.67)(2,0.75)\naput{$f_4$}
        \pcline[linestyle=none](2,1)(3.5,1)\naput{$f_5$}
    \end{pspicture}
    
\end{document}

在此处输入图片描述

对于这个简单的例子,定义九个点然后使用是有意义的\psline

\documentclass[border=0bp]{standalone}
\usepackage{pst-plot}
\begin{document}
    
    \psset{unit=1.5cm}
    \begin{pspicture}[showgrid=false](-2.75,-0.75)(4,2)
        \psframe*[linecolor=yellow,opacity=0.5](-2.75,-0.75)(4,2)
        \psaxes[linecolor=lightgray]{->}(0,0)(-2.5,-0.5)(3.5,1.5)[$t$,0][$F(t)$,90]
        \psset{algebraic,linewidth=1.5pt,linecolor=red}
        \pnodes{A}(-2.5,0)(-1,0)(-1,0)(0,0.25)(0,0.5)(1,0.5)(1,0.67)(2,0.75)(2,1)(3.5,1)
        \multido{\iA=0+2,\iB=1+2,\iC=2+2,\iD=1+1}{5}{%
          \pcline(A\iA)(A\iB)\naput{$f_\iD$}
            \ifnum\iA<7 \psline(A\iB)(A\iB|A\iC)\fi}
    \end{pspicture}
    
\end{document}

答案2

还请考虑不太奇特的 tikz 代码:

\documentclass{article}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[scale=1.5,line width=2pt]
        \filldraw[yellow] (-3,-.5) rectangle (4.3,2);
        \draw[gray!50,-latex] (-2.8,0)--(4,0) node[black,right] ()  {$t$};
        \draw[gray!50,-latex] (0,-0.15)--(0,1.5) node[black,above] ()  {$F(t)$};
        \foreach \i in {-2,-1,...,3}
            \draw[gray!50] (\i,.15)--(\i,-.15) node[black,below] () {$\i$ };
            \draw[gray!50] (.15,1)--(-.15,1) node[black,left] () {$1$ };
        \draw[red] (-2.5,0)--(-1,0)  node[pos=.5,above,black] () {$f_1$};
        \draw[red] (-1,0)--(0,.25)  node[pos=.5,above,black] () {$f_2$};
        \draw[red] (0,.25)--(0,.5);
        \draw[red] (0,.5)--(1,.5)  node[pos=.5,above,black] () {$f_3$};
        \draw[red] (1,.5)--(1,.67);
        \draw[red] (1,.67)--(2,.75)  node[pos=.5,above,black] () {$f_4$};
        \draw[red] (2,.75)--(2,1);
        \draw[red] (2,1)--(3.5,1)  node[pos=.5,above,black] () {$f_5$};
    \end{tikzpicture}
\end{document}

输出如下:

在此处输入图片描述

相关内容