1

I'm trying to follow the tutorial here:

http://nbviewer.ipython.org/github/ehmatthes/intro_programming/blob/master/notebooks/visualization_earthquakes.ipynb#install_standard

However, I am using pandas instead of the built in csv module for python. My code is as follows:

import pandas as pd
eq_data = pd.read_csv('earthquake_data.csv')
map2 = Basemap(projection='robin'
               , resolution='l'
               , area_thresh=1000.0
               , lat_0=0
               , lon_0=0)

map2.drawcoastlines()
map2.drawcountries()
map2.fillcontinents(color = 'gray')
map2.drawmapboundary()
map2.drawmeridians(np.arange(0, 360, 30))
map2.drawparallels(np.arange(-90, 90, 30))

x,y = map2(eq_data['longitude'].values, eq_data['latitude'].values)

map2.plot(x,y, marker='0', markercolor='red', markersize=6)

This produces an AssertionError but with no description:

AssertionError                            Traceback (most recent call last)
<ipython-input-64-d3426e1f175d> in <module>()
     14 x,y = map2(range(20), range(20))#eq_data['longitude'].values, eq_data['latitude'].values)
     15 
---> 16 map2.plot(x,y, marker='0', markercolor='red', markersize=6)

c:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.pyc in with_transform(self, x, y, *args, **kwargs)
    540             # convert lat/lon coords to map projection coords.
    541             x, y = self(x,y)
--> 542         return plotfunc(self,x,y,*args,**kwargs)
    543     return with_transform
    544 

c:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.pyc in plot(self, *args, **kwargs)
   3263             ax.hold(h)
   3264         try:
-> 3265             ret =  ax.plot(*args, **kwargs)
   3266         except:
   3267             ax.hold(b)

c:\Python27\lib\site-packages\matplotlib\axes.pyc in plot(self, *args, **kwargs)
   4135         lines = []
   4136 
-> 4137         for line in self._get_lines(*args, **kwargs):
   4138             self.add_line(line)
   4139             lines.append(line)

c:\Python27\lib\site-packages\matplotlib\axes.pyc in _grab_next_args(self, *args, **kwargs)
    315                 return
    316             if len(remaining) <= 3:
--> 317                 for seg in self._plot_args(remaining, kwargs):
    318                     yield seg
    319                 return

c:\Python27\lib\site-packages\matplotlib\axes.pyc in _plot_args(self, tup, kwargs)
    303         ncx, ncy = x.shape[1], y.shape[1]
    304         for j in xrange(max(ncx, ncy)):
--> 305             seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
    306             ret.append(seg)
    307         return ret

c:\Python27\lib\site-packages\matplotlib\axes.pyc in _makeline(self, x, y, kw, kwargs)
    255                             **kw
    256                             )
--> 257         self.set_lineprops(seg, **kwargs)
    258         return seg
    259 

c:\Python27\lib\site-packages\matplotlib\axes.pyc in set_lineprops(self, line, **kwargs)
    198                 raise TypeError('There is no line property "%s"' % key)
    199             func = getattr(line, funcName)
--> 200             func(val)
    201 
    202     def set_patchprops(self, fill_poly, **kwargs):

c:\Python27\lib\site-packages\matplotlib\lines.pyc in set_marker(self, marker)
    851 
    852         """
--> 853         self._marker.set_marker(marker)
    854 
    855     def set_markeredgecolor(self, ec):

c:\Python27\lib\site-packages\matplotlib\markers.pyc in set_marker(self, marker)
    231         else:
    232             try:
--> 233                 Path(marker)
    234                 self._marker_function = self._set_vertices
    235             except ValueError:

c:\Python27\lib\site-packages\matplotlib\path.pyc in __init__(self, vertices, codes, _interpolation_steps, closed, readonly)
    145             codes[-1] = self.CLOSEPOLY
    146 
--> 147         assert vertices.ndim == 2
    148         assert vertices.shape[1] == 2
    149 

AssertionError: 

I thought I had the problem due to the update to pandas which no longer allows passing Series like you used to be able to as described here:

Runtime error using python basemap and pyproj?

But as you can see, I adjusted my code for this and it didn't fix the problem. At this point I am lost.

I am using Python 2.7.6, pandas 0.15.2, and basemap 1.0.7 on windows server 2012 x64.

Community
  • 1
  • 1
mnky9800n
  • 1,113
  • 2
  • 15
  • 33
  • 1
    what if you set `x = eq_data['longitude'].values` and `y = eq_data['latitude'].values` separately and then pass them into `plot()`? – alacy Jan 02 '15 at 00:17
  • This doesn't work because map2() expects 3 arguments (x,y, and self). – mnky9800n Jan 02 '15 at 02:08
  • So `map2.plot(x,y, marker='0', markercolor='red', markersize=6)` won't work if you declare `x` and `y` separately? – alacy Jan 02 '15 at 02:14
  • Oh, I misread your comment I'm sorry. No this: `x = eq_data['longitude'].values; y= eq_data['latitude'].values; map2.plot(x,y, marker='0', markercolor='red', markersize=6);` produces the same error as before. – mnky9800n Jan 02 '15 at 02:22

1 Answers1

2

There are two problems with my code. First, the plot function for the map2 object is inherited from matplotlib. Thus the marker attribute cannot be '0' it needs to be 'o'. Additionally, there is no markercolor attribute. It is called color. The below code should work.

import pandas as pd
eq_data = pd.read_csv('earthquake_data.csv')
map2 = Basemap(projection='robin'
               , resolution='l'
               , area_thresh=1000.0
               , lat_0=0
               , lon_0=0)

map2.drawcoastlines()
map2.drawcountries()
map2.fillcontinents(color = 'gray')
map2.drawmapboundary()
map2.drawmeridians(np.arange(0, 360, 30))
map2.drawparallels(np.arange(-90, 90, 30))

x,y = map2(eq_data['longitude'].values, eq_data['latitude'].values)

map2.plot(x,y, marker='o', color='red', markersize=6, linestyle='')
mnky9800n
  • 1,113
  • 2
  • 15
  • 33