[pstricks] Working with multiple data columns
Herbert Voss
Herbert.Voss at FU-Berlin.DE
Sun Jan 24 10:43:56 CET 2010
Am 24.01.2010 04:08, schrieb Brandon Kuczenski:
> On Sat, 23 Jan 2010, Herbert Voss wrote:
>
>> Am 23.01.2010 21:00, schrieb Brandon Kuczenski:
>>
>> http://tug.org/PSTricks/main.cgi?file=pst-plot/DataExamples#polarplot
>>
>> the last example shows how two values can be added
>> for a third plot.
>>
>
> \makeatletter
> \pst at def{ScalePoints}<%
> /y ED /x ED
> counttomark dup dup cvi eq not { exch pop } if
> /m exch def /n m 2 div cvi def
> n { /RAD exch def % save y as radius
> dup % xVal xVal
> cos exch sin RAD mul y mul m 1 roll
> RAD mul x mul m 1 roll
> /m m 2 sub def } repeat>
> \makeatother
>
> What does 'ED' mean?
exch def
> Thank you, this looks promising.. you are basically using ScalePoints to
> 'pre-process' the data queue-wise, so that x, y are turned into
> y*cos(x), y*sin(x). This is basically what I want to do.
here is an example which plots the data (y3-y1)*cos(x) (y3-y1)*sin(x)
and saves the values in an external file data.dat, reads this file
at plots it with plotstyle dot. There is only a problem when running
the example from within a graphical user interface. Ghostscript
does't allow overwriting or creating files when it is not called
directly. However, run latex and dvips and then gs <file>.ps,
then everything should be fine.
Herbert
\documentclass{minimal}
\usepackage{pstricks-add}
\def\data{% x y1 y2 y3
1 45 67 89
2 46 66 87
3 47 62 88
4 44 61 80
5 42 52 72
}
\begin{document}
\begin{pspicture}(0,0)(10,10)
\begin{psgraph}[ticks=none](0,0)(-45,-5)(25,1){10cm}{10cm}
% say we want to plot y3 - y1
\listplot[linecolor=red]{
/Pstdata (data.dat) (w) file def
\data
counttomark 4 div cvi /m exch def % m = num rows
m { % x y1 y2 y3
exch pop % ditch y2
exch sub % y3 - y1
exch dup RadtoDeg cos % y x cos(x)
3 -1 roll dup % x cos(x) y y
3 1 roll mul % y x cos(x)*y
3 1 roll RadtoDeg sin mul % cos(x)*y y*sin(x)
2 copy
exch
20 string cvs Pstdata exch writestring
Pstdata (\space) writestring
20 string cvs Pstdata exch writestring
Pstdata (\string\n) writestring
counttomark cvi 2 roll % shift to front
} repeat
}
\readdata{\Data}{data.dat}
\listplot[showpoints=true,linecolor=blue,plotstyle=dots]{\Data}
\end{psgraph}
\end{pspicture}
\end{document}
More information about the PSTricks
mailing list