简体   繁体   English

散点图上的散点图

[英]Scatter Plot on Plotly Map

I am trying to show a scatter plot on a plotly world map. 我试图在散布的世界地图上显示散布图。 The code runs in a jupyter notebook. 该代码在jupyter笔记本中运行。

Here is the code 这是代码

mpis = []
colors = ["rgb(0,116,217)","rgb(255,65,54)","rgb(133,20,75)","rgb(255,133,27)","lightgrey"]
for i in range(len(mpi)):
    mpis.append(
        dict(
        type = 'scattergeo',
        #locationmode = 'world',
        lon = mpi['lon'][i],
        lat = mpi['lat'][i],
        text = str(mpi['MPI'][i]),
        marker = dict(
            size = 10,# mpi['MPI'][i]*100,
            color = colors[i%len(colors)],
            line = dict(width=0.5, color='rgb(40,40,40)'),
            sizemode = 'area'
        ),)

    )

layout = go.Layout(
    title = 'MPI',
    geo = dict(
            scope='world',
            #projection=dict( type = 'Mercator'),
            showland = True,
            landcolor = 'rgb(217, 217, 217)',
            subunitwidth=1,
            countrywidth=1,
            subunitcolor="rgb(255, 255, 255)",
            countrycolor="rgb(255, 255, 255)"
        ),)

fig = dict( data=mpis, layout=layout ) #fig =  go.Figure(layout=layout, data=mpis)
iplot( fig, validate=False)

This is an example of object in the data 这是数据中对象的示例

{'lat': 36.734772499999998,
  'lon': 70.811995299999978,
  'marker': {'color': 'rgb(0,116,217)',
   'line': {'color': 'rgb(40,40,40)', 'width': 0.5},
   'size': 10,
   'sizemode': 'area'},
  'text': '',
  'type': 'scattergeo'},

but the result is the map is shown without any shape drawn. 但结果是显示的地图没有绘制任何形状。

Mercator should be 'mercator' Mercator应该是“墨卡托”

Lattitude and longtitude must be lists: 纬度和经度必须列出:

'lat': ['36.734772499999998'],
'lon': ['70.811995299999978'],

Here is working example: 这是工作示例:

import plotly.plotly as py
import plotly.graph_objs as go
from plotly import tools
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode()


mpis = [{'lat': ['36.7347725'],
  'lon': ['70.8119953'],
  'marker': {'color': 'rgb(0,116,217)',
   'line': {'color': 'rgb(40,40,40)', 'width': 0.5},
   'size': 38.700000000000003,
   'sizemode': 'diameter'},
  'text': '0.387',
  'type': 'scattergeo'},
]


layout = go.Layout(
    title = 'MPI',
    showlegend = True,
    geo = dict(
            scope='world',
            projection=dict( type = 'natural earth'),
            showland = True,
            landcolor = 'rgb(217, 217, 217)',
            subunitwidth=1,
            countrywidth=1,
            subunitcolor="rgb(255, 255, 255)",
            countrycolor="rgb(255, 255, 255)"
        ),)

fig =  go.Figure(layout=layout, data=mpis)
iplot( fig, validate=False)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM