[pstricks] [Fwd: Re: OT: Converter matrix to picture]
Herbert Voss
hvoss at tug.org
Fri Feb 3 15:20:31 CET 2006
Paul Smith wrote:
> On 2/3/06, Herbert Voss <hvoss-WUdSmCIlby8 at public.gmane.org> wrote:
>
>>>>tell me the structure of your data file?
>>>>Are the values also saved as a matrix?
>>>
>>>Thanks to all. An example of a data file is attached. It is a text
>>>file with a matrix. Each column corresponds to x-coordinate, whereas
>>>each row corresponds to y-coordinate. Both x and y have the same
>>>range: [0,1]. From column to column, x increases 0.1. From row to row,
>>>y increases 0.1. First column corresponds to x=0 and first row to y=0.
>>>
>>>------------------------------------------------------------------------
>>>
>>>0 1 1 0 0 0 0 1 1 1
>>>0 1 1 0 1 1 1 0 1 0
>>
>>understood. Here an example if you could have your textfile
>>as
>>
>>/matrix [
>>0 1 1 0 0 0 0 1 1 1
>>0 1 1 0 1 1 1 0 1 0
>>....
>>] def
>
>
> Great, Herbert! That is it. Maybe, a "spy-like" command could be added
> to the list of commands of PSTricks. Well, that is just a
> suggestion...
let's see ...
However, I was a bit too clever ...
the textfile should be with a first and last line of
/dotmatrix [
0 1 1 0 0 0 0 1 1 1
...
...
] def
I forgot that PSTricks also defines a /matrix array for internal
purposes. It collides with the one from this text matrix. Name it
/dotmatrix [ ... ] def instead and everything will be ok. See
example, which also shows the possibility of printing the dots
as squares without whitespace.
Herbert
\documentclass[a4paper]{article}
\usepackage{pst-plot}
\makeatletter
\def\specialPlot#1{%
\pst at killglue
\begin at SpecialObj%
\addto at pscode{
(#1) run % load the data file
\psk at dotsize % scale dot
\@nameuse{psds@\psk at dotstyle} % dotstyle
/n 0 def % index for element
0 0.1 1 { % the y loop
/y exch def % save y
0 0.1 1 { % the x loop
/x exch def % save x
dotmatrix n get % get value from matrix
dup 0 gt { % test if > 0
x \pst at number\psxunit mul y \pst at number\psyunit mul Dot%
} { pop } ifelse
/n n 1 add def
} for
} for
}%
\end at SpecialObj%
}
\makeatother
\begin{document}
\psset{unit=10}
\begin{pspicture}(-0.1,-0.1)(1.1,1.1)
\psaxes[Dx=0.1,Dy=0.1]{->}(1,1)
\psset{dotscale=3,dotstyle=square*,linecolor=magenta}
\specialPlot{matrix.txt} % must be of /dotmatrix [ ... ] def
\end{pspicture}
\begin{pspicture}(-0.1,-0.1)(1.1,1.1)
\psaxes[Dx=0.1,Dy=0.1]{->}(1,1)
\psset{dotsize=1.1cm,dotstyle=square*,linecolor=magenta}
\specialPlot{matrix.txt}
\end{pspicture}
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: matrix.txt
Url: http://tug.org/pipermail/pstricks/attachments/20060203/c08530c1/attachment.txt
More information about the PSTricks
mailing list