无法在plotly/python的气泡图中看到气泡

2024-10-04 03:16:11 发布

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

我正在制作来自kaggle的拉面评级数据集

我想看到使用scatter_geoplotly开始的评论/国家数量的传播

我的代码:

country_count = df['Country'].value_counts()
import plotly.express as px
fig = px.scatter_geo(country_count, locations = country_count.index, size = country_count)
fig.show()

给我这个: plotly image

请帮忙


Tags: 数据代码df数量count评论figplotly
1条回答
网友
1楼 · 发布于 2024-10-04 03:16:11

由于scatter_geo函数的locatioinmode参数的默认设置,完整分散不可见。当位置为国家名称时,可以将其更改为country name。修改后的代码如下:

import pandas as pd
import numpy as np
import plotly.express as px
import pycountry

df = pd.read_csv('ramen-ratings.csv')
country_count = df['Country'].value_counts()
country_count = country_count.reset_index().rename(columns={'index':'Country', 'Country':'Count'})
fig = px.scatter_geo(country_count, locations='Country', locationmode='country names', size='Count')
fig.show()

获得的图表如下所示: enter image description here

完整的文档可在此处访问:https://plotly.com/python-api-reference/generated/plotly.express.scatter_geo.html

相关问题 更多 >