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 lsts
|
||||
(apply map list
|
||||
(for/collect ((row csv))
|
||||
(for/collect ((row (cdr csv)))
|
||||
(for/collect ((x row))
|
||||
(or (string->number x) +nan.0)))))
|
||||
(displayln (line-plot lsts title: (if (null? args) "" (car args))
|
||||
xlabel: (car names) names: (cdr names))))
|
||||
(displayln (line-plot lsts title: (if (null? args) "" (car args)) names: names)))
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
|
||||
(def (line-plot lsts (colors +default-colors+)
|
||||
width: (width 160) height: (height 100)
|
||||
title: (title "") xlabel: (xlabel "") names: (names []))
|
||||
title: (title "") names: (names []))
|
||||
(define-values (xmin xmax ymin ymax canvases)
|
||||
(match lsts
|
||||
([ys] (let ((xmin 0)
|
||||
|
@ -83,15 +83,6 @@
|
|||
(scale-fn xmin xmax)
|
||||
(scale-fn ymin ymax)
|
||||
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))
|
||||
(xmax (apply nanmax xs))
|
||||
(all-ys (flatten yss))
|
||||
|
@ -107,7 +98,11 @@
|
|||
(u8vector-length (vector-ref (car canvases) 0))
|
||||
(vector-length (car canvases))))
|
||||
(add-border! plot xmin xmax ymin ymax)
|
||||
(unless (null? names) (add-legend! plot names colors))
|
||||
(unless (string-empty? xlabel) (add-xlabel! plot xlabel))
|
||||
(if (null? (cdr names))
|
||||
(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))
|
||||
(plot-str plot))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue