Ploly-Name'iPlot'未定义 [英] Plotly - name 'iplot' is not defined

查看:57
本文介绍了Ploly-Name'iPlot'未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试Ploly for Python,但是经常遇到上面提到的相同的错误消息。我在蟒蛇上密谋安装,分别在Jupyter和Spyder上得到错误信息:

#data manipulation
import pandas as pd
import numpy as np

#loading csv
df = df = pd.read_csv(r'C:UsershendevDesktopFIFA18 - 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只有在v3.10.0plotly.plotly模块deprecated已被绘制v4.0之前,$ from plotly.plotly import iplot才有效。请先检查您的版本:

$ 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

这篇关于Ploly-Name'iPlot'未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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