Add option to add title
This commit is contained in:
parent
6301fa651d
commit
0b1b2f84b2
4 changed files with 12 additions and 3 deletions
|
@ -7,12 +7,15 @@ Depends on [[https://github.com/dlozeve/fancy][Fancy]] for colors and display.
|
||||||
#+ATTR_HTML: :width 100% :style margin-left: auto; margin-right: auto;
|
#+ATTR_HTML: :width 100% :style margin-left: auto; margin-right: auto;
|
||||||
[[./demo.png]]
|
[[./demo.png]]
|
||||||
|
|
||||||
Annual CO₂ emissions (t) (source: [[https://ourworldindata.org/grapher/annual-co2-emissions-per-country?tab=chart&time=1850..latest&country=CHN~USA~Europe][Our World in Data]])
|
(source: [[https://ourworldindata.org/grapher/annual-co2-emissions-per-country?tab=chart&time=1850..latest&country=CHN~USA~Europe][Our World in Data]])
|
||||||
|
|
||||||
** Features
|
** Features
|
||||||
|
|
||||||
- Braille canvas for plotting
|
- Braille canvas for plotting
|
||||||
- Line plots
|
- Line plots
|
||||||
|
- Axes and tick labels showing ranges
|
||||||
|
- Optional title, x-axis label, and legend
|
||||||
|
- Input data loading from a CSV file
|
||||||
|
|
||||||
** References
|
** References
|
||||||
|
|
||||||
|
|
BIN
demo.png
BIN
demo.png
Binary file not shown.
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 26 KiB |
2
demo.ss
2
demo.ss
|
@ -14,5 +14,5 @@
|
||||||
(for/collect ((row csv))
|
(for/collect ((row 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
|
(displayln (line-plot lsts title: (if (null? args) "" (car args))
|
||||||
xlabel: (car names) names: (cdr names))))
|
xlabel: (car names) names: (cdr names))))
|
||||||
|
|
|
@ -64,9 +64,14 @@
|
||||||
(set! (plot-str plot)
|
(set! (plot-str plot)
|
||||||
(str (plot-str plot) (make-string (quotient (plot-hsize plot) 2) #\ ) xlabel "\n")))
|
(str (plot-str plot) (make-string (quotient (plot-hsize plot) 2) #\ ) xlabel "\n")))
|
||||||
|
|
||||||
|
(def (add-title! plot title)
|
||||||
|
(set! (plot-str plot)
|
||||||
|
(str "\n" (make-string (quotient (- (plot-hsize plot) 10) 2) #\ ) title "\n\n"
|
||||||
|
(plot-str plot))))
|
||||||
|
|
||||||
(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)
|
||||||
xlabel: (xlabel "") names: (names []))
|
title: (title "") xlabel: (xlabel "") 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)
|
||||||
|
@ -104,4 +109,5 @@
|
||||||
(add-border! plot xmin xmax ymin ymax)
|
(add-border! plot xmin xmax ymin ymax)
|
||||||
(unless (null? names) (add-legend! plot names colors))
|
(unless (null? names) (add-legend! plot names colors))
|
||||||
(unless (string-empty? xlabel) (add-xlabel! plot xlabel))
|
(unless (string-empty? xlabel) (add-xlabel! plot xlabel))
|
||||||
|
(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