[英]Seaborn heatmap to plotly failed
I'm having plotly error when converting seaborn.heatmap figure to plotly. 将seaborn.heatmap图转换为plotly时出现plotly错误。 I'm doing that in jupyter notebook with following code: 我正在使用以下代码在jupyter笔记本中执行此操作:
%matplotlib inline
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from plotly.offline import init_notebook_mode, iplot_mpl
init_notebook_mode(connected=True)
np.random.seed(2017)
data = np.random.randn(10, 20)
When I'm plotting it as static seaborn heatmap everything is alright: 当我将其绘制为静态海洋热图时,一切都很好:
sns.heatmap(data)
But when I'm trying to convert that object to plotly I have an error: 但是,当我尝试将该对象转换为任意位置时,出现错误:
sns.heatmap(data)
fig = plt.gcf()
iplot_mpl(fig)
Error Traceback: 错误回溯:
/opt/cloudera/parcels/Anaconda/envs/py35/lib/python3.5/site-packages/plotly/matplotlylib/renderer.py:445: UserWarning:
Dang! That path collection is out of this world. I totally don't know what to do with it yet! Plotly can only import path collections linked to 'data' coordinates
---------------------------------------------------------------------------
PlotlyEmptyDataError Traceback (most recent call last)
<ipython-input-3-2a07e9adfc34> in <module>()
1 sns.heatmap(data)
2 fig = plt.gcf()
----> 3 iplot_mpl(fig)
/opt/cloudera/parcels/Anaconda/envs/py35/lib/python3.5/site-packages/plotly/offline/offline.py in iplot_mpl(mpl_fig, resize, strip_style, verbose, show_link, link_text, validate, image, image_filename, image_height, image_width)
681 return iplot(plotly_plot, show_link, link_text, validate,
682 image=image, filename=image_filename,
--> 683 image_height=image_height, image_width=image_width)
684
685
/opt/cloudera/parcels/Anaconda/envs/py35/lib/python3.5/site-packages/plotly/offline/offline.py in iplot(figure_or_data, show_link, link_text, validate, image, filename, image_width, image_height, config)
330 config.setdefault('linkText', link_text)
331
--> 332 figure = tools.return_figure_from_figure_or_data(figure_or_data, validate)
333
334 # Though it can add quite a bit to the display-bundle size, we include
/opt/cloudera/parcels/Anaconda/envs/py35/lib/python3.5/site-packages/plotly/tools.py in return_figure_from_figure_or_data(figure_or_data, validate_figure)
1396 if not figure['data']:
1397 raise exceptions.PlotlyEmptyDataError(
-> 1398 "Empty data list found. Make sure that you populated the "
1399 "list of data objects you're sending and try again.\n"
1400 "Questions? Visit support.plot.ly"
PlotlyEmptyDataError: Empty data list found. Make sure that you populated the list of data objects you're sending and try again.
Questions? Visit support.plot.ly
According to this example , you would need to first convert your matplotlib
figure to a Plotly
object and then add the data
manually. 根据此示例 ,您首先需要将matplotlib
图形转换为Plotly
对象,然后手动添加data
。 Whether that's more convenient than doing everything with Plotly
from the beginning is a different issue. 从一开始这是否比使用Plotly
进行所有操作更方便,这是另一个问题。
%matplotlib inline
import plotly
import matplotlib as plt
import numpy as np
import seaborn as sns
plotly.offline.init_notebook_mode()
np.random.seed(2017)
data = np.random.randn(10, 20)
sns.heatmap(data)
mpl_fig = plt.pyplot.gcf()
plotly_fig = plotly.tools.mpl_to_plotly(mpl_fig)
plotly_fig['data'] = [dict(z=data, type="heatmap")]
plotly.offline.iplot(plotly_fig)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.