gpt4 book ai didi

python - Jupyter Notebook 中未显示 Plotly 图表

转载 作者:太空狗 更新时间:2023-10-29 22:12:13 36 4
gpt4 key购买 nike

几个小时以来,我一直在努力解决这个问题。我按照 Plotly website 上的步骤操作图表仍然没有显示在笔记本中。

这是我的 plotly 代码:

colorway = ['#f3cec9', '#e7a4b6', '#cd7eaf', '#a262a9', '#6f4d96', '#3d3b72', '#182844']

data = [
go.Scatter(
x = immigration.columns,
y = immigration.loc[state],
name=state) for state in immigration.index]

layout = go.Layout(
title='Immigration',
yaxis=dict(title='Immigration %'),
xaxis=dict(title='Years'),
colorway=colorway,
font=dict(family='Courier New, monospace', size=18, color='#7f7f7f')
)

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

这是我导入笔记本的所有内容:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot

init_notebook_mode(connected=True)

最佳答案

如果您想在离线模式下工作,您需要更改 init_notebook_mode 调用并删除 connected=True

这样:

# Import the necessaries libraries
import plotly.offline as pyo
import plotly.graph_objs as go
# Set notebook mode to work in offline
pyo.init_notebook_mode()
# Create traces
trace0 = go.Scatter(
x=[1, 2, 3, 4],
y=[10, 15, 13, 17]
)
trace1 = go.Scatter(
x=[1, 2, 3, 4],
y=[16, 5, 11, 9]
)
# Fill out data with our traces
data = [trace0, trace1]
# Plot it and save as basic-line.html
pyo.iplot(data, filename = 'basic-line')

输出应显示在您的 jupyter notebook 中:

My example

关于python - Jupyter Notebook 中未显示 Plotly 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52771328/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com