no takers at the end of week. fortunately, I kept banging my head against the wall, and I was able to figure this out.
use PDL; use PDL::GSL::INTERP; use PDL::Graphics::PGPLOT; #here is my sparse X,Y data to be plotted (note each step of X = one full integer value) my $x=pdl(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23); my $y=pdl(92.45, 82.50, 78.69, 74.86, 70.52, 66.54, 62.39, 58.40, 54.21, 49.96, 45.75, 41.89, 37.76, 33.87, 29.48, 25.62, 21.92, 17.92, 13.53, 9.37, 5.77, 3.96, 1.92, 0.59); #this creates a GSL cubic spline interpolation function object from the sparse X,Y data my $spline = PDL::GSL::INTERP->init('cspline',$x,$y); #now I loop through the range of X values, in smaller increments 0.1 (to effectively increase the apparent density of the points by a factor of ten, and thus making the drawn line segments be one tenth their original size) for (my $x_smaller_increments=0; $x_smaller_increments<=23; $x_smaller_increments+=0.1) { $x_smaller_increments = sprintf("%0.1f", $x_smaller_increments); my $y_smaller_increments = sprintf("%0.3f", $spline->eval($x_smaller_increments)); #save the new X smaller step values, and matching Y cubic spline evaluated terms push(@cubic_spline_x, $x_smaller_increments); push(@cubic_spline_y, $y_smaller_increments); #print to screen for verification all looks good print "x = $x_smaller_increments y = $y_smaller_increments\n"; } #PGPLOT code, create a new PGPLOT object, set output device to PNG file (eg; the output of this program will be a new PNG file in this cwd that contains the drawn graph) $window = new_window("/PNG"); my $x_cspline_pdl = pdl(@cubic_spline_x); #convert array of regular perl scalers to PDL pdl datatype my $y_cspline_pdl = pdl(@cubic_spline_y); #convert array of regular perl scalers to PDL pdl datatype #this single line tells PGPLOT to draw a line rendering, using PGPLOT defaults for the PDL pdl x,y datatypes line $x_cspline_pdl, $y_cspline_pdl; close_window($window); #note, a new file called pgplot.png was in fact created in my cwd which did display the desired graph. very cool! _____ From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Greg Aiken Sent: Thursday, June 30, 2011 12:28 PM To: perl-win32-users@listserv.ActiveState.com Subject: most powerful and amazing PDL + PGPLOT + GSL + OpenGL I need to create a scientific plot in 2D of simple X,Y point data. I found what I feel is one of the most amazing Perl modules for such task. PDL (Perl Data Language) has a simple windows install that requires installing perhaps a total of 5 modules. I had no trouble installing from an internet based ppm install. This solution is so cool that I wanted to share this with others, who have not had the opportunity to hear about this before. It is basically like commercial Matlab, it offers an interactive environment and allows one to manipulate large sets of numbers and create powerful graphs using both PGPLOT and it even has OpenGL bindings and can create a 3D renderings that the user can actually interactively rotate about in an OpenGL window! If this weren't enough, it includes GSL, GNU scientific library, to allow for things such as cubic spline interpolation, differentiation and integration. Anyways, this is all pretty amazing, and I wanted to share this with anyone who might one day have a need for such a thing. Does anyone in this list currently use PDL and PGPLOT? If so, I was wondering if I could ask you a question. I have basically figured out how to draw my own 2D graph. Basically, PGPLOT draws line segments to connect sample points. If one has a set of sample points, the closer they are to each other, the less 'line segmenty' the line looks - and the result is more like a smooth curve. I was wondering if anyone had an example that starts with a sparse X,Y sample set, and uses the GSL 'cspline' routine to 'make more closer spaced points', for the purpose of drawing a 'smoother' graph that takes on a cubic spline appearance. If anyone can help, that would be appreciated.
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs