[racket] Plot question: discrete-histogram with error-bars
Do you mean the benchmark names? Those do show up in the benchmark docs,
even with `no-ticks`.
Do the examples in the benchmark docs[1] looklike what you want, or are
we talking about different things?
Vincent
[1] http://stamourv.github.io/racket-benchmark/index.html#%28part._simple._example._fibonacci._and._jit%29
At Tue, 29 Jul 2014 16:46:54 -0400 (EDT),
J. Ian Johnson wrote:
>
> no-ticks entirely removes ticks, so I don't get to see my histogram categories. I had to modify error-bars.
> -Ian
> ----- Original Message -----
> From: "Vincent St-Amour" <stamourv at ccs.neu.edu>
> To: "J. Ian Johnson" <ianj at ccs.neu.edu>
> Cc: "Vincent St-Amour" <stamourv at ccs.neu.edu>, "users" <users at racket-lang.org>
> Sent: Tuesday, July 29, 2014 4:39:46 PM GMT -05:00 US/Canada Eastern
> Subject: Re: [racket] Plot question: discrete-histogram with error-bars
>
> I misremembered. The relevant code is in the library's docs:
>
> (parameterize ([plot-x-ticks no-ticks]) ...)
>
> Vincent
>
>
> At Tue, 29 Jul 2014 15:39:36 -0400 (EDT),
> J. Ian Johnson wrote:
> >
> > [1 <text/plain; utf-8 (7bit)>]
> > I don't see anything that addresses the number/category mismatch in the benchmark library. I just hacked on error-bars to take the same keywords that discrete-histogram takes for introducing ticks, #:add-ticks? and #:far-ticks?, and use those for something like default-ticks-fun in plot-element, only returns empty for x,y[,z] if the given booleans are false.
> >
> > -Ian
> > ----- Original Message -----
> > From: "Vincent St-Amour" <stamourv at ccs.neu.edu>
> > To: "J. Ian Johnson" <ianj at ccs.neu.edu>
> > Cc: "users" <users at racket-lang.org>
> > Sent: Tuesday, July 29, 2014 3:17:03 PM GMT -05:00 US/Canada Eastern
> > Subject: Re: [racket] Plot question: discrete-histogram with error-bars
> >
> > Have a look at the benchmarking library. I remember we solved that
> > problem, but I don't remember how off the top of my head.
> >
> > Vincent
> >
> >
> > At Tue, 29 Jul 2014 15:02:37 -0400 (EDT),
> > J. Ian Johnson wrote:
> > >
> > > error-bars does not work with discrete-histogram in a convenient way. I've mostly worked around it by computing the x coordinate for where each error bar will go, but providing a number instead of the histogram's "category" introduces a new axis that gets rendered with my histogram's categories. It doesn't really make sense to show those numbers.
> > >
> > > As a stopgap measure before error-bars (or discrete-histogram) is fixed, how do I tell plot to not render the error-bar's x axis?
> > >
> > > I've attached what a plot looks like with and without error bars to illustrate the problematic output.
> > > Thanks,
> > > -Ian
> > >
> > > (resent with compressed attachments)
> > >
> > > Here is a snippet of the rendering code I'm using.
> > > (define (get-numbers tag sel)
> > > (define (scale x) (if (number? x) x 0))
> > > (for*/list ([(name numbers) (in-hash timings)]
> > > [n (in-value (hash-ref numbers tag))])
> > > (list name
> > > (scale (average-vec (sel n)))
> > > (scale (stddev-vec (sel n))))))
> > >
> > > (define (bench-plot sel y-label x-label out-file)
> > > (plot
> > > (for/fold ([plots '()])
> > > ([(tag algo) (in-dict algo-name)]
> > > [i (in-naturals)])
> > > (define numbers* (get-numbers tag sel))
> > > (define skip 5.5)
> > > (define error
> > > ;; For current algo, give error bars for each benchmark.
> > > (error-bars (for/list ([x numbers*] [m (in-naturals)])
> > > (list (+ 1/2 i (* m skip))
> > > (second x)
> > > (third x)))
> > > #:x-min i
> > > #:color -7))
> > > (list* error
> > > (discrete-histogram (for/list ([x numbers*]) (list (first x) (second x)))
> > > #:label algo
> > > #:skip skip #:x-min i
> > > #:style (add1 (* 2 i))
> > > #:color -7 #:line-color "black"
> > > #:line-style i)
> > > plots))
> > > #:y-label y-label
> > > #:x-label x-label
> > > #:legend-anchor 'top-left
> > > #:out-file out-file))
> > >
> > > (define (do-with-params thunk)
> > > (parameterize ([plot-font-size 20]
> > > [plot-x-tick-label-anchor 'top-right]
> > > [plot-x-tick-label-angle 60]
> > > [line-color "black"]
> > > [interval-color "black"]
> > > [interval-line1-color "black"]
> > > [interval-line2-color "black"]
> > > [plot-width (* 2 (plot-width))])
> > > (thunk)))
> > > [2 with-error.pdf <application/pdf (base64)>]
> > >
> > > [3 without-error.pdf <application/pdf (base64)>]
> > >
> > > [4 <text/plain; us-ascii (7bit)>]
> > > ____________________
> > > Racket Users list:
> > > http://lists.racket-lang.org/users
> > [2 error.patch <text/x-patch (quoted-printable)>]
> > diff --git a/pkgs/plot-pkgs/plot-lib/plot/private/common/plot-element.rkt b/pkgs/plot-pkgs/plot-lib/plot/private/common/plot-element.rkt
> > index c5d491a..a3d7009 100644
> > --- a/pkgs/plot-pkgs/plot-lib/plot/private/common/plot-element.rkt
> > +++ b/pkgs/plot-pkgs/plot-lib/plot/private/common/plot-element.rkt
> > @@ -32,6 +32,32 @@
> > ((plot-z-ticks) za zb) ((plot-z-far-ticks) za zb))]
> > [_ (raise-type-error 'default-ticks-fun "2- or 3-vector of ivl" r)])))
> >
> > +(defproc (optional-ticks-fun [add-ticks? boolean?] [far-ticks? boolean?]) ticks-fun/c
> > + (λ (r)
> > + (match r
> > + [(vector (ivl xa xb) (ivl ya yb))
> > + (define-values (x-ticks y-ticks)
> > + (if add-ticks?
> > + (values ((plot-x-ticks) xa xb) ((plot-y-ticks) ya yb))
> > + (values empty empty)))
> > + (define-values (x-far-ticks y-far-ticks)
> > + (if far-ticks?
> > + (values ((plot-x-far-ticks) xa xb) ((plot-y-far-ticks) ya yb))
> > + (values empty empty)))
> > + (values x-ticks x-far-ticks y-ticks y-far-ticks)]
> > + [(vector (ivl xa xb) (ivl ya yb) (ivl za zb))
> > + (define-values (x-ticks y-ticks z-ticks)
> > + (if add-ticks?
> > + (values ((plot-x-ticks) xa xb) ((plot-y-ticks) ya yb) ((plot-z-ticks) za zb))
> > + (values empty empty empty)))
> > + (define-values (x-far-ticks y-far-ticks z-far-ticks)
> > + (if far-ticks?
> > + (values ((plot-x-far-ticks) xa xb) ((plot-y-far-ticks) ya yb) ((plot-z-far-ticks) za zb))
> > + (values empty empty empty)))
> > + (values x-ticks x-far-ticks y-ticks y-far-ticks z-ticks z-far-ticks)
> > + (values )]
> > + [_ (raise-type-error 'optional-ticks-fun "2- or 3-vector of ivl" r)])))
> > +
> > (defproc (function-bounds-fun [f sampler/c] [samples exact-nonnegative-integer?]) bounds-fun/c
> > (λ (r)
> > (match-define (vector xi yi) r)
> > diff --git a/pkgs/plot-pkgs/plot-lib/plot/private/contracted/plot-element.rkt b/pkgs/plot-pkgs/plot-lib/plot/private/contracted/plot-element.rkt
> > index 1b35b99..f583e8b 100644
> > --- a/pkgs/plot-pkgs/plot-lib/plot/private/contracted/plot-element.rkt
> > +++ b/pkgs/plot-pkgs/plot-lib/plot/private/contracted/plot-element.rkt
> > @@ -30,7 +30,7 @@
> > [ticks-fun (or/c ticks-fun/c #f)]
> > [render-proc (or/c ((is-a?/c 3d-plot-area%) . -> . (treeof legend-entry?)) #f)])))
> > bounds-fun/c ticks-fun/c
> > - (activate-contract-out default-ticks-fun
> > + (activate-contract-out default-ticks-fun optional-ticks-fun
> > function-bounds-fun function-interval-bounds-fun
> > inverse-bounds-fun inverse-interval-bounds-fun
> > surface3d-bounds-fun)
> > diff --git a/pkgs/plot-pkgs/plot-lib/plot/private/plot2d/point.rkt b/pkgs/plot-pkgs/plot-lib/plot/private/plot2d/point.rkt
> > index 715ed96..606d670 100644
> > --- a/pkgs/plot-pkgs/plot-lib/plot/private/plot2d/point.rkt
> > +++ b/pkgs/plot-pkgs/plot-lib/plot/private/plot2d/point.rkt
> > @@ -139,6 +139,8 @@
> > [#:line-style line-style plot-pen-style/c (error-bar-line-style)]
> > [#:width width (>=/c 0) (error-bar-width)]
> > [#:alpha alpha (real-in 0 1) (error-bar-alpha)]
> > + [#:add-ticks? add-ticks? boolean? #t]
> > + [#:far-ticks? far-ticks? boolean? #t]
> > ) renderer2d?
> > (let* ([bars (sequence->listof-vector 'error-bars bars 3)]
> > [bars (filter vrational? bars)])
> > @@ -149,6 +151,8 @@
> > [x-max (if x-max x-max (apply max* xs))]
> > [y-min (if y-min y-min (apply min* (map - ys hs)))]
> > [y-max (if y-max y-max (apply max* (map + ys hs)))])
> > - (renderer2d (vector (ivl x-min x-max) (ivl y-min y-max)) #f default-ticks-fun
> > + (renderer2d (vector (ivl x-min x-max) (ivl y-min y-max))
> > + #f
> > + (optional-ticks-fun add-ticks? far-ticks?)
> > (error-bars-render-fun xs ys hs
> > color line-width line-style width alpha)))])))