Hello I am working through a Python Crash Course book and one of the tasks is to build a simple map of earthquake locations using plotly. The goal is to have the program open an HTML on my Safari browser that displays a map of where the earthquakes have taken place. However, when I try to run the code I receive the error:
TypeError: invalid Figure property: Layout Layout Bad property path: Layout ^^^^^^
No HTML or pop up occurs in the browser.
The code I am running:
`import json
from plotly.graph_objs import Scattergeo, Layout
from plotly import offline
#explore the sturcture of the data
filename = 'eq_data_1_day_m1.json'
with open(filename) as f:
all_eq_data = json.load(f)
readable_file = 'new_readable_eq_data.json'
with open(readable_file, 'w') as f:
json.dump(all_eq_data, f, indent=4)
all_eq_dicts = all_eq_data['features']
print(len(all_eq_dicts))
mags, lons, lats = [], [], []
for eq_dict in all_eq_dicts:
mag = eq_dict['properties']['mag']
lon = eq_dict['geometry']['coordinates'][0]
lat = eq_dict['geometry']['coordinates'][1]
mags.append(mag)
lons.append(lon)
lats.append(lat)
#map the earthquakes
data = [Scattergeo(lon=lons, lat=lats)]
my_layout = Layout(title='Global Earthquakes')
fig = {'data': data, 'Layout': my_layout}
offline.plot(fig, filename='global_earthquakes.html')
`
I have tried to rewrite the code and copy it over and over again from the book but it won't run. Plotly is up to date. I have been able to extract data from the 'new_readable_eq_data.json' file so I do not think that is the problem. The error is specifically found on the last line of code:
offline.plot(fig, filename='global_earthquakes.html')
What are some ways to get around this problem? Thanks.