Hey Tim,

I'm a little rushed at the moment, but yes, you're on the right track. I
have two relevant comments.

First, the way that you insert the figure isn't quite right. The name of
the widget is "ImageViewer" and the arguments aren't quite right. This will
probably do the trick (note I get rid of extraneous quotation when using
the "fat comma" operator; adjust for taste):

----%<----
use Prima qw(Application ImageViewer);

...

$wDisplay->insert(ImageViewer =>
  place => {
    relx=>0.5,  # relative x position runs from 0 - 1 (bare x is in pixels)
    rely=>0.25,  # relative y position runs from 0 - 1
    # probably also want to specify relwidth and/or relheight
    anchor'=>'sw'
  },
  image => $im,
);
---->%----

This will, with very high likelihood, display your image with scroll bars.
I hate this behavior of ImageViewer as it most certainly does not Do What I
Mean. For this reason I've created the StretchyImage widget, but I haven't
distributed it on CPAN quite yet. Partly for this reason, and partly for
other reasons, I have considered creating an Image Annotation.

Second, this image will *NOT* be included in "hard" output formats with the
version of PDL::Graphics::Prima that is currently on CPAN. The newest
version, on Github, will work. It depends on the development version of
Prima, which has not yet hit CPAN either. I can give some instructions on
how to address this if you like.

Hope that helps. Sorry for the rushed response.
David


On Sun, Aug 3, 2014 at 3:01 AM, Tim Haines <[email protected]>
wrote:

> Hello, all.
>
> I'm trying to insert an image into a plot using Prima much as you would do
> with figimage from matplotlib. My (feeble) attempt is included below. I
> took a cue from the examples on the cpan site, but I couldn't get it to
> work. I have a feeling the Prima::Image class isn't a Prima::Drawable
> object and needs to be encapsulated in something that is, but how to do
> that elludes me.
>
> use PDL;
> use Prima qw(Application);
> use PDL::Graphics::Prima;
>
> my $t_data = sequence(5) * 0.5;
> my $y_data = cos($t_data);
>
> my $wDisplay = Prima::MainWindow->create(
> text  => 'Graph Test',
> size  => [400, 400],
> );
>
> $wDisplay->insert('Plot',
> -function => ds::Func(\&PDL::cos, color => cl::Blue),
> -data => ds::Pair($t_data, $y_data, color => cl::Red),
>  pack => { fill => 'both', expand => 1},
> );
>
> my $im = Prima::Image->load('m82_small.jpg');
> die "$@" if $@;
>
> $im->set('width'=>100,'height'=>100, 'type'=> im::RGB);
>
> $wDisplay->insert('Image' =>
> 'place' => {'x'=>0.5,'y'=>0.25,'anchor'=>'sw'},
>  '-data'  => $im->data
> );
>
> run Prima;
>
>
> Thanks in advance!
>
> - Tim
>
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
>


-- 
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to