Hi, I´m trying to run the following plotly sample code from “Bubble maps in Python”. The code follows:
´´´
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv(‘https://raw.githubusercontent.com/plotly/datasets/master/2014_us_cities.csv’)
df.head()
df[‘text’] = df[‘name’] + ‘
Population ’ + (df[‘pop’]/1e6).astype(str)+’ million’
limits = [(0,3),(3,11),(11,21),(21,50),(50,3000)]
colors = [“royalblue”,“crimson”,“lightseagreen”,“orange”,“lightgrey”]
cities =
scale = 5000
fig = go.Figure()
for i in range(len(limits)):
lim = limits[i]
df_sub = df[lim[0]:lim[1]]
fig.add_trace(go.Scattergeo(
locationmode = ‘USA-states’,
lon = df_sub[‘lon’],
lat = df_sub[‘lat’],
text = df_sub[‘text’],
marker = dict(
size = df_sub[‘pop’]/scale,
color = colors[i],
line_color=‘rgb(40,40,40)’,
line_width=0.5,
sizemode = ‘area’
),
name = ‘{0} - {1}’.format(lim[0],lim[1])))
fig.update_layout(
title_text = ‘2014 US city populations
(Click legend to toggle traces)’,
showlegend = True,
geo = dict(
scope = ‘usa’,
landcolor = ‘rgb(217, 217, 217)’,
)
)
fig.show()
´´´
The code was copied in VisualStudioCode and run in Python 3.9.9 (Mac). After it´s run follows the following message:
´´´
Proyectos Python 3.9.9/plotly.py"
Traceback (most recent call last):
File “/Users/alejandroureta/Documents/Proyectos Python 3.9.9/plotly.py”, line 1, in
import plotly.graph_objects as go
File “/Users/alejandroureta/Documents/Proyectos Python 3.9.9/plotly.py”, line 1, in
import plotly.graph_objects as go
ModuleNotFoundError: No module named ‘plotly.graph_objects’; ‘plotly’ is not a package
´´´
Running a “pip3 list” command, I can see plotly version 5.24.1 is installed in the corresponding project virtual environment. I would appreciate help with this problem.
Thank you, Alejandro.