gpt4 book ai didi

python - Plotly - 名称 'iplot' 未定义

转载 作者:行者123 更新时间:2023-12-01 08:57:03 34 4
gpt4 key购买 nike

一直在使用Python的plotly,但不断遇到上述相同的错误消息。我在 Anaconda 上安装了plotly,分别在 Jupyter 和 Spyder 上收到错误消息:

#data manipulation
import pandas as pd
import numpy as np

#loading csv
df = df = pd.read_csv(r'C:\Users\hendev\Desktop\FIFA18 - Ultimate Team players.csv')

import plotly.graph_objs as go

# prepare data
x2017 = df.overall[df.added_date == 2017]
x2018 = df.overall[df.added_date == 2018]

trace1 = go.Histogram(
x=x2017,
opacity=0.75,
name = "2017",
marker=dict(color='rgba(171, 50, 96, 0.6)'))
trace2 = go.Histogram(
x=x2018,
opacity=0.75,
name = "2018",
marker=dict(color='rgba(12, 50, 196, 0.6)'))

data = [trace1, trace2]
layout = go.Layout(barmode='overlay',
title=' Rating added in 2017 and 2018',
xaxis=dict(title='students-staff ratio'),
yaxis=dict( title='Count'),
)
fig = go.Figure(data=data, layout=layout)
iplot(fig)

知道我做错了什么吗?

最佳答案

注意: $ from plotly.plotly import iplot只会工作到plotly v3.10.0 plotly.plotly模块已deprecated阴谋v4.0 。首先检查您的版本:

$ python3 -c 'import plotly; print(plotly.__version__)' # for Python 3
$ python -c 'import plotly; print(plotly.__version__)' # for Python 2

v4.0从那时起,该功能已分为两种模式:在线离线

在线

如果您希望在线呈现数字,您现在需要导入 chart-studio并使用

from chart_studio.plotly import plot, iplot

离线

如果您想在本地渲染图像,您有多种选择:

from plotly.offline import iplot
# your code
iplot(fig)

from plotly.subplots import make_subplots
fig = make_subplots(# your args)
# your code
fig.show()

import plotly.io as pio
# your code
pio.show(fig)

import plotly.graph_objects as go
fig = go.Figure(# your args)
# your code
fig.show()

您可以阅读有关渲染器的更多信息 here .

关于python - Plotly - 名称 'iplot' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52727937/

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