跳转到主要内容

trame的Plotly图象小部件

项目描述

Test and Release

trame-plotly扩展trame 小部件,使其能够通过Plotly组件显示图表。

trame中的Plotly集成允许您通过利用它们的 PythonJavaScript 接口来创建丰富的可视化。JavaScript版本通过trame.widgets.plotly.Plotly类定义中的Vue.plotly暴露。

此包不应单独使用,而应作为 trame 的依赖项。有关任何特定性,请参阅trame文档

安装

可以使用pip安装trame-plotly

pip install --upgrade trame-plotly

使用方法

《Trame 教程》是学习如何使用该库并开始构建您自己的应用程序的最佳去处。[前往教程](https://kitware.github.io/trame/docs/tutorial.html)。

API 参考文档提供了 API 级别的文档。[查看 API 参考](https://trame.readthedocs.io/en/latest/index.html)。

Plotly 组件依赖于服务器来生成图表定义。这可以通过手动操作或简单地使用 Python 版本的 Plotly 来实现。

如何使用它?

使用 Python 库

import plotly.graph_objects as go
from trame.widgets import plotly

fig = go.Figure(
    data=go.Contour(
        z=[
            [10, 10.625, 12.5, 15.625, 20],
            [5.625, 6.25, 8.125, 11.25, 15.625],
            [2.5, 3.125, 5.0, 8.125, 12.5],
            [0.625, 1.25, 3.125, 6.25, 10.625],
            [0, 0.625, 2.5, 5.625, 10],
        ]
    )
)
fig2 = go.Figure(
    data=go.Contour(
        z=[
            [5.625, 6.25, 8.125, 11.25, 15.625],
            [2.5, 3.125, 5.0, 8.125, 12.5],
            [10, 10.625, 12.5, 15.625, 20],
            [0.625, 1.25, 3.125, 6.25, 10.625],
            [0, 0.625, 2.5, 5.625, 10],
        ]
    )
)

widget = plotly.Figure(fig)
widget.update(fig2)

但是,如果您想尝试更多,可以直接使用组件 API,同时自行构建数据。

from trame.widgets import plotly

# https://plotly.com/javascript/reference/
plotly_data = [
  {
    "x": [1,2,3,4],
    "y": [10,15,13,17],
    "type": "scatter",
  }
]

# https://plotly.com/javascript/reference/layout/
plotly_layout = {
  "title": "My graph",
}

# https://plotly.com/javascript/configuration-options/
plotly_options = {
  "scroll_zoom": True,
  "editable": True,
  "static_plot": True,
  "to_image_options": {
    "format": "svg", # one of png, svg, jpeg, webp
    "filename": "custom_image",
    "height": 500,
    "width": 700,
    "scale": 1 # Multiply title/legend/axis/canvas sizes by this factor
  },
  "display_mode_bar": True,
  "mode_bar_buttons_to_remove": [
    "zoom2d", "pan2d", "select2d", "lasso2d", "zoomIn2d", "zoomOut2d", "autoScale2d", "resetScale2d", # 2D
    "zoom3d", "pan3d", "orbitRotation", "tableRotation", "handleDrag3d", "resetCameraDefault3d", "resetCameraLastSave3d", "hoverClosest3d", # 3D
    "hoverClosestCartesian", "hoverCompareCartesian", # Cartesian
    "zoomInGeo", "zoomOutGeo", "resetGeo", "hoverClosestGeo", # Geo
    "hoverClosestGl2d", "hoverClosestPie", "toggleHover", "resetViews", "toImage", "sendDataToCloud", "toggleSpikelines", "resetViewMapbox", # Other
  ],
  "mode_bar_buttons_to_add": [
    {
      "name": 'color toggler',
      "icon": icon1, # https://plotly.com/javascript/configuration-options/#add-buttons-to-modebar
      "click": "...",
    },
  ],
  "locale": "fr",
  "display_logo": False,
  "responsive": True,
  "double_click_delay": 1000,
}

# Hand made chart
chart = plotly.Figure(
  data=("chart_data", plotly_data),
  layout=("chart_layout", plotly_layout),
  **plotly_options,
)

类型

属性

data, layout, display_mode_bar, scroll_zoom, editable, static_plot, to_image_options, mode_bar_buttons_to_remove, mode_bar_buttons_to_add, locale, display_logo, responsive, double_click_delay

事件

after_export, after_plot, animated, animating_frame, animation_interrupted, auto_size, before_export, button_clicked, click, click_annotation, deselect, double_click, framework, hover, legend_click, legend_double_click, relayout, restyle, redraw, selected, selecting, slider_change, slider_end, slider_start, transitioning, transition_interrupted, unhover

许可

trame-plotly 在 MIT 许可下提供。有关更多详细信息,请参阅许可证。选择此许可证是为了与Plotlyvue-plotly使用的许可证相匹配,这些许可证对于使该库成为可能至关重要。

社区

Trame | 讨论 | 问题 | 路线图 | 联系我们

https://zenodo.org/badge/410108340.svg

喜欢 trame 吗?

通过推荐信品牌认可分享您的体验。

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

trame-plotly-3.0.2.tar.gz (3.1 MB 查看哈希值)

上传时间 源代码

构建分发

trame_plotly-3.0.2-py3-none-any.whl (3.1 MB 查看哈希值)

上传时间 Python 3

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面