不幸的是,我每次使用Jupitter Notebook在Python中使用Plotly在Jupyter Notebook中创建了一些绘图,不幸的是,每次我打开Jupyter Notebook时都必须重新加载数据才能在Plotly中查看这些绘图,这是为什么发生的,如果我能以某种方式使绘图生成每次我运行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建议运行“重新启动并清除输出”菜单命令,或者在任何不同步的情况下随时在任何单元格中执行此块以恢复数字: