Fix bug in labels and legends when there is a single column
This commit is contained in:
parent
ec1ee66a57
commit
b138a28101
2 changed files with 9 additions and 15 deletions
|
@ -11,8 +11,7 @@
|
||||||
(def names (car csv))
|
(def names (car csv))
|
||||||
(def lsts
|
(def lsts
|
||||||
(apply map list
|
(apply map list
|
||||||
(for/collect ((row csv))
|
(for/collect ((row (cdr csv)))
|
||||||
(for/collect ((x row))
|
(for/collect ((x row))
|
||||||
(or (string->number x) +nan.0)))))
|
(or (string->number x) +nan.0)))))
|
||||||
(displayln (line-plot lsts title: (if (null? args) "" (car args))
|
(displayln (line-plot lsts title: (if (null? args) "" (car args)) names: names)))
|
||||||
xlabel: (car names) names: (cdr names))))
|
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
|
|
||||||
(def (line-plot lsts (colors +default-colors+)
|
(def (line-plot lsts (colors +default-colors+)
|
||||||
width: (width 160) height: (height 100)
|
width: (width 160) height: (height 100)
|
||||||
title: (title "") xlabel: (xlabel "") names: (names []))
|
title: (title "") names: (names []))
|
||||||
(define-values (xmin xmax ymin ymax canvases)
|
(define-values (xmin xmax ymin ymax canvases)
|
||||||
(match lsts
|
(match lsts
|
||||||
([ys] (let ((xmin 0)
|
([ys] (let ((xmin 0)
|
||||||
|
@ -83,15 +83,6 @@
|
||||||
(scale-fn xmin xmax)
|
(scale-fn xmin xmax)
|
||||||
(scale-fn ymin ymax)
|
(scale-fn ymin ymax)
|
||||||
width: width height: height)])))
|
width: width height: height)])))
|
||||||
([xs ys] (let ((xmin (apply nanmin xs))
|
|
||||||
(xmax (apply nanmax xs))
|
|
||||||
(ymin (apply nanmin ys))
|
|
||||||
(ymax (apply nanmax ys)))
|
|
||||||
(values xmin xmax ymin ymax
|
|
||||||
[(draw-canvas xs ys
|
|
||||||
(scale-fn xmin xmax)
|
|
||||||
(scale-fn ymin ymax)
|
|
||||||
width: width height: height)])))
|
|
||||||
([xs . yss] (let* ((xmin (apply nanmin xs))
|
([xs . yss] (let* ((xmin (apply nanmin xs))
|
||||||
(xmax (apply nanmax xs))
|
(xmax (apply nanmax xs))
|
||||||
(all-ys (flatten yss))
|
(all-ys (flatten yss))
|
||||||
|
@ -107,7 +98,11 @@
|
||||||
(u8vector-length (vector-ref (car canvases) 0))
|
(u8vector-length (vector-ref (car canvases) 0))
|
||||||
(vector-length (car canvases))))
|
(vector-length (car canvases))))
|
||||||
(add-border! plot xmin xmax ymin ymax)
|
(add-border! plot xmin xmax ymin ymax)
|
||||||
(unless (null? names) (add-legend! plot names colors))
|
(if (null? (cdr names))
|
||||||
(unless (string-empty? xlabel) (add-xlabel! plot xlabel))
|
(add-legend! plot (list (car names)) colors)
|
||||||
|
(add-legend! plot (cdr names) colors))
|
||||||
|
(if (null? (cdr names))
|
||||||
|
(add-xlabel! plot "Index")
|
||||||
|
(add-xlabel! plot (car names)))
|
||||||
(unless (string-empty? title) (add-title! plot title))
|
(unless (string-empty? title) (add-title! plot title))
|
||||||
(plot-str plot))
|
(plot-str plot))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue