[racket] plot w/ log scale

From: Neil Toronto (neil.toronto at gmail.com)
Date: Fri Nov 9 20:56:12 EST 2012

On 11/08/2012 04:29 PM, David Van Horn wrote:
> On 11/8/12 5:48 PM, Vincent St-Amour wrote:
>> You can use axis transforms, but you may need to bound them.
>>
>> #lang racket
>> (require plot)
>> (parameterize ([plot-y-transform (axis-transform-bound log-transform 1
>> 2000)])
>>    (plot (discrete-histogram '(#(a 10) #(b 100) #(c 1000)))))
>
> Thanks!
>
> Maybe someone can explain why this doesn't work?
>
> #lang racket
> (require plot)
> (parameterize
>    ([plot-y-transform (axis-transform-bound log-transform 1 2000)]
>     [plot-y-ticks (log-ticks)])
>    (plot (discrete-histogram '(#(a 10) #(b 100) #(c 1000)))))
>
>
> log-ticks-layout: expects type <positive real> as 1st argument, given:
> 0; other arguments were: 1000

It's trying to lay out and format ticks on the entire visible axis, 
regardless of the axis's transform. (Ticks and transforms are entirely 
independent.) By default, histogram boxes draw from 0 to their given 
height. In your example, the layout-er tries to lay out ticks from 0 to 
1000 and fails.

This will do what you want (notice the #:y-min argument):

   (parameterize ([plot-y-transform log-transform]
                  [plot-y-ticks (log-ticks)])
     (plot (discrete-histogram '(#(a 10) #(b 100) #(c 1000))
                               #:y-min 1)))

The thing that's bugging me now is that this doesn't work:

   (parameterize ([plot-y-transform log-transform]
                  [plot-y-ticks (log-ticks)])
     (plot (discrete-histogram (list (vector 'a (ivl 1 10))
                                     (vector 'b (ivl 1 100))
                                     (vector 'c (ivl 1 1000))))))

"Histograms always draw from 0" is justifiable, but I wish I remembered 
making that design decision. :D

Neil ⊥


Posted on the users mailing list.