《朱庇特笔记本》中正在消失的普洛特利情节? [英] Disappearing Plotly plots in Jupyter Notebook?

查看:23
本文介绍了《朱庇特笔记本》中正在消失的普洛特利情节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jupyter Notebook中使用Ploly在Python中创建了一些曲线图,不幸的是,每次我打开Jupyter Notebook时都必须重新加载数据才能在Ploly中看到这些曲线图,为什么会发生这种情况,如果我可以在每次运行Jupyter Notebook时以某种方式使曲线图自动生成? 请给我一些建议,这对我来说真的是个大问题。

例如,当我打开Jupyter Notebook时,我必须重新加载数据集才能在Jupyter Notebook中再次显示它:

#Size of the plot
figsize=(10,5)

#Count of values of good and bad credits in the dataset
goodCount = data[data["Risk"]== 'good']["Risk"].value_counts().values
badCount = data[data["Risk"]== 'bad']["Risk"].value_counts().values

#Bar fo good credit
trace0 = go.Bar(x = data[data["Risk"]== 'good']["Risk"].value_counts().index.values,
               y = data[data["Risk"]== 'good']["Risk"].value_counts().values,
               name='Good credit',
               text= goodCount, 
               textposition="auto", 
               marker = dict(color = "green", line=dict(color="black", width=1),),opacity=1)

#Bar of bad credit
trace1 = go.Bar(x = data[data["Risk"]== 'bad']["Risk"].value_counts().index.values,
               y = data[data["Risk"]== 'bad']["Risk"].value_counts().values,
               name='Bad credit', 
               text= badCount, 
               textposition="auto", 
               marker = dict(color = "red", line=dict(color="black", width=1),),opacity=1)

#Creation of bar plot 
data = [trace0, trace1]
layout = go.Layout()
layout = go.Layout(yaxis=dict(title='Count'),
                   xaxis=dict(title='Risk variable'),
                   title='Distribution of target variable in the dataset')


fig = go.Figure(data=data, layout=layout)
fig.show()

推荐答案

troubleshooting guide建议运行"重新启动并清除输出"菜单命令,或在任何单元格中随时执行此块,以便在情况不同步时恢复图形:

import plotly.io as pio
pio.renderers.default='notebook'

您看到的是Ploly Notebook集成的一个限制,如果您可以升级到它,在JupyterLab中会更好:)

这篇关于《朱庇特笔记本》中正在消失的普洛特利情节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆