简体   繁体   English

密谋Ipython-display(HTML)函数未显示html文件

[英]Plotly Ipython - display(HTML) function is not displaying html file

I am creating images using plotly library and trying to display in HTML. 我正在使用plotly库创建图像并尝试以HTML显示。 I have format the images in HTML format. 我已将图像格式化为HTML格式。 But display(HTML(report_html)) code is not displaying HTML page. 但是display(HTML(report_html))代码未显示HTML页面。

I am using python 3.5 and pycharm IDE. 我正在使用python 3.5和pycharm IDE。 I am not using iPython notebook. 我没有使用iPython笔记本。

Source code: 源代码:

 from IPython.display import display, HTML, Image
 import plotly.plotly as py
 from plotly.offline import init_notebook_mode
 init_notebook_mode()

 data = go.scatter(x=df['date'], y=i, name = long_name['value'])
 figures = [data]
 images = [base64.b64encode(py.image.get(figure, width=width,height=height)).decode('utf-8') for figure in figures]

  report_html = ''
  for image in images:
      _ = template
      _ = _.format(image=image, caption='', width=width, height=height)
      report_html += _

  display(HTML(report_html))

I am not getting any error. 我没有任何错误。 I am just getting following output 我只是得到以下输出

IPython.core.display.HTML object IPython.core.display.HTML对象

Sorry for the late reply, The code works perfectly for me, let me share my sample,the basic difference is I used the figure object under plotly.graph_objs instead of figures = [data] 对不起,我的代码很适合我,让我分享我的示例,基本区别是我figure object under plotly.graph_objs使用了figure object under plotly.graph_objs而不是figures = [data]

Code: 码:

from IPython.display import display, HTML, Image
import plotly.plotly as py
import base64
import plotly.graph_objs as go
py.sign_in('<<username here>>', '<<api key here>>')

# required variables
width=500
height=300

# template not provided so created my own
template = """
<div class="row">
    <div class="col-xs-12" style="text-align:center">
        {caption}
    </div>
    <div class="col-xs-12">
        <img src="data:image/png;base64,  {image}" alt="Red dot"/>
    </div>
</div>
"""

# data = go.scatter(x=df['date'], y=i, name = long_name['value'])

# using my sample data instead
trace = go.Bar(x=[2, 4, 6], y= [10, 12, 15])

# layout can also be provided, I am giving as blank
layout = dict()

# figures = [data]
# changing the above commented line to plotly figure object
fig = go.Figure(data=[trace], layout=layout)

# defining list which will contain all the plot objects
figures = []
figures.append(fig)

images = [base64.b64encode(py.image.get(figure, width=width,height=height)).decode('utf-8') for figure in figures]

report_html = ''
for image in images:
    _ = template
    _ = _.format(image=image, caption='', width=width, height=height)
    report_html += _

display(HTML(report_html))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将保存为 html 文件的绘图图形导入并显示到 Jupyter Notebook 中 - Importing and displaying a plotly graph saved as an html file into Jupyter Notebook 在 GitHub 页面上显示交互式 plotly 图表(.html 文件) - Display interactive plotly chart (.html file) on GitHub Pages 如何将iPython HTML类发送到.html文件? - How to send iPython HTML class to a .html file? 当下载为 html 时,IPython 交互式小部件不会更新 - IPython interactive widget is not updating plotly when downloaded as html IPython.core.display.HTML to png - IPython.core.display.HTML to png 如何格式化IPandy html显示的Pandas数据帧? - How to format IPython html display of Pandas dataframe? 在RMarkdown html文档中显示python plotly图形 - Display python plotly graph in RMarkdown html document 如何显示<IPython.core.display.HTML object> ? - How to display <IPython.core.display.HTML object>? 如何保存一个<ipython.core.display.html> ? 我需要保存一个<pandas.dataframe.style>作为图像或 HTML 文件</pandas.dataframe.style></ipython.core.display.html> - How to save a <IPython.core.display.HTML> ? I need to save a <pandas.DataFrame.style> as a image or as a HTML file 将带有 plotly 的 Jupyter 笔记本导出到 html 离线时无法正确显示 - Exporting Jupyter notebook with plotly to html not displaying correctly when offline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM