Hi Jovan,

I hope I’m not missing something, but this seems to meet your needs?

use strict;
use warnings;
use PDL;
use PDL::Graphics::Gnuplot qw(plot3d);
my ($x, $y, $ohms) = rcols \*DATA, 0..2;
plot3d($x, $y, $ohms);
print "Press return to quit:";<>;
__DATA__
174466.6 148753.6 3.205395
174438.8 149112.8 2.041845
174410.4 149471.7 2.192256
174382.7 149830.3 2.345829
174354.9 150189.4 2.256398
174326.8 150548.4 2.134265
174299.2 150907.4 2.360153
174271.1 151265.9 2.303999
174243.3 151624.9 2.437044
174215.4 151983.8 2.454804
174187.4 152343 2.407471
174159.6 152701.7 2.339043
174131.5 153060.5 2.363042
174103.9 153419.6 2.399614
174075.8 153778.4 2.352736
174047.8 154137.4 2.267724
174020.1 154496.3 2.219654
173992.3 154855.3 2.157816

No further mangling of data required, just feed it in as 1D ndarrays for x, y, 
and z. Craig’s amazing PDL::Graphics::Gnuplot knows exactly what to do.

Best regards,
Ed

________________________________
From: Jörg Sommrey <[email protected]>
Sent: Friday, April 19, 2024 1:20:17 PM
To: Jovan Trujillo <[email protected]>
Cc: perldl <[email protected]>
Subject: Re: [Pdl-general] Plotting flat xyz data as an image.

Hi Jovan,

in addition to Luis' solution, here is another approach for your
mapping problem.

You need to figure out the image's dimensions yourself, then you may
align the x- and y-coordinates to a grid and put the z-data into the
corresponding cells.

my $img = zeroes dim1, dim2;
my $xy = cat $x, $y;
my ($min, $max) = $xy->minmaxover;
my $norm = ($xy->xchg(0, 1) - $min) / ($max - $min);
$img->indexND((($img->shape - 1) * $norm)->rint) .= $z;
image $img;

Regards,
-jo

On Thu 18 Apr 2024 11:19:29 PM CEST, Jovan Trujillo
<[email protected]> wrote:

> If you look at my example code it shows that the Excel data basically has
> the coordinates flattened to a list:
>
> my $x = flat(xvals(10,10)); # This is basically how x-coordinates are
> output from my machine.
> my $y = flat(yvals(10,10)); # Same format as x-coordinates
> my $z = sequence(100)*rand(1); # Some dummy data for this example.
>
> This is just an example to show the structure of the data coming in. A
> sample of the data in the Excel file looks like this:
>
> X (um) Y (um) R (Ohms/sq)
> 174466.6 148753.6 3.205395
> 174438.8 149112.8 2.041845
> 174410.4 149471.7 2.192256
> 174382.7 149830.3 2.345829
> 174354.9 150189.4 2.256398
> 174326.8 150548.4 2.134265
> 174299.2 150907.4 2.360153
> 174271.1 151265.9 2.303999
> 174243.3 151624.9 2.437044
> 174215.4 151983.8 2.454804
> 174187.4 152343 2.407471
> 174159.6 152701.7 2.339043
> 174131.5 153060.5 2.363042
> 174103.9 153419.6 2.399614
> 174075.8 153778.4 2.352736
> 174047.8 154137.4 2.267724
> 174020.1 154496.3 2.219654
> 173992.3 154855.3 2.157816
>
>
>
> I have parsed that data into $x, $y, and $z but $z needs to be mapped into
> an N x N matrix for image plotting using the coordinates given in $x and
> $y. The machine walks along Y and then steps to the next X coordinate when
> it reaches the end of Y. All points in X and Y are expected to be unique. I
> need to create the matrix using zeroes(N,N) since I know how many points I
> took in X and Y, and then create a sequence that interpolates $x and $y
> into matrix index values. Then use matching to know where in the matrix the
> $z values belong. If there is something built into PDL to do that let me
> know.
>
> I hope this helps clarify the problem.
>
> Thanks,
> Jovan
>
> On Thu, Apr 18, 2024 at 1:35 PM David Mertens <[email protected]>
> wrote:
>
>> Hello Jovan,
>>
>> Did you try this?
>> my $z = sequence(10,10)*rand(1);
>>
>> Seems to me you just need a z-value pdl that has the same dimensions as
>> the x and y coordinates.
>>
>> David
>>
>> On Thu, Apr 18, 2024, 1:11 PM Jovan Trujillo <[email protected]>
>> wrote:
>>
>>> Hi Greg,
>>> Yes, I've been looking into a heat map or flattened 3d scatterplot. In
>>> Mathematica, I can easily import the Excel spreadsheet and plot using
>>> ListDensityPlot to give me a nice high-resolution image of the data.
>>>
>>> But my question is simply a mapping problem. If I have two piddles with
>>> $x and $y coordinates and a third representing the $data, how do I create a
>>> $matrix that maps the $data based on the coordinates from $x and $y? If I
>>> had $matrix I can simply plot image($matrix) with PDL::Graphics::Gnuplot.
>>>
>>> Thank you,
>>> Jovan
>>>
>>> On Thu, Apr 18, 2024 at 1:16 AM Grégory Vanuxem <[email protected]>
>>> wrote:
>>>
>>>> Hello,
>>>>
>>>> I haven’t carefully looked at your problem with GNUPlot but I wonder if
>>>> what you are trying to achieve could not be done with surface routines,
>>>> that’s with 3d ones ? Or maybe something like heatmap like this question:
>>>>
>>>>
>>>> https://stackoverflow.com/questions/76577557/trying-to-create-heat-map-using-ggplot-similar-to-density-contour-plot-but-wh
>>>>
>>>> Just to give some hints on possible routines.
>>>>
>>>> - Greg
>>>>
>>>> Le jeu. 18 avr. 2024 à 01:53, Jovan Trujillo <[email protected]>
>>>> a écrit :
>>>>
>>>>> Hi all,
>>>>>
>>>>> I've been wracking my brain all morning trying to figure this out, but
>>>>> how could I convert a set of 3 1D piddles containing xyz data
>>>>> into a matrix
>>>>> for plotting as an image using PDL::Graphics::Gnuplot? Say for example:
>>>>>
>>>>> use PDL;
>>>>> use PDL::Graphics::Gnuplot qw/image gplot/;
>>>>>
>>>>> my $x = flat(xvals(10,10)); # This is basically how x-coordinates are
>>>>> output from my machine.
>>>>> my $y = flat(yvals(10,10)); # Same format as x-coordinates
>>>>> my $z = sequence(100)*rand(1); # Some dummy data for this example.
>>>>>
>>>>> my $image; # How do I map $x,$y,$z into this 10x10 $image piddle?
>>>>> image($image);
>>>>>
>>>>> That's my basic problem. How do I map $x,$y,$z data into an $image
>>>>> matrix?
>>>>>
>>>>> Thank you,
>>>>> Jovan
>>>>> _______________________________________________
>>>>> pdl-general mailing list
>>>>> [email protected]
>>>>> https://lists.sourceforge.net/lists/listinfo/pdl-general
>>>>>
>>>> _______________________________________________
>>> pdl-general mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/pdl-general
>>>
>>




_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to