0
我想顯示分配給每個標記的顏色的圖例。當我設置showlegend = True
時,它只顯示一種顏色,而且也顯示錯誤的標籤。我從他們的一個例子中最後添加了輸出。在Plotly中顯示圖例Python
代碼
cities = [dict(
type = 'scattergeo',
locationmode = 'country names',
lon = df['lng'].apply(lambda x: float(x)),
lat = df['lat'].apply(lambda x: float(x)),
text = df['name_of_city'],
marker = dict(
size = df['total_graduates'].apply(lambda x: float(x))/2000,
color = df['effective_literacy_rate_total'],
colorscale='Portland',
line = dict(width=0.5, color='rgb(40,40,40)'),
sizemode = 'area'
)
)]
layout = dict(
title = 'Top 500 Indian Cities by Population',
showlegend = True,
autosize=False,
width=800,
height=1000,
geo = dict(
resolution=100,
scope='asia',
lonaxis = dict(range= [ 65.0 ,100.0]),
lataxis = dict(range= [ 0.0,40.0 ]),
projection=dict(type = 'Mercator'),
showland = True,
landcolor = 'rgb(50,50,50)',
subunitwidth=1,
countrywidth=1,
subunitcolor="rgb(255, 255, 255)",
countrycolor="rgb(255, 255, 255)"
),
)
fig = dict(data=cities, layout=layout)
iplot(fig, validate=False, filename='top-500-indian-cities')
感謝,加入** showscale =真**又解決了我的問題,謝謝你的努力:) – Arijit