4
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は私にこの美しいプロットを与えました:

ここに画像の説明を入力

今、私はこれをplotly intyerative plotにインポートしたい

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                                  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'

地理的な地図でのプロットの例を見たことがありません! だから、どんな助けも大歓迎です!

4

1 に答える 1

9

残念ながら、Plotly はベースマップの変換をまだサポートしていません。

とはいえ、回避策があります。

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

簡単に言うと、ベースマップ オブジェクトから xy 座標を抽出し、それらを Plotly トレース オブジェクトにアタッチして を呼び出す必要がありますplotly.plotly.plot()

Plotly について他にご不明な点がございましたら、お気軽にお問い合わせください。

于 2014-11-28T16:49:22.617 に答える