Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kaggle上带有Python的贴图:未显示贴图_Python_Maps_Analytics_Data Analysis_Geo - Fatal编程技术网

Kaggle上带有Python的贴图:未显示贴图

Kaggle上带有Python的贴图:未显示贴图,python,maps,analytics,data-analysis,geo,Python,Maps,Analytics,Data Analysis,Geo,问题更新-请参见下面的编辑部分 我正在做一件事 我想在内核中添加一些地图,以便使用plotly显示世界各地金牌得主的分布情况 我使用了以下不显示输出的代码,您能帮忙吗 import plotly.graph_objs as go from plotly.offline import init_notebook_mode,iplot init_notebook_mode(connected=True) data = dict(type = 'choropleth', l

问题更新-请参见下面的编辑部分

我正在做一件事

我想在内核中添加一些地图,以便使用plotly显示世界各地金牌得主的分布情况

我使用了以下不显示输出的代码,您能帮忙吗

import plotly.graph_objs as go 
from plotly.offline import init_notebook_mode,iplot
init_notebook_mode(connected=True)

data = dict(type = 'choropleth',
            locations = goldMedals['region'],
            locationmode = 'country names',
            colorscale = 'Viridis',
            reversescale = True,
            text= goldMedals['region'],
            z = goldMedals['region'],
            colorbar = {'title':'gold medals'})

layout = dict(title = 'gold medals',
                geo = dict(showframe = False,projection = {'type':'Mercator'})
             )
如果您需要查看所有可以查看的数据

编辑1:由于收到了第一个答案,我添加了以下代码来显示地图,但我收到了一个valueError

fig = dict(data=data, layout=layout)
iplot(fig)
错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-62ab92846e12> in <module>()
      1 fig = dict(data=data, layout=layout)
----> 2 iplot(fig)

/opt/conda/lib/python3.6/site-packages/plotly/offline/offline.py in iplot(figure_or_data, show_link, link_text, validate, image, filename, image_width, image_height, config)
    334     config.setdefault('linkText', link_text)
    335 
--> 336     figure = tools.return_figure_from_figure_or_data(figure_or_data, validate)
    337 
    338     # Though it can add quite a bit to the display-bundle size, we include

/opt/conda/lib/python3.6/site-packages/plotly/tools.py in return_figure_from_figure_or_data(figure_or_data, validate_figure)
   1473 
   1474         try:
-> 1475             figure = Figure(**figure).to_dict()
   1476         except exceptions.PlotlyError as err:
   1477             raise exceptions.PlotlyError("Invalid 'figure_or_data' argument. "

/opt/conda/lib/python3.6/site-packages/plotly/graph_objs/_figure.py in __init__(self, data, layout, frames)
    312                         respective traces in the data attribute
    313         """
--> 314         super(Figure, self).__init__(data, layout, frames)
    315 
    316     def add_area(

/opt/conda/lib/python3.6/site-packages/plotly/basedatatypes.py in __init__(self, data, layout_plotly, frames)
    114 
    115         # ### Import traces ###
--> 116         data = self._data_validator.validate_coerce(data)
    117 
    118         # ### Save tuple of trace objects ###

/opt/conda/lib/python3.6/site-packages/_plotly_utils/basevalidators.py in validate_coerce(self, v)
   1977 
   1978         else:
-> 1979             self.raise_invalid_val(v)
   1980 
   1981         return v

/opt/conda/lib/python3.6/site-packages/_plotly_utils/basevalidators.py in raise_invalid_val(self, v)
    214             typ=type_str(v),
    215             v=repr(v),
--> 216             valid_clr_desc=self.description()))
    217 
    218     def raise_invalid_elements(self, invalid_els):

ValueError: 
    Invalid value of type 'builtins.dict' received for the 'data' property of 
        Received value: {'type': 'choropleth', 'locations': 3             Denmark
42            Finland
44            Finland
48            Finland
60             Norway
73             Norway
76             Norway
78             Norway
79             Norway
113            Norway
117            Norway
150            France
172           Belarus
173            France
174            France
178          Cameroon
182             Spain
188             Spain
200            France
218             Italy
219             Italy
220             Italy
221             Italy
222             Italy
226             Italy
227             Italy
283               USA
524          Pakistan
550            Russia
587        Uzbekistan
             ...     
270411          Italy
270416          Italy
270431          China
270432          China
270433          China
270434          China
270435          China
270439          China
270440          China
270477         Serbia
270480         Russia
270514        Croatia
270552        Hungary
270588         Russia
270609         Russia
270610         Russia
270641         Russia
270676          Italy
270770        Germany
270773         Russia
270876    Switzerland
270896        Germany
270917    Switzerland
270934         Russia
270970        Belarus
270981        Georgia
271009        Germany
271016    Netherlands
271049    Netherlands
271076         Russia
Name: region, Length: 13224, dtype: object, 'locationmode': 'country names', 'colorscale': 'Viridis', 'reversescale': True, 'text': 3             Denmark
42            Finland
44            Finland
48            Finland
60             Norway
73             Norway
76             Norway
78             Norway
79             Norway
113            Norway
117            Norway
150            France
172           Belarus
173            France
174            France
178          Cameroon
182             Spain
188             Spain
200            France
218             Italy
219             Italy
220             Italy
221             Italy
222             Italy
226             Italy
227             Italy
283               USA
524          Pakistan
550            Russia
587        Uzbekistan
             ...     
270411          Italy
270416          Italy
270431          China
270432          China
270433          China
270434          China
270435          China
270439          China
270440          China
270477         Serbia
270480         Russia
270514        Croatia
270552        Hungary
270588         Russia
270609         Russia
270610         Russia
270641         Russia
270676          Italy
270770        Germany
270773         Russia
270876    Switzerland
270896        Germany
270917    Switzerland
270934         Russia
270970        Belarus
270981        Georgia
271009        Germany
271016    Netherlands
271049    Netherlands
271076         Russia
Name: region, Length: 13224, dtype: object, 'z': 3             Denmark
42            Finland
44            Finland
48            Finland
60             Norway
73             Norway
76             Norway
78             Norway
79             Norway
113            Norway
117            Norway
150            France
172           Belarus
173            France
174            France
178          Cameroon
182             Spain
188             Spain
200            France
218             Italy
219             Italy
220             Italy
221             Italy
222             Italy
226             Italy
227             Italy
283               USA
524          Pakistan
550            Russia
587        Uzbekistan
             ...     
270411          Italy
270416          Italy
270431          China
270432          China
270433          China
270434          China
270435          China
270439          China
270440          China
270477         Serbia
270480         Russia
270514        Croatia
270552        Hungary
270588         Russia
270609         Russia
270610         Russia
270641         Russia
270676          Italy
270770        Germany
270773         Russia
270876    Switzerland
270896        Germany
270917    Switzerland
270934         Russia
270970        Belarus
270981        Georgia
271009        Germany
271016    Netherlands
271049    Netherlands
271076         Russia
Name: region, Length: 13224, dtype: object, 'colorbar': {'title': 'gold medals'}}

    The 'data' property is a tuple of trace instances
    that may be specified as:
      - A list or tuple of trace instances
        (e.g. [Scatter(...), Bar(...)])
      - A list or tuple of dicts of string/value properties where:
        - The 'type' property specifies the trace type
            One of: ['area', 'bar', 'box', 'candlestick', 'carpet',
                     'choropleth', 'cone', 'contour',
                     'contourcarpet', 'heatmap', 'heatmapgl',
                     'histogram', 'histogram2d',
                     'histogram2dcontour', 'mesh3d', 'ohlc',
                     'parcoords', 'pie', 'pointcloud', 'sankey',
                     'scatter', 'scatter3d', 'scattercarpet',
                     'scattergeo', 'scattergl', 'scattermapbox',
                     'scatterpolar', 'scatterpolargl',
                     'scatterternary', 'splom', 'streamtube',
                     'surface', 'table', 'violin']

        - All remaining properties are passed to the constructor of
          the specified trace type

        (e.g. [{'type': 'scatter', ...}, {'type': 'bar, ...}])
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在()
1图=dict(数据=数据,布局=布局)
---->2 iplot(图)
/iplot中的opt/conda/lib/python3.6/site-packages/plotly/offline/offline.py(图或图数据、显示链接、链接文本、验证、图像、文件名、图像宽度、图像高度、配置)
334 config.setdefault('linkText',link_text)
335
-->336 figure=工具。从图或数据返回图(图或数据,验证)
337
338#虽然它可以大大增加显示包的大小,但我们包括
/opt/conda/lib/python3.6/site-packages/plotly/tools.py从图或图数据返回图(图或图数据,验证图)
1473
1474尝试:
->1475图=图(**图)。to_dict()
1476例外情况除外。PlotlyError作为错误:
1477引发异常。PlotlyError(“无效的'figure_或_data'参数。”
/opt/conda/lib/python3.6/site-packages/plotly/graph\u objs//u figure.py in\uuuuuuuuu init\uuuuuuuu(self、数据、布局、框架)
312数据属性中的各个记录道
313         """
-->314超级(图,自).\uuuu初始(数据,布局,帧)
315
316 def添加区域(
/opt/conda/lib/python3.6/site-packages/plotly/basedatatypes.py in_u_______________________________
114
115#####导入跟踪###
-->116 data=self.\u data\u validator.validate\u强制(数据)
117
118#####保存跟踪对象的元组###
/验证强制(self,v)中的opt/conda/lib/python3.6/site-packages//\u plotly\u utils/basevalidators.py
1977
1978年其他:
->1979年自我提升无效价值(v)
1980
1981年返回v
/opt/conda/lib/python3.6/site-packages//\u plotly\u utils/basevalidators.py in raise\u invalid\u val(self,v)
214类型=类型_str(v),
215 v=repr(v),
-->216有效\u clr\u desc=self.description())
217
218 def raise_无效元素(自身、无效元素):
值错误:
为的“data”属性接收到类型为“builtins.dict”的无效值
收到的值:{'type':'choropleth','locations':3
42芬兰
44芬兰
48芬兰
60挪威
73挪威
76挪威
78挪威
79挪威
113挪威
117挪威
150法国
172白俄罗斯
173法国
174法国
178喀麦隆
182西班牙
188西班牙
200法国
218意大利
219意大利
220意大利
221意大利
222意大利
226意大利
227意大利
283美国
524巴基斯坦
550俄罗斯
587乌兹别克斯坦
...     
270411意大利
270416意大利
270431中国
270432中国
270433中国
270434中国
270435中国
270439中国
270440中国
270477塞尔维亚
270480俄罗斯
270514克罗地亚
270552匈牙利
270588俄罗斯
270609俄罗斯
270610俄罗斯
270641俄罗斯
270676意大利
270770德国
270773俄罗斯
270876瑞士
270896德国
270917瑞士
270934俄罗斯
270970白俄罗斯
270981格鲁吉亚
271009德国
271016荷兰
271049荷兰
271076俄罗斯
名称:区域,长度:13224,数据类型:对象,'locationmode':'country names','colorscale':'Viridis','reversescale':True,'text':3丹麦
42芬兰
44芬兰
48芬兰
60挪威
73挪威
76挪威
78挪威
79挪威
113挪威
117挪威
150法国
172白俄罗斯
173法国
174法国
178喀麦隆
182西班牙
188西班牙
200法国
218意大利
219意大利
220意大利
221意大利
222意大利
226意大利
227意大利
283美国
524巴基斯坦
550俄罗斯
587乌兹别克斯坦
...     
270411意大利
270416意大利
270431中国
270432中国
270433中国
270434中国
270435中国
270439中国
270440中国
270477塞尔维亚
270480俄罗斯
270514克罗地亚
270552匈牙利
270588俄罗斯
270609俄罗斯
270610俄罗斯
270641俄罗斯
270676意大利
270770德国
270773俄罗斯
270876瑞士
270896德国
270917瑞士
270934俄罗斯
270970白俄罗斯
270981格鲁吉亚
271009德国
271016荷兰
271049荷兰
271076俄罗斯
名称:区域,长度:13224,数据类型:对象,“z”:3
42芬兰
44芬兰
48芬兰
60挪威
73挪威
76挪威
78挪威
79挪威
113挪威
117挪威
150法国
172白俄罗斯
17
fig = dict(data=data, layout=layout)
iplot(fig)