Python 将地理图从matplotlib导入plotly
matplotlib给了我这个美丽的情节: 现在,我想将其导入plotly intyerative plotPython 将地理图从matplotlib导入plotly,python,matplotlib,plot,plotly,Python,Matplotlib,Plot,Plotly,matplotlib给了我这个美丽的情节: 现在,我想将其导入plotly intyerative plot import mpl_toolkits import mpl_toolkits.basemap # # specify the map boundaries and projection type # mymap = mpl_toolkits.basemap.Basemap(llcrnrlon= -120, llcrnrlat=22,
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()
我收到以下几个奇怪的错误:
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.
---------------------------------------------------------------------------
KeyError回溯(最近一次呼叫最后一次)
在()
---->1 py.iplot\u mpl(fig\u map,filename='DataScience/data visualization/geographic\u map\u plot\u 1')
/iplot\u mpl中的usr/local/lib/python2.7/dist-packages/plotly/plotly/plotly.pyc(图、调整大小、条带样式、更新、**打印选项)
257“object.Run‘help(plotly.graph_objs.Figure)’了解更多信息。”
258 )
-->259返回iplot(图,**绘图选项)
260
261
/iplot中的usr/local/lib/python2.7/dist-packages/plotly/plotly/plotly.pyc(图\或\数据,**绘图\选项)
113如果“自动打开”不在绘图选项中:
114绘图选项['auto_open']=False
-->115分辨率=绘图(图或数据,**绘图选项)
116 URLSPILT=res.split(“/”)
117用户名,plot_id=urlspit[-2][1:,urlspit[-1]#TODO:HACKY!
/绘图中的usr/local/lib/python2.7/dist-packages/plotly/plotly/plotly.pyc(图\或\数据,验证,**绘图\选项)
185“看到此错误:\n\n{0}”
186.“格式(错误))
-->187如果不是图[“数据”]:
188引发异常。PlotlyEmptyDataError(
189“找到空数据列表。请确保已填充”
KeyError:“数据”
我还没有在地理地图上看到plotly的任何示例!因此,非常感谢您的帮助!不幸的是,plotly还不支持基础地图转换 也就是说,有一个解决办法: 简而言之,您需要从basemap对象提取x-y坐标,将其附着到Plotly跟踪对象,然后调用
Plotly.Plotly.plot()
如果您对Plotly有任何其他问题,请随时与我联系。谢谢,参加聚会有点晚,您知道是否添加了此功能吗?
---------------------------------------------------------------------------
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'