[pstricks] Custom plotting of data (custom coloring of select points in a data set)

Herbert Voss Herbert.Voss at FU-Berlin.DE
Thu Dec 3 16:36:46 CET 2009


Am 03.12.2009 14:43, schrieb Jorge Nto:

> I have a set of 2D data (DAT-file) which I would like to plot and color
> according to their Y value. Until now I can only plot all points with
> listplot having all the same color (ex: \listplot[plotstyle= dots
> linecolor=red]). But for my purpose I would have to use a \forloop or
> \multido command to read every single point in the data set and plot it by
> chosing a color according to its Y-coordinate value, for example using the
> \hsv command. The question is: How can I access the elements of data as
> single points? Is there a syntax like: \data[20][1] or \data(20) (or for
> those who know MATLAB:  data(20,:) -colon syntax to access the coordinates).
> 
> I  did not find any similar on Internet. Maybe I must re-define the listplot
> command but I could do this only if I had the source code of the original
> command or something like that.

\documentclass{minimal}
\usepackage{pstricks-add}
\begin{filecontents*}{demo.data}
    0.1414    0.0052
    0.2828    0.0217
    0.4243    0.0480
    0.5657    0.0890
    0.7071    0.1375
    0.8485    0.1906
    0.9899    0.2663
    1.1314    0.3580
    1.2728    0.4644
    1.4142    0.5801
    1.5556    0.7033
    1.6971    0.8899
    1.8385    1.1143
    1.9799    1.2593
    2.1213    1.5692
    2.2627    3.2331
    2.4042    4.4097
    2.5456    5.8186
    2.6870    7.4441
    2.8284    8.2287
\end{filecontents*}

\makeatletter
\def\psdots at iii{%
  \psk at dotsize
  \@nameuse{psds@\psk at dotstyle}
  newpath
  n { dup   % y y
      \pst at number\psyunit div % to orig y value
      180 exch dup sethsbcolor % 180 Y Y hsb color
      transform floor .5 add exch floor
      .5 add exch itransform Dot stroke} repeat }
\makeatother
\begin{document}

\readdata{\data}{demo.data}
\psset{xunit=3}
\begin{pspicture}(0,0)(3,10)
  \psaxes{->}(0,0)(3,10)
  \listplot[plotstyle=dots]{\data}
\end{pspicture}

\end{document}

the only important lines are
      \pst at number\psyunit div % to orig y value
      180 exch dup sethsbcolor % 180 Y Y hsb color

Herbert


More information about the PSTricks mailing list