[racket] Plot: #:samples parameter of function---is this what was meant?

From: Neil Toronto (neil.toronto at gmail.com)
Date: Thu May 24 22:16:51 EDT 2012

On 04/28/2012 06:31 AM, Deren Dohoda wrote:
> Thanks, Neil. I don't mind. Clearly rough sampling would make plots
> really icky. That's not at all my goal. It was more like localization
> of the parameters.--- which is still true under the current
> interpretation, just not in a way I expected.
>
> Backstory: I was plotting splines and it was extremely slow and at
> first all I found to speed things up was to decrease the number of
> samples... with predictable results. What I had done was interpolate
> 520 points, generating 519 polynomials evaluated over a short
> distance, which when plotted used (function ... ) 519 times. I was
> getting worried that it was trying to plot all 519 functions over the
> entire range but then discarding results not wanted to be seen or
> something...

Quick reminder: your worry was spot-on, and I was going to fix the problem.

I've just pushed a fix. This test program used to sample the function 
`f' about 500,000 times:

#lang racket
(require plot plot/utils)

(define count 0)
(define (f x)
   (set! count (+ count 1))
   (sin x))

(define xs (linear-seq -4 4 501))  ; bounds for 500 function renderers
(time
  (plot (for/list ([x1  (in-list xs)]
                   [x2  (in-list (rest xs))])
          (function f x1 x2))))
count


It now samples `f' only 1000 times: twice for each renderer's endpoints.

You might need to be a bit careful rendering piecewise functions with 
many function renderers. If the pieces are drawn partially transparent 
and a bit thick, the endpoints will visibly overlap, giving the function 
a "knotted" look. Here's an example:

#lang racket
(require plot plot/utils)

(define xs (linear-seq -4 4 50))
(plot (for/list ([x1  (in-list xs)]
                  [x2  (in-list (rest xs))])
         (function sin x1 x2 #:width 5 #:alpha 1/2)))

Neil ⊥

Posted on the users mailing list.