[plt-scheme] Science Collection - saving plots

From: Williams, M. Douglas (M.DOUGLAS.WILLIAMS at saic.com)
Date: Wed Oct 13 10:23:34 EDT 2004

I hadn't looked too deeply into the graphics yet.  Thanks for the help.  It
will make my saving graphics and putting them into presentations and
documentation much easier.

I still wish that cut and paste 'just worked' from displayed snips to other
apps, but I had no problems finding workarounds on both Windows and Linux.

Has anyone put together a package of graphics tools/helper functions like
the 'save-snip' example?

Thanks for the interest,
Doug

> -----Original Message-----
> From: Jens Axel Søgaard 
> Sent: Wednesday, October 13, 2004 6:03 AM
> To: Williams, M. Douglas
> Subject: [plt-scheme] Science Collection - saving plots
> 
> Hello,
> 
> I have played a little with the science collection and am quite happy
> with it.
> 
> Yesterday I saw the video and slides from the Denver meeting, which were
> quite interesting  (thanks for making them available). I couldn't help
> noticing that
> you were unsatisfied by the way you saved plots as image files.
> 
> Loading and saving images in the DrScheme repl involves two concepts. The
> image it self is a bitmap% object, and the thing that is displayed on
> the screen
> is a snip%, which contains the bitmap object. To save the image inside a
> snip, one has to get the bitmap and send it a save message:
> 
> (define (save-snip snip filename)
>   (send (send snip get-bitmap)
>         save-file filename 'png 75)
>   (void))
> 
> Loading an image to be displayed in the repl is done by making a bitmap%
> object
> (and this loads the image from disk) and then wrapping it in a snip%.
> 
> (define (load-snip filename)
>   (make-object image-snip%
>     (make-object bitmap% filename 'png #f)
>     #f))
> 
> DrScheme supports other formats such as gif and jpeg if you don't want
> pngs.
> The mysterious 75 is the quality used for saving, but that only has an
> effect for jpeg-images.
> 
> Here is a complete example:
> 
> (require (lib "binomial.ss" "science" "random-distributions"))
> (require (lib "discrete-histogram-with-graphics.ss" "science"))
> 
> (define (save-snip snip filename)
>   (send (send snip get-bitmap)
>         save-file filename 'png 75)
>   (void))
> 
> (define (load-snip filename)
>   (make-object image-snip%
>     (make-object bitmap% filename 'png #f)
>     #f))
> 
> (let ((the-snip (let ((h (make-discrete-histogram)))
>                   (do ((i 0 (+ i 1)))
>                     ((= i 100) (void))
>                     (discrete-histogram-increment! h (random-binomial .5
> 20)))
>                   (discrete-histogram-plot h "Histogram of Binomial
> Distribution"))))
>   (save-snip the-snip "foo.png"))
> 
> (load-snip "foo.png")
> 
> --
> Jens Axel Søgaard



Posted on the users mailing list.