在 Racket 中是否有任何函数可以在 python 中绘制类似 "stem" 的图?
Is in Racket any function to draw a plot like "stem" plot in python?
"A stem plot plots vertical lines at each x location from the baseline to y, and places a marker there."
像这样:
您使用的图表是由Python中的以下代码生成的:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0.1, 2 * np.pi, 41)
y = np.exp(np.sin(x))
plt.stem(x, y, use_line_collection=True)
plt.show()
正在尝试使用 Racket 构建类似的图:
#lang racket
(require plot)
(define my-linspace
(λ (start stop [num 50])
(range start stop (/ stop num))))
(define x (my-linspace 0 (* 2 pi) 41))
(define y (map exp (map sin x)))
(define my-blue '(32 119 180))
(plot
#:x-min -0.3
#:x-max 6.5
#:y-min -0.2
#:y-max 2.9
#:x-label #f
#:y-label #f
(let ([data (map list x y)])
(list
(points data #:color my-blue #:sym 'fullcircle5)
; for each data point, draw a vertical line
; at its "x" ranging from height 0 to its "y"
(list (map (λ (d) (vrule (first d) 0 (second d) #:color my-blue #:width 2)) data))
(list (hrule 0 (first (first data)) (first (last data)) #:color "red" #:width 2)))))
"A stem plot plots vertical lines at each x location from the baseline to y, and places a marker there."
像这样:
您使用的图表是由Python中的以下代码生成的:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0.1, 2 * np.pi, 41)
y = np.exp(np.sin(x))
plt.stem(x, y, use_line_collection=True)
plt.show()
正在尝试使用 Racket 构建类似的图:
#lang racket
(require plot)
(define my-linspace
(λ (start stop [num 50])
(range start stop (/ stop num))))
(define x (my-linspace 0 (* 2 pi) 41))
(define y (map exp (map sin x)))
(define my-blue '(32 119 180))
(plot
#:x-min -0.3
#:x-max 6.5
#:y-min -0.2
#:y-max 2.9
#:x-label #f
#:y-label #f
(let ([data (map list x y)])
(list
(points data #:color my-blue #:sym 'fullcircle5)
; for each data point, draw a vertical line
; at its "x" ranging from height 0 to its "y"
(list (map (λ (d) (vrule (first d) 0 (second d) #:color my-blue #:width 2)) data))
(list (hrule 0 (first (first data)) (first (last data)) #:color "red" #:width 2)))))