How can I customize the marker size, color, colorscale in plotly scattergeo?

Hi,

  1. Im trying to adjust the marker size and color as per population.
  2. Im trying to adjust the colorscale of cities from highest to lowest population.

here is the code:

 import csv

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

filename = 'data/russian-cities.csv'
with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)

    # for index, column_header in enumerate(header_row):
    #     print(index, column_header)

    lats, lons, populations, hover_texts = [], [], [], []
    for row in reader:
        lat = (row[1])
        lats.append(lat)
        lon = (row[2])
        lons.append(lon)
        city = (row[0])
        population = (row[7])
        populations.append(population)
        hover_texts.append(city + ", " + population)

print(populations)
populations.sort()

data = [{
    'type': 'scattergeo',
    'lon': lons,
    'lat': lats,
    'text': hover_texts,
    'marker': {
        'size': populations,
        'color': populations,
        'colorscale': 'Electric',
        'reversescale': True,
        'colorbar': {'title': 'Population'}
    },
}]

my_layout = Layout(title='Population of Russian Cities')
fig = {'data': data, 'layout': my_layout}
offline.plot(fig, filename='population_of_russian_cities.html')

Here is the result that Im receiving:

ValueError:
Invalid element(s) received for the 'color' property of scattergeo.marker
    Invalid elements include: ['', '', '', '', '', '', '', '', '', '']

The 'color' property is a color and may be specified as:
  - A hex string (e.g. '#ff0000')
  - An rgb/rgba string (e.g. 'rgb(255,0,0)')
  - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
  - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
  - A named CSS color:
        aliceblue, antiquewhite, aqua, aquamarine, azure,
        beige, bisque, black, blanchedalmond, blue,
        blueviolet, brown, burlywood, cadetblue,
        chartreuse, chocolate, coral, cornflowerblue,

The Problem is caused because of below piece of code here:

   'marker': {
        'size': populations,
        'color': populations,

Could you please help me to solve the issue ?

The first part of the error message tells you that you populations array has some non numerical values in it (empty strings) you can replace those with None or np.nan and that should make color work.
For size I believe you need to pass sizes in pixels so you’d need to transform populations to get that.

Thank you for your time and help Dear @RenaudLN . Much Appreciated.