我不能用iplot进行绘图

2024-04-25 14:27:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我不熟悉plotly,这是我在kaggle上写的代码:

import chart_studio.plotly as py
import plotly.graph_objects as go

df = timesData.iloc[:100,:]

traceC = go.Scatter(
    x = df.world_rank,
    y = df.citations,
    mode = "lines",
    name = "citations", 
    marker = dict(color = "rgba(160, 151, 216, 1)"),
    text = df.university_name
)

traceT = go.Scatter(
    x = df.world_rank,
    y = df.teaching,
    mode = "lines+markers",
    name = "teaching", 
    marker = dict(color = "rgba(5, 181, 194, 1)"),
    text = df.university_name
)

data = [traceC, traceT]

layout = dict(title = "Citation and Teaching vs World Rank of Top 100 Universities",
              xaxis = dict(title = "World Rank", ticklen = 5, zeroline = False))
fig = dict(data = data, layout = layout)
iplot(fig)

这就是我得到的错误:

PlotlyRequestError: Authentication credentials were not provided.

我还将plotly.plotly更改为chart_studio.plotly,因为我在那里遇到了另一个错误

我能做什么


Tags: nameimportgodfworlddataaschart
1条回答
网友
1楼 · 发布于 2024-04-25 14:27:58

如果这样做有效,您是否介意尝试一下:

import pandas as pd
import plotly.graph_objs as go
df = timesData.iloc[:100,:]

traceC = go.Scatter(
    x = df.world_rank,
    y = df.citations,
    mode = "lines",
    name = "citations", 
    marker = dict(color = "rgba(160, 151, 216, 1)"),
    text = df.university_name
)

traceT = go.Scatter(
    x = df.world_rank,
    y = df.teaching,
    mode = "lines+markers",
    name = "teaching", 
    marker = dict(color = "rgba(5, 181, 194, 1)"),
    text = df.university_name
)

data = [traceC, traceT]


layout = dict(title = "Citation and Teaching vs World Rank of Top 100 Universities",
              xaxis = dict(title = "World Rank", ticklen = 5, zeroline = False))

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

fig.show()

相关问题 更多 >