\listplot 或 \dataplot 的自定义样式

\listplot 或 \dataplot 的自定义样式

可以为\listplot和朋友制作自定义样式吗?默认情况下,它们仅支持、、,plotstyle=curve我需要使用包中的。linebezierbsplinepst-bspline

\documentclass[a4paper,14pt]{scrartcl}
\usepackage{pst-plot,pst-func,pstricks-add,pst-eps}
\pagestyle{empty}
\usepackage{filecontents}
\begin{filecontents}{data1.dat}
256.4912 0.0674
259.7543 0.0904
264.7287 0.0502
270.1739 0.0339
276.2696 0.0531
281.4192 0.0402
284.4351 -0.1221
286.7098 -0.2659
289.9052 -0.8337
292.8813 -1.391
295.1299 -1.3968
297.858 -1.8959
299.5145 -0.608
302.1028 -0.323
\end{filecontents}
\begin{document}
\readdata{\foo}{data1.dat}
\begin{psgraph}
[axesstyle=frame,ticksize=6pt,subticks=5,Ox=250,Dx=10,Oy=-2,](250,-2)(310,0.2){0.8\linewidth}{0.6\linewidth}
\listplot[plotstyle=dots,linecolor=blue,linewidth=0.5pt,showpoints=true]{\foo}
\listplot[plotstyle=bezier,linecolor=red,linewidth=0.5pt,showpoints=false]{\foo}
 \end{psgraph}
\end{document}

答案1

相当古老,但你可以看看:

我实现了一种新的cspline绘图样式,它使用三次样条函数插入给定的一组数据点。样条函数的计算方式使得可以使用 Postscript 的运算符绘制控制点curveto。该算法的实现方式如下http://www.codeproject.com/Articles/31859/通过一组 2D 点绘制平滑曲线

\documentclass{article}
\usepackage{pst-plot}
\thispagestyle{empty}
\usepackage{filecontents}
\begin{filecontents}{data1.dat}
256.4912 0.0674
259.7543 0.0904
264.7287 0.0502
270.1739 0.0339
276.2696 0.0531
281.4192 0.0402
284.4351 -0.1221
286.7098 -0.2659
289.9052 -0.8337
292.8813 -1.391
295.1299 -1.3968
297.858 -1.8959
299.5145 -0.608
302.1028 -0.323
\end{filecontents}
%
% Define the 'cspline' plot style to use cubic splines
\makeatletter
\def\beginplot@cspline{\begin@OpenObj}
\def\endplot@cspline{\ps@cspline}
\pst@def{BezierSpline}<
  10 dict begin
    /getX { Points exch 2 mul get } def
    /getY { Points exch 2 mul 1 add get } def
    /n Points length 1 sub 2 idiv def
    /GetFirstControlPoints {
    /x n array def
    /tmp n array def
    /b 2 def
    x 0 rhs 0 get b div put
    1 1 n 1 sub {
        /i exch def
        tmp i 1 b div dup 4 1 roll put
        i n 1 sub lt { 4 }{ 3.5 } ifelse exch sub /b exch def
        x i rhs i get x i 1 sub get sub b div put
    } for
    1 1 n 1 sub {
        n exch sub
        dup dup x exch 1 sub 2 copy 6 2 roll
        get 3 1 roll tmp exch get
        exch x exch get mul sub
        put    
    } for
    x
    } bind def
    %
    n 1 eq {
    0 getX 2 mul 1 getX add 3 div
    0 getY 2 mul 1 getY add 3 div
    exch dup 3 1 roll 2 mul 0 getX sub
    exch dup 3 1 roll 2 mul 0 getY sub
    [ 0 getX 0 getY 7 3 roll 1 getX 1 getY ] /outPoints exch def
    } {
    /outPoints 6 n mul 2 add array def
    0 1 n {
        dup dup 6 mul dup 1 add
        outPoints exch 5 -1 roll getY put
        outPoints exch 3 -1 roll getX put
    } for
    /rhs n array def
    1 1 n 2 sub {
        rhs exch dup dup getX 4 mul exch 1 add getX 2 mul add put
    } for
    rhs 0 0 getX 1 getX 2 mul add put
    rhs n 1 sub dup getX 8 mul n getX add 2 div put
    GetFirstControlPoints
    1 1 n 2 sub {
        rhs exch dup dup getY 4 mul exch 1 add getY 2 mul add put
    } for
    rhs 0 0 getY 1 getY 2 mul add put
    rhs n 1 sub dup getY 8 mul n getY add 2 div put
    GetFirstControlPoints
    0 1 n 1 sub {
        /i exch def
        2 copy
        i get outPoints 6 i mul 3 add 3 -1 roll put
        i get outPoints 6 i mul 2 add 3 -1 roll put
        2 copy
        i n 1 sub lt {
        i 1 add get i 1 add getY 2 mul exch sub outPoints 6 i mul 5 add 3 -1 roll put
        i 1 add get i 1 add getX 2 mul exch sub outPoints 6 i mul 4 add 3 -1 roll put
        }{
        n 1 sub get n getY add 2 div outPoints 6 n 1 sub mul 5 add 3 -1 roll put
        n 1 sub get n getX add 2 div outPoints 6 n 1 sub mul 4 add 3 -1 roll put
        } ifelse
    } for
    pop pop
    } ifelse
    outPoints
    end>
\def\ps@cspline{%
  \addto@pscode{
    \tx@setlinejoin
    ] dup length /n ED /Points ED
    \tx@BezierSpline
    [ exch aload pop
    counttomark -2 roll moveto
    { counttomark 0 eq { pop exit } if
      counttomark -6 roll curveto
    } loop
    \ifshowpoints Points aload pop \fi
  }%
  \end@OpenObj%
}
\makeatother
\begin{document}
\readdata{\foo}{data1.dat}
\begin{psgraph}
[axesstyle=frame,ticksize=6pt,subticks=5,Ox=250,Dx=10,Oy=-2,](250,-2)(310,0.2){0.8\linewidth}{0.6\linewidth}
\listplot[plotstyle=dots,linecolor=blue,showpoints]{\foo}
\listplot[plotstyle=cspline,linecolor=red,linewidth=0.5pt]{\foo}
 \end{psgraph}
\end{document}

在此处输入图片描述

我将对这段代码进行一些测试和调整,然后将其发送给 Herbert,以纳入 pst-plot(或 pstricks-add)。

相关内容