3

I'm trying to display a graph generated by PDL (using PLplot) inside a Gtk3 app. When I try the following code, I see two problems:

  1. $pdlImg isn't a GdkPixbuf so new_from_pixbuf() doesn't work.
  2. $pdlImg appears to be empty as because the error message prints out the 10x10x3 array as a string and they're all zeroes.

Code:

#!/usr/bin/perl -w

use strict;
use PDL;
use PDL::Graphics::PLplot;
use Gtk3 -init;

my $pdlImg = zeroes(byte, 10, 10, 3);
my $pl = PDL::Graphics::PLplot->new(DEV => 'mem', MEM => $pdlImg);
my $x = sequence(10);
my $y = $x**2;
$pl->xyplot($x, $y);
$pl->close;

my $win = Gtk3::Window->new;
my $img = Gtk3::Image->new_from_pixbuf($pdlImg);
$win->add($img);
$win->show_all;
Gtk3::main();
TheAmigo
  • 1,032
  • 1
  • 10
  • 29

1 Answers1

2

To answer your first question, you are having PLplot put the plot into a piddle that is 10 pixels wide and 10 pixels high. I'm not sure if you're just going to get one corner of the normal plot in that case, or if you're getting the whole plot sampled into those 10x10 pixels. But in either case it's no surprise that $pdlImg is entirely zeroes. Try passing in a piddle with larger size (perhaps 1000, 1000, 3), or perhaps even using MEM => $pdlImg=null when you create the PLplot plot object.

I can't help with your second question, I have no experience with Gtk3, sorry.

Derek
  • 63
  • 5
  • You'd think, but when I print sum($pdlImg) after $pl->close, it's zero. – TheAmigo Aug 22 '16 at 12:45
  • Clarification: @Derek, When I change the size to 500x500x3 and print sum($pdlImg) after $pl->close, it's zero. – TheAmigo Aug 22 '16 at 12:53
  • I'll have to take your word for it. I haven't used PLplot in a long time, don't have a working PDL::Graphics::PLplot at the moment, can't seem to get it installed, and don't have the time to mess with it. You might try asking on the PDL mailing list. – Derek Aug 22 '16 at 21:12