[racket] Controlling the size of plot symbols

From: Neil Toronto (neil.toronto at gmail.com)
Date: Thu Apr 10 18:35:38 EDT 2014

On 04/10/2014 08:17 AM, Konrad Hinsen wrote:
> Hi everyone,
>
> I am trying to use (abuse?) Racket's 3D plots for molecular
> visualization.  It actually works out better than I expected, except
> that I haven't yet figured out how to control the size of the plot
> symbols in the way I want.
>
> The documentation says no more than that the size of a symbol is a
> positive number. But how is this number interpreted?
>
> What I would like to have is "full circles" whose radii are equal to
> the atomic radii of my atoms. That means I have to set the symbol size
> on the same scale as the coordinates. My experiments make me suspect
> that symbol size is interpreted as an absolute size in pixels or
> whatever. Is it somehow possible to change this?

It's unfortunately not. But I think there's something you can do 
instead: use `parametric-interval' to draw the circles instead.

Of course, then you get squashed circles if the plot bounds and area 
aren't both square. And the axis ticks and labels sort of mess up the 
latter. So... you can turn them off, and add the axes back in. Here's 
one way, with central axes:

#lang racket

(require plot math)

(define xs (sample (normal-dist 0 1) 100))
(define ys (sample (normal-dist 0 1) 100))
(define rs (sample (uniform-dist 0 0.2) 100))

(define (circle-renderer x y r)
   (parametric-interval
    (λ (t) (list x y))
    (λ (t) (list (+ x (* r (cos t)))
                 (+ y (* r (sin t)))))
    0 (* 2 pi)
    #:line1-style 'transparent
    #:samples 15))

(plot-decorations? #f)
(time (plot (list (map circle-renderer xs ys rs)
                   (x-axis #:labels? #t)
                   (y-axis #:labels? #t))
             #:x-min -3.5 #:x-max 3.5
             #:y-min -3.5 #:y-max 3.5))


The "#:samples 15" argument is critical. Otherwise it samples 500 points 
around each circle, which takes a long time if you have a lot of circles.

Let me know if something like this doesn't work for you.

Neil ⊥


Posted on the users mailing list.