``` (require plot (define quest-symbs '(出席 発言 取組 聞取 資料 時刻 反応 熱意 理解 役立 満足))
;; number, short symbol, Japanese Sentence, English Translation (define responses '((5 特に “特にそう思う” “very much” “I really think so”) (4 多少 “多少そう思う” “fairly much” “I somewhat think so”) (3 どちも “どちらともいえない” “neither” “I can't say either way”) (2 あまり “あまりそう思わない” “not much” “I do not think so much”) (1 全く “全くそう思わない” “not at all” “I do not think so at all”)))
(define ind-als ;;教員 '((nme (教員 スモール 教養)) (smr (2018 1 H30 Z)) ;; 学期 SeMesteR (cls (1 84)) ;; 授業、教室 CLasS (dta ((62 13 9 0 0) ;; データ、DaTA (19 24 28 6 6) (23 24 27 6 4) (53 22 9 0 0) (35 29 19 0 1) (64 12 7 1 0) (54 19 10 1 0) (69 9 6 0 0) (34 28 16 4 1) (43 25 12 2 1) (35 25 20 2 1)))))
(define dep-als ;;学科 '((nme (学科 教養 大学)) (smr (2018 1 H30 Z)) (cls (7 269)) (dta ((202 41 26 0 0) (62 68 99 22 17) (72 74 98 14 11) (144 67 41 9 8) (111 78 55 13 10) (171 60 28 5 4) (140 65 46 10 8) (165 62 27 9 6) (96 98 51 14 8) (119 76 56 8 8) (109 79 60 9 10)))))
(define uni-als ;;大学 '((nme (大学 南九州 学園)) (smr (2018 1 H30 Z)) (cls (59 2452)) (dta ((1738 472 206 23 8) (495 549 923 195 283) (713 765 736 162 65) (1400 628 296 86 35) (1264 630 384 110 55) (1795 446 166 25 13) (1378 654 317 59 38) (1573 588 230 33 20) (976 886 438 99 42) (1411 684 289 33 24) (1217 740 388 58 38)))))
;; remove ind results from dep results ;; and dep results from uni (define als-ref (lambda (idx als) (let ((tmp (assv idx als))) (if tmp (cadr tmp) #f))))
(define remove-internal-data (lambda (base umbrella) (map (lambda (list-pair) (map – (car list-pair)(cadr list-pair))) (map list umbrella base))))
(define remove-internal-body-als (lambda (bse-als grp-als) (list (assoc 'nme grp-als) ;; keep the same (assoc 'smr grp-als) ;; keep the same (cons 'cls (list (map – (als-ref 'cls grp-als) (als-ref 'cls bse-als)))) (cons 'dta (list (remove-internal-data (als-ref 'dta bse-als) (als-ref 'dta grp-als))))))) ;; (remove-internal-body-als dep uni)
;; responses must be in form (Int “Str”) ;; like '(5 “very much” ... ) (4 “多少”) (define stack-plot-body ;; Questions Numbers Responses (lambda (Qstns Alst Rspns) ;; Questions, Numbers, Responses (plot (stacked-histogram (reverse (map vector Qstns (als-ref 'dta Alst))) #:invert? #t #:add-ticks? #t #:labels (map (lambda (l) (format “~s ~s” (car l) (cadr l))) Rspns) #:colors '(-7 -6 -5 -4 -3 -2 -1 0) #:line-colors '(-7 -6 -5 -4 -3 -2 -1 0) #:styles '(0 4 5 6 3) #:line-widths '(1 1 1 1 1) #:gap .5 ) #:legend-anchor 'top-right #:width 600 #:height 250 #:x-label “枚数 Responses” #:y-label “設問 Questions” #:title (format “~a ~a ~a” (car (als-ref 'nme Alst)) (car (als-ref 'smr Alst)) (cadr (als-ref 'smr Alst))) )))
#lang racket
(require plot) ;; discrete-histogram, stacked-histogram etc
(require plot/utils) ;; ->plot-label
(define listsmpl '(62 13 9 0 0))
(define counts->percents
(lambda (lon) ;; list of numbers
(let ((total (apply + lon)))
(map (lambda (count)
(* (/ count total) 100.0))
lon))))
(define pnt-w-lbl
(lambda (x n l)
(point-label (vector x n) l #:anchor 'bottom)))
(define vline-to-y
(lambda (x y)
(lines (map vector (list x x) (list 0 y)))))
(define lines-percents-labels-counts
(lambda (lon)
(let ((pcnts (counts->percents lon))
(lvels '(5 4 3 2 1))
(tot-lab (->plot-label (apply + lon))))
(append ;; need a flat list for plot
(map (lambda (l p) ;; level percent
(vline-to-y l p))
lvels pcnts)
(map (lambda (x n l) ;; xResponse level nNumber point lLabel
(pnt-w-lbl x n l))
lvels pcnts (map (lambda (s) (string-append s "/" tot-lab))
(map ->plot-label lon)))))))
(parameterize ((plot-title "TCR: Attendance")
(plot-tick-size 3)
(plot-x-far-axis? #f)
(plot-y-far-axis? #f))
(plot (lines-percents-labels-counts listsmpl)
#:y-max 100 #:x-min .2 #:x-max 5.8
#:width 300 #:height 250
#:x-label "levels" #:y-label "percent"))
#lang racket
(current-directory "FD201801")
(current-directory-for-user "FD201801")
(require plot) ;; discrete-histogram, stacked-histogram etc
(require plot/utils) ;; ->plot-label
;; Questions Symbols
(define quest-symbs '(出席 発言 取組 聞取 資料 時刻 反応 熱意 理解 役立 満足))
;; データを入力し直すところ
(define ind-als ;;教員の連帯リスト associative list
'((nme (教員 TCR スモール 教養))
(smr (2018 1 H30 Z)) ;; 学期 SeMesteR
(cls (1 84)) ;; 授業、教室 CLasS
(dta ((62 13 9 0 0) ;; データ、DaTA
(19 24 28 6 6)
(23 24 27 6 4)
(53 22 9 0 0)
(35 29 19 0 1)
(64 12 7 1 0)
(54 19 10 1 0)
(69 9 6 0 0)
(34 28 16 4 1)
(43 25 12 2 1)
(35 25 20 2 1)))))
(define dep-als ;;学科 associative list
'((nme (学科 DPT 教養 大学))
(smr (2018 1 H30 Z))
(cls (7 269))
(dta ((202 41 26 0 0)
(62 68 99 22 17)
(72 74 98 14 11)
(144 67 41 9 8)
(111 78 55 13 10)
(171 60 28 5 4)
(140 65 46 10 8)
(165 62 27 9 6)
(96 98 51 14 8)
(119 76 56 8 8)
(109 79 60 9 10)))))
(define uni-als ;;大学
'((nme (大学 UVY 南九州 学園))
(smr (2018 1 H30 Z))
(cls (59 2452))
(dta ((1738 472 206 23 8)
(495 549 923 195 283)
(713 765 736 162 65)
(1400 628 296 86 35)
(1264 630 384 110 55)
(1795 446 166 25 13)
(1378 654 317 59 38)
(1573 588 230 33 20)
(976 886 438 99 42)
(1411 684 289 33 24)
(1217 740 388 58 38)))))
;; inspired by "Racket for Data Science" code
;; by Nicholas M. Van Horn n3mo's
(define als-ref
(lambda (idx als)
(let ((tmp (assv idx als)))
(if tmp (cadr tmp) #f))))
(define counts->percents
(lambda (lon) ;; list of numbers
(let ((total (apply + lon)))
(map (lambda (count)
(* (/ count total) 100.0))
lon))))
(define pnt-w-lbl
(lambda (x n l)
(point-label (vector x n) l #:anchor 'bottom)))
(define vline-to-y
(lambda (x y)
(lines (map vector (list x x) (list 0 y)))))
(define lines-percents-labels-counts
(lambda (lon)
(let ((pcnts (counts->percents lon))
(lvels '(5 4 3 2 1))
(tot-lab (->plot-label (apply + lon))))
(append ;; need a flat list for plot
(map (lambda (l p) ;; level percent
(vline-to-y l p))
lvels pcnts)
(map (lambda (x n l) ;; xResponse level nNumber point lLabel
(pnt-w-lbl x n l))
lvels pcnts (map (lambda (s) (string-append s "/" tot-lab))
(map ->plot-label lon)))))))
;; get data ready for lines-percents-labels-counts
(define dta->Qss-Als
(lambda (Qss Als) ;; Question Symbols, A-list
(map list Qss (als-ref 'dta Als))))
(define plot-bod-als-to-percentlines-countlabels
(lambda (BodAls Qsyms)
(let ((QR-als (dta->Qss-Als Qsyms BodAls))
(bod (->plot-label (car (als-ref 'nme BodAls)))))
(define lines-percents-titled
(lambda (QR)
(let* ((ttl (string-append bod ":" (->plot-label (car QR))))
(fle-name (string-append ttl (->plot-label (car (als-ref 'smr BodAls))) "0" (->plot-label (cadr (als-ref 'smr BodAls))) ".png")))
(plot (lines-percents-labels-counts (cadr QR))
#:x-min .2 #:y-max 100
#:x-max 5.8 #:height 250
#:width 400 #:y-label "percent"
#:x-label "levels"
#:title ttl
#:out-file fle-name
#:out-kind 'png))))
(map lines-percents-titled QR-als))))
;;; Working!!
(parameterize ((plot-tick-size 3)
(plot-x-far-axis? #f)
(plot-y-far-axis? #f))
(plot-bod-als-to-percentlines-countlabels uni-als quest-symbs))
Plot a Spiral with with N as26 x-start as 3
(require plot)
(define (sqr n) (* n n))
(define (next-vertex xy-vector) (match-define (vector x y) xy-vector) (define h (sqrt (+ (sqr x) (sqr y)))) (vector (– x (/ y h)) (+ y (/ x h))))
(define (short-hypo-lines xy-vec) (define new-xy (next-vertex xy-vec)) (list (lines (list xy-vec new-xy)) (lines (list (vector 0 0) new-xy))))
(define N 26) (define x-start 3) (define y-start 0)
(define (spiral limit) (define (helper lim xy-vec lines) (cond ((= 0 lim) lines) (#t (helper (sub1 lim) (next-vertex xy-vec) (cons (short-hypo-lines xy-vec) lines))))) (helper limit (vector x-start y-start) '()))
(parameterize ((plot-decorations? #f)) (plot (list ;; plot first line from 0,0 to x-start,y-start (lines (list (vector 0 0)(vector x-start y-start))) ;; plot the short-side and hypotenuse for the right triangles ;; that make form the spiral (spiral N))))
;; save the plot to png for sharing on-line
(define spiral-bmp-1 (parameterize ((plot-decorations? #f)) (plot-bitmap (list (lines (list (vector 0 0)(vector x-start y-start))) (spiral N)))))
(send spiral-bmp-1 save-file “spiral-1-vector.png” 'png)
```
#Racket #plot #Python #TheodorusSpiral #seashell
Spiral Plot with Vectors
#lang racket
; https://ruhrspora.de/posts/3043273
; https://www.johndcook.com/blog/2019/08/04/spiral-of-theodorus/
; https://write.as/bs2lr/turtles-do-a-spiral
; http://mathcentral.uregina.ca/QQ/database/QQ.09.07/h/lucy1.html
(require plot)
(define (sqr n)
(* n n))
(define (next-vertex xy-vector)
(match-define (vector x y) xy-vector)
(define h (sqrt (+ (sqr x) (sqr y))))
(vector (- x (/ y h)) (+ y (/ x h))))
(define (short-hypo-lines xy-vec)
(define new-xy
(next-vertex xy-vec))
(list (lines (list xy-vec new-xy))
(lines (list (vector 0 0) new-xy))))
(define N 16)
(define (spiral limit)
(define (helper lim xy-vec lines)
(cond
((= 0 lim) lines)
(#t (helper (sub1 lim)
(next-vertex xy-vec)
(cons
(short-hypo-lines xy-vec)
lines)))))
(helper limit (vector 1 0) '()))
(parameterize
((plot-decorations? #f))
(plot (list
(lines (list (vector 0 0)(vector 1 0)))
(spiral N))))
(define spiral-bmp-1
(parameterize
((plot-decorations? #f))
(plot-bitmap (list
(lines (list (vector 0 0)(vector 1 0)))
(spiral N)))))
(send spiral-bmp-1 save-file "spiral-1-vector.png" 'png)
#Racket #DrRacket #Plot #TheodorusSpiral
Theodorus Spiral plot
#lang racket
; https://ruhrspora.de/posts/3043273
; https://www.johndcook.com/blog/2019/08/04/spiral-of-theodorus/
; https://write.as/bs2lr/turtles-do-a-spiral
; http://mathcentral.uregina.ca/QQ/database/QQ.09.07/h/lucy1.html
(require plot)
(define (sqr n)
(* n n))
(define (next-vertex xy-list)
(match-define (list x y) xy-list)
(define h (sqrt (+ (sqr x) (sqr y))))
(list (- x (/ y h)) (+ y (/ x h))))
(define (short-hypo-lines xy-list)
(define new-xy
(next-vertex xy-list))
(list (lines (list (list->vector xy-list) (list->vector new-xy)))
(lines (list (list->vector (list 0 0)) (list->vector new-xy)))))
(define N 17)
(define (spiral limit)
(define (helper lim xy-list lines)
(cond
((= 0 lim) lines)
(#t (helper (sub1 lim)
(next-vertex xy-list)
(cons
(short-hypo-lines xy-list)
lines)))))
(helper limit (list 1 0) '()))
(parameterize
((plot-decorations? #f))
(plot (list
(lines (map vector (list 0 1)(list 0 0)))
(spiral N))))
(define spiral-bmp-1
(parameterize
((plot-decorations? #f))
(plot-bitmap (list
(lines (map vector (list 0 1)(list 0 0)))
(spiral N)))))
;; save bitmap as png to upload on-line
(send spiral-bmp-1 save-file "spiral-1.png" 'png)