Hi,
- Im trying to adjust the marker size and color as per population.
- 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 ?