【问题标题】:Racket Real Time Plot/Chart球拍实时图/图表
【发布时间】:2016-06-01 05:06:54
【问题描述】:

我正在尝试在球拍中制作实时图表。我查看了 Plot 和 GUI 库,似乎我遗漏了一些东西。调用 plot 时,它返回一个图像 snip% 或许多其他图片格式。但是我似乎找不到任何方法来在图表中添加或删除点而不再次调用 plot 。现在我想我可以使用像

这样的方法

https://planet.racket-lang.org/package-source/williams/animated-canvas.plt/2/5/planet-docs/animated-canvas/index.html

但是我必须重新实现 snip% 附带的所有操作机制。现在可能是无论如何我都必须这样做,但我要问的是是否有任何现有机制可以让您在创建绘图片段后操纵图表和数据,或者我必须这样做每次我想改变它的外观时手动重绘它?通常,是否有任何现有的工作可以在 Racket 中制作实时图表?

【问题讨论】:

    标签: plot graph charts racket real-time-updates


    【解决方案1】:

    在深入研究 Rackets OOP 和 gui 库后,我最终发现(并理解)了 plot/dc,文档声称可以将其用于此类应用程序:https://docs.racket-lang.org/plot/plotting.html?q=plot%2Fdc#%28def._%28%28lib._plot%2Fmain..rkt%29._plot%2Fdc%29%29

    在渲染时它似乎比动画画布效果更好,但我仍然需要重新实现缩放和点击以及 snip%s 附带的所有东西,除非有人有更好的想法。

    #lang racket
    
    (require racket/gui plot racket/draw)
    
    (define num 0)
    
    (define f (new frame% [label "Test graph"]
                   [width 200]
                   [height 200]))
    (define c (new canvas% [parent f]))
    
    
    (send f show #t)
    
    (define (loop)
      (set! num (add1 num))
      (plot/dc (function sin (- pi) num)
               (send c get-dc)
               0 0
               (- (send f get-width) 40) ;; figure out how to get the actual size of the text outside the graphs boarder?
               (- (send f get-height) 40)
               #:title "Graph"
               #:x-label "num"
               #:y-label "sin"
               )
      (sleep/yield .2)
      (loop))
    
    (loop)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-14
      • 1970-01-01
      • 2018-09-23
      • 2014-07-06
      • 1970-01-01
      • 2019-10-29
      • 1970-01-01
      相关资源
      最近更新 更多