'ValueError: Invalid element(s) received for the 'size' property of scattergeo.marker

I've encountered an issue with plotly. I can't seem to find the error in the code and it won't allow my graph to show.

import json

from plotly.graph_objs import Scattergeo, Layout
from plotly import offline

""" Get json file """
filename = 'all_week.json'
with open(filename, encoding='utf-8') as f:
    all_week_data = json.load(f)

""" Create readable file """
readable_file = 'readable_all_week.json'
with open(readable_file, 'w') as f:
    json.dump(all_week_data, f, indent=4)

""" Get data from dictionary """
eq_week_dicts = all_week_data['features']

""" Create list and store mags, lons, lats, labels """
mags, lons, lats, labels = [], [], [], []
for eq_week_dict in eq_week_dicts:
    mags.append(eq_week_dict['properties']['mag'])
    lons.append(eq_week_dict['geometry']['coordinates'][0])
    lats.append(eq_week_dict['geometry']['coordinates'][1])
    labels.append(eq_week_dict['properties']['title'])

""" Create Map """
data = [{
    'type': 'scattergeo',
    'lon': lons,
    'lat': lats,
    'text': labels,

    # Create marks on map
    'marker': {
        'size': [5*mag for mag in mags],
        'color': mags,
        'colorscale': 'Viridis',
        'reverscale': True,
        'colorbar': {'title': 'Magnitude'}
    }
}]

""" Output data """
title = all_week_data['metadata']['title']
my_layout = Layout(title=title)

fig = {'data': data, 'layout': my_layout}
offline.plot(fig, filename='eqs.html')

Here is the error code I am receiving. I do not know how to fix it? Would a try clause work?

enter image description here



Solution 1:[1]

The traceback is pretty clear. size must be either an int/float in range 0-inf or a list/tuple of such int/float values. In your case you have negative ints/float values in the list

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris_Rands