在Racket中,是否有任何函数可以在python中绘制类似于“ stem”图的图?

时间:2019-11-18 17:29:05

标签: plot racket

“茎图在从基线到y的每个x位置绘制垂直线,并在此处放置标记。” 像这样: python stem plot

1 个答案:

答案 0 :(得分:1)

您使用的图形由以下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()

尝试使用球拍构建相似的剧情:

#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)))))

enter image description here