如何使用Plotly在Databricks中渲染图表?

我正在尝试使用Databricks中的Plotly库渲染图表。但是,不会渲染任何图像。例如,我使用以下语句:

<table>
  <thead>
    <tr>
      <td align="left">
        :information_source: Information
      </td>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <ul>
          <li>Tis not true.</li>
          <li>I won't explode.</li>
        </ul>
      </td>
    </tr>
  </tbody>
</table>

没有输出。为什么?

ief111111 回答:如何使用Plotly在Databricks中渲染图表?

如果您使用plotly 4.2版,则不再需要import plotly.offline,而只需在使用Plotly Express或fig.show()创建的图形上调用go.Figure()。新的渲染器框架具有特定于Databricks的渲染器:)

此处提供完整文档:https://plot.ly/python/renderers/https://plot.ly/python/creating-and-updating-figures/

,

从查看the docs开始,您必须指定output_type='div'并将绘图对象传递给displayHTML()。这是Python笔记本或单元中的一个有效示例:

## Install & import plotly
!pip install plotly
from plotly.offline import plot
import plotly.graph_objs as go
import numpy as np

x = np.random.randn(2000)
y = np.random.randn(2000)

# Instead of simply calling plot(...),store your plot as a variable and pass it to displayHTML().
# Make sure to specify output_type='div' as a keyword argument.
# (Note that if you call displayHTML() multiple times in the same cell,only the last will take effect.)

p = plot(
  [
    go.Histogram2dContour(x=x,y=y,contours=dict(coloring='heatmap')),go.Scatter(x=x,mode='markers',marker=dict(color='white',size=3,opacity=0.3))
  ],output_type='div'
)

displayHTML(p)
本文链接:https://www.f2er.com/3141014.html

大家都在问