Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to make custom style for \listplot and friends? By default they support only plotstyle=curve, line, bezier, and I need to use bspline from pst-bspline package.

\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}
share|improve this question

1 Answer 1

Quite oldish, but here you go:

I implemented a new cspline plot style, which interpolates a given set of data points with cubic splines. The splines are calculates such, that the control points can be drawn with Postscript's curveto operator. The algorithm was implemented following http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit

\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}

enter image description here

I'll test and tweak this code a bit and then send it to Herbert for inclusion into pst-plot (or pstricks-add).

share|improve this answer
    
it is already in the current pstricks and pst-plot –  Herbert Mar 14 at 10:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.