暗能星系

    • 登录
    • 搜索

    Bokeh实战

    UX 用户交互设计
    1
    6
    28
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • A
      anneng 最后由 编辑

      1.安装
      pip install bokeh
      2.基本概念
      Annotation 注解 像标题 图例 标签
      Visual aids that make reading the plot easier. This includes titles, legends, labels, or bands, for example.

      Application 一个应用
      A Bokeh application is a recipe for generating Bokeh documents. Typically, this is Python code run by a Bokeh server whenever a new sessions is created.

      BokehJS Bokeh的JS框架 可以直接用这个js库进行开发
      The JavaScript client library that actually renders the visuals and handles the UI interactions for Bokeh plots and widgets in the browser. In most cases, Bokeh handles all interactions with BokehJS automatically (“We write the JavaScript, so you don’t have to”).

      Document 文档 其实就是最终的html
      An organizing data structure for Bokeh applications. Documents contain all the Bokeh models and data needed to render an interactive visualization or application in the browser.

      Embedding 把bokeh嵌入到应用中的方法
      Various methods that help with including Bokeh plots and widgets in web apps, web pages, or Jupyter notebooks.

      Glyph 基础图形元素
      API objects that draw vectorized graphics to represent data. Glyphs are the basic visual building blocks of Bokeh plots. This includes elements such as lines, rectangles, squares, wedges, or the circles of a scatter plot. The The bokeh.plotting interface interface provides a convenient way to create plots centered around glyphs.

      Layout 布局
      A collection of Bokeh objects. This can be several plots and widgets, arranged in nested rows and columns.

      Model 内部的最底层模型
      The lowest-level objects that Bokeh visualizations consist of. Bokeh’s models are part of the The bokeh.models interface interface. Most users will not use this level of interface to assemble plots directly. However, ultimately all Bokeh plots consist of collections of models. It is helpful to understand them enough to configure their attributes and properties.

      Plot 一个组件
      Containers that hold all the various objects (such as renderers, glyphs, or annotations) of a visualization. The The bokeh.plotting interface interface provides the figure() function to help with assembling all the necessary objects.

      Renderer 渲染器
      General term for any method or function that draws elements of the plot. Examples of elements that are generated by renderers are glyphs or annotations.

      Server 后台服务器 用于分享和发布应用 基于流的大量数据处理
      The Bokeh server is an optional component. You can use the Bokeh server to share and publish Bokeh plots and apps, to handle streaming of large data sets, or to enable complex user interactions based on widgets and selections.

      Widget 控件 对图形进行控制和调整
      User interface elements that are not directly part of a Bokeh plot, such as sliders, drop-down menus, or buttons. You can use events and data from widgets in your Python code, or you can use input from widgets to update you Bokeh plot itself. You can use widgets in standalone applications or with the Bokeh server.

      3.前后端组成
      BokeH实际上是一种后端渲染的模式 和之前Java MVC模式类似。
      570f6e85-0583-45fb-84b7-edf2a033bd0c-image.png
      BokehJS, the JavaScript library
      BokehJS runs in the browser. This library handles rendering and user interactions. It takes a collection of declarative JSON objects as its input and uses them as instructions on how to handle the various aspects of your visualization in a browser. For example:

      plots and widgets

      layouts and arrangements

      tools and renderers

      plot axes

      In the browser, BokehJS converts these JSON objects into BokehJS models and renders them according to corresponding BokehJS views.

      Bokeh, the Python library
      The Python library generates the JSON objects that BokehJS uses to render your visualization in a browser.

      At its lowest level, the Python library uses a set of model classes that exactly mirror the set of models that BokehJS creates in a browser.

      These Python model classes are able to validate their content and attributes and serialize themselves to JSON. Most of the models are very simple and usually consist of only a few property attributes and no methods. You can configure the attributes of those models either by setting them when creating a model or later by setting attribute values on the model object.

      1 条回复 最后回复 回复 引用 0
      • A
        anneng 最后由 编辑

        https://dmolina.github.io/en/post/rest_bokeh/
        bokeh restfule模式

        Example

        class Figure(Resource):
        def get(self):
        plot = get_plot()
        div, js = components(plot)
        js, tags = autoload_static(plot, CDN, "fig/")
        return {'js': js, 'tags': tags}

        api.add_resource(Figure, '/fig')

        if name == 'main':
        app.run()

        1 条回复 最后回复 回复 引用 0
        • A
          anneng 最后由 anneng 编辑

          https://github.com/theislab/interactive_plotting/tree/master/interactive_plotting/experimental

          Bokeh的扩展机制:使用typescript进行扩展 以上面的为例
          bokeh init
          bokeh build

          //注意 npm 安装有问题的话 可以先下载仓库 本地安装 
          git clone https://github.com.cnpmjs.org/bokeh/bokeh.git
          npm install ./bokeh/bokehjs

          这个例子一直编译有问题 直接在__init__.py中把experimental的导出删除

          1 条回复 最后回复 回复 引用 0
          • A
            anneng 最后由 编辑

            70174ed5-afcb-4d25-8d9f-b5ef02efbc80-image.png
            bokeh、flask的数据交互

            1 条回复 最后回复 回复 引用 0
            • A
              anneng 最后由 编辑

              7a355f8c-b1f6-463d-888d-7b926ecd25da-image.png

              1 条回复 最后回复 回复 引用 0
              • A
                anneng 最后由 编辑

                d7d9f810-234e-491c-ae88-6d1b56146129-image.png

                1 条回复 最后回复 回复 引用 0
                • First post
                  Last post
                Powered by 暗能星系