我想做一些类似于matplotlib.pyplot.matshow的球拍。我明白这是一个微不足道的问题,也许我只是在做蠢事,但在阅读了球拍绘图文档之后,我还是失败了。
将被转换为圆圈图像的示例矩阵:
#lang typed/racket
(require math/array)
(require plot)
(: sq (-> Integer Integer))
(define (sq [v : Integer])
(* v v))
(: make-2d-matrix (-> Integer Integer (Array Boolean)))
(define (make-2d-matrix [s : Integer] [r : Integer])
(let ([center : Integer (exact-round (/ s 2))])
(let ([a (indexes-array ((inst vector Integer) s s))])
(let ([b (inline-array-map (λ ([i : (Vectorof Index)])
(+
(sq (- (vector-ref i 0) center))
(sq (- (vector-ref i 1) center))))
a)])
(array<= b (array (sq r)))
))))
(array-map (λ ([i : Boolean]) (if (eq? i #f) 0 1)) (make-2d-matrix 20 6))谁能给我个提示吗?
发布于 2017-04-22 23:31:56
完全不是愚蠢的问题。这是一个很难与一群python库程序员竞争的领域。下面是我在球拍中的表现:
#lang racket
(require 2htdp/image
math/array)
;; a 10x10 array
(define a
(build-array #(10 10)
(λ (e)
(match e
[(vector x y)
(cond [(= x y) x]
[else 0])]))))
;; map a value to a color
(define (cmap v)
(color (floor (* 255 (/ v 10)))
0
(floor (* 255 (- 1 (/ v 10))))))
(apply
above
(for/list ([y (in-range 10)])
(apply
beside
(for/list ([x (in-range 10)])
(rectangle 10 10 'solid (cmap (array-ref a (vector x y))))))))发布于 2017-04-23 06:39:39
根据您的情况,您可能会对flomaps感兴趣:
title.html?q=flbitmap
发布于 2017-04-23 02:06:52
我不知道你到底想策划什么。plot库是围绕绘图函数设计的,但我不知道您想表达什么函数。
下面是绘制矩阵的两种方法:
(plot (points (cast (array->vector* m) (Vectorof (Vectorof Real)))
(plot3d (points3d (cast (array->vector* m) (Vectorof (Vectorof Real)))
之所以需要cast,是因为array->vector*的类型不够具体。
https://stackoverflow.com/questions/43565442
复制相似问题