Ploly-Name'iPlot'未定义

2022-03-02 00:00:00 python plotly data-visualization

问题描述

我一直在尝试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。

相关文章