密密麻麻地显示在朱皮特记事本上

2024-04-27 07:38:16 发布

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

我有一个数据框'国家',我正在使用jupyter笔记本绘制。在

它在Kaggle的笔记本上画得很好,但当我使用jupyter笔记本时却不显示出来。。在

我在StackOverflow上读过类似的问题,我尝试过这两种方法:

init_notebook_mode(connected=True)

&

^{pr2}$

请查看以下完整代码:

import plotly.offline as py
from plotly.offline import iplot
py.offline.init_notebook_mode(connected=True)
import plotly.graph_objs as go

trace1 = go.Bar(
    x= country.index,
    y= country['Avg. Points'],
    name='Avg. Points'
)

trace2= go.Bar(
    x= country.index,
    y= country['Avg. Price'],
    name='Avg. Price'
)

data=[trace1, trace2]
layout=go.Layout(
    barmode='stack')

fig=go.Figure(data=data, layout=layout)
py.iplot(fig, filename='stacked-bar')

下图是它在Kaggle上的样子。enter image description here


Tags: pyimportgodatainitmode笔记本jupyter
1条回答
网友
1楼 · 发布于 2024-04-27 07:38:16

我尝试使用您的代码,用Plotly的example数据替换数据。我无法复制你的问题。假设您已经使用$ pip install plotly正确地安装了绘图,并且数据没有问题,下面的方法应该可以工作。在

from plotly.offline import iplot不是必需的,因为您使用py.iplot。在

import plotly.offline as py
import plotly.graph_objs as go

py.init_notebook_mode(connected=True)

trace1 = go.Bar(
    x= country.index,
    y= country['Avg. Points'],
    name='Avg. Points'
)

trace2= go.Bar(
    x= country.index,
    y= country['Avg. Price'],
    name='Avg. Price'
)

data=[trace1, trace2]
layout=go.Layout(barmode='stack')

fig=go.Figure(data=data, layout=layout)
py.iplot(fig, filename='stacked-bar')

相关问题 更多 >