racket / plot

Other
40 stars 37 forks source link

Allow markers to be specified for function and line renderers (#118) #120

Closed alex-hhh closed 1 year ago

alex-hhh commented 1 year ago

The #marker option for function, inverse and line renderers will draw markers along the rendered plot line. The main difference between overlaying a points renderer over a function or line renderer is that legend entries show the marker as well.

Here is an example:

#lang racket

(require plot)
(plot-new-window? #t)

(define (do-plot-pr118)
  (define-values (xdata ydata)
    (parameterize ([current-pseudo-random-generator (make-pseudo-random-generator)])
      (random-seed 42)                    ; ensure our test is deterministic
      (define (randsin x)(+ (sin x) (/ ( - (random) 0.5) 5) ) )
      (define xdata (range 0 (* 2 pi) (/ pi 9 ) ) )
      (define ydata (map (lambda (x) (randsin x) ) xdata ) )
      (values xdata ydata)))

  (parameterize ([point-size 10]
                 [line-width 2]
                 [plot-width 800]
                 [plot-height 600]
                 [point-line-width 1.5]
                 [plot-pen-color-map 'set1]
                 [plot-x-label  #f]
                 [plot-y-label  #f])
    (plot (list
           (function sin 0 (* 2 pi)
                     #:label "exact"
                     #:marker 'diamond
                     #:color 0
                     #:marker-count 10)
           (lines (map vector xdata ydata )
                  #:label "discrete"
                  #:marker 'square
                  #:color 1
                  #:marker-color "black"))
          #:legend-anchor 'top-right
          #:out-file "Sample-PR118.png")))

(do-plot-pr118)

Sample-PR118