首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将地理地块从matplotlib导入到plotly

将地理地块从matplotlib导入到plotly
EN

Stack Overflow用户
提问于 2014-11-28 23:58:21
回答 1查看 870关注 0票数 4
代码语言:javascript
复制
import mpl_toolkits
import mpl_toolkits.basemap

#
# specify the map boundaries and projection type
#
mymap = mpl_toolkits.basemap.Basemap(llcrnrlon= -120, llcrnrlat=22,
                                     urcrnrlon=-58, urcrnrlat=48,
                                     projection="tmerc", lon_0 = -95, lat_0 = 35,
                                     resolution = "l")
fig_map = plt.figure(6, figsize=(10, 8))

mymap.fillcontinents(color = "lightgray")
mymap.drawcoastlines(color = "gray", linewidth=1.2)
mymap.drawcountries(color = "gray", linewidth=2)
mymap.drawstates(color = "gray")

mymap.drawmapboundary()

plt.show()

matplotlib给了我这个漂亮的图:

现在,我想将这个导入到plot intyerative中

代码语言:javascript
复制
py.iplot_mpl(fig_map, filename='DataScience/data-visualization/geographic_map_plot_1')

/usr/local/lib/python2.7/dist-packages/plotly/matplotlylib/renderer.py:479: UserWarning:

I found a path object that I don't think is part of a bar chart. Ignoring.

我收到几个奇怪的错误,如下所示:

代码语言:javascript
复制
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-79-561cd71f8586> in <module>()
----> 1 py.iplot_mpl(fig_map, filename='DataScience/data-visualization/geographic_map_plot_1')

/usr/local/lib/python2.7/dist-packages/plotly/plotly/plotly.pyc in iplot_mpl(fig, resize, strip_style, update, **plot_options)
    257             "object. Run 'help(plotly.graph_objs.Figure)' for more info."
    258         )
--> 259     return iplot(fig, **plot_options)
    260 
    261 

/usr/local/lib/python2.7/dist-packages/plotly/plotly/plotly.pyc in iplot(figure_or_data, **plot_options)
    113     if 'auto_open' not in plot_options:
    114         plot_options['auto_open'] = False
--> 115     res = plot(figure_or_data, **plot_options)
    116     urlsplit = res.split('/')
    117     username, plot_id = urlsplit[-2][1:], urlsplit[-1]  # TODO: HACKY!

/usr/local/lib/python2.7/dist-packages/plotly/plotly/plotly.pyc in plot(figure_or_data, validate, **plot_options)
    185                                          "seeing this error:\n\n{0}"
    186                                          "".format(err))
--> 187         if not figure['data']:
    188             raise exceptions.PlotlyEmptyDataError(
    189                 "Empty data list found. Make sure that you populated the "

KeyError: 'data'

我还没有在地理地图上看到任何plotly的例子!所以,任何帮助都是非常感谢的!

EN

回答 1

Stack Overflow用户

发布于 2014-11-29 00:49:23

不幸的是,Plotly还不支持底图转换。

也就是说,有一个变通方法:

http://nbviewer.ipython.org/github/etpinard/plotly-misc-nbs/blob/etienne/plotly-maps.ipynb

简而言之,您需要从底图对象中提取x-y坐标,将它们附加到Plotly trace对象并调用plotly.plotly.plot()

如果您对Plotly有任何其他问题,请随时与我联系。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27192268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档