Obspy: Plotting stations in an inventory on a map using projection='local'

Created on 19 Dec 2019  路  8Comments  路  Source: obspy/obspy

I have an issue with plotting the stations in an inventory on a map using projection='local'. The 'ortho' and 'global' options do work.

I am using ObsPy version 1.1.1, Python 3.7.5 and OSX.
I installed Python via Homebrew and Obspy through pip.

The same problem occurs for ObsPy 1.1.1 under Python 2.7.17 (not shown here)

from obspy import UTCDateTime
from obspy.clients.fdsn import Client
cl=Client('KNMI')

t0 = UTCDateTime('2019-01-01T00:00:00')
t1 = UTCDateTime('2020-01-01T00:00:00')

inv = cl.get_stations(network='NL',station='DBN*',channel='HDF',starttime=t0,endtime=t1)

inv.plot(projection='local')

Produces the following error:

ValueError                                Traceback (most recent call last)
<ipython-input-6-ff488bde6a67> in <module>
----> 1 inv.plot(projection='local')

/usr/local/lib/python3.7/site-packages/obspy/core/inventory/inventory.py in plot(self, projection, resolution, continent_fill_color, water_fill_color, marker, size, label, color, color_per_network, colormap, legend, time, show, outfile, method, fig, **kwargs)
    748                        water_fill_color=water_fill_color,
    749                        colormap=None, colorbar=False, marker=marker,
--> 750                        title=None, show=False, fig=fig, **kwargs)
    751 
    752         if legend is not None and color_per_network:

/usr/local/lib/python3.7/site-packages/obspy/imaging/maps.py in plot_map(method, *args, **kwargs)
    787     if method is None:
    788         if HAS_BASEMAP:
--> 789             return plot_basemap(*args, **kwargs)
    790         elif HAS_CARTOPY:
    791             return plot_cartopy(*args, **kwargs)

/usr/local/lib/python3.7/site-packages/obspy/imaging/maps.py in plot_basemap(lons, lats, size, color, labels, projection, resolution, continent_fill_color, water_fill_color, colormap, colorbar, marker, title, colorbar_ticklabel_format, show, fig, **kwargs)
    259                 water_fill_color=water_fill_color, colormap=colormap,
    260                 marker=marker, title="", adjust_aspect_to_colorbar=colorbar,
--> 261                 **kwargs)
    262     except AttributeError as e:
    263         if 'axesPatch' not in str(e):

/usr/local/lib/python3.7/site-packages/obspy/imaging/maps.py in _plot_basemap_into_axes(ax, lons, lats, size, color, bmap, labels, projection, resolution, continent_fill_color, water_fill_color, colormap, marker, title, adjust_aspect_to_colorbar, **kwargs)
    432         else:
    433             ax.set_axis_bgcolor(water_fill_color)
--> 434         bmap.drawcoastlines(color="0.4")
    435         bmap.drawcountries(color="0.75")
    436         bmap.fillcontinents(color=continent_fill_color,

/usr/local/lib/python3.7/site-packages/mpl_toolkits/basemap/__init__.py in drawcoastlines(self, linewidth, linestyle, color, antialiased, ax, zorder)
   1847         # get current axes instance (if none specified).
   1848         ax = ax or self._check_ax()
-> 1849         coastlines = LineCollection(self.coastsegs,antialiaseds=(antialiased,))
   1850         coastlines.set_color(color)
   1851         coastlines.set_linestyle(linestyle)

/usr/local/lib/python3.7/site-packages/matplotlib/collections.py in __init__(self, segments, linewidths, colors, antialiaseds, linestyles, offsets, transOffset, norm, cmap, pickradius, zorder, facecolors, **kwargs)
   1224             **kwargs)
   1225 
-> 1226         self.set_segments(segments)
   1227 
   1228     def set_segments(self, segments):

/usr/local/lib/python3.7/site-packages/matplotlib/collections.py in set_segments(self, segments)
   1239             _segments = self._add_offsets(_segments)
   1240 
-> 1241         self._paths = [mpath.Path(_seg) for _seg in _segments]
   1242         self.stale = True
   1243 

/usr/local/lib/python3.7/site-packages/matplotlib/collections.py in <listcomp>(.0)
   1239             _segments = self._add_offsets(_segments)
   1240 
-> 1241         self._paths = [mpath.Path(_seg) for _seg in _segments]
   1242         self.stale = True
   1243 

/usr/local/lib/python3.7/site-packages/matplotlib/path.py in __init__(self, vertices, codes, _interpolation_steps, closed, readonly)
    128         if vertices.ndim != 2 or vertices.shape[1] != 2:
    129             raise ValueError(
--> 130                 "'vertices' must be a 2D list or array with shape Nx2")
    131 
    132         if codes is not None:

ValueError: 'vertices' must be a 2D list or array with shape Nx2
.imaging .core.inventory

All 8 comments

It looks like you are using Python 2.7, but you say you think you are using Python 3.7 - can you check that you are using the Python you expect to be using?

Ah, my bad, it was a Python2 notebook. I can generate the error for both Python versions actually. I have updated the post now such that it reflects the error message under Python3.

Thanks for checking - just wanted to be sure it wasn't some strange mixed install issue!

I'm afraid I can't reproduce this on my machine - this might be a matplotlib/basemap version thing. What versions of those two packages have you installed?

For reference I have:

  • matplotlib 3.0.3
  • basemap 1.2.0

I feel like I have seen this issue before but I haven't been able to find an issue or PR relating to it.

I have the same versions of matplotlib and basemap. Strange!

There are no issues with plotting the Catalog, by the way:

from obspy import UTCDateTime
from obspy.clients.fdsn import Client
cl=Client('KNMI')

t0 = UTCDateTime('2019-01-01T00:00:00')
t1 = UTCDateTime('2020-01-01T00:00:00')

cat = cl.get_events(starttime=t0,endtime=t1)

cat.plot(projection='local')

works like a charm.

Eventually I solved it by changing package versions. This works for me.

Python | 3.7.3 | packaged by conda-forge | (default, Dec 6 2019, 08:36:57)
[Clang 9.0.0 (tags/RELEASE_900/final)]
ObsPy | 1.1.0
Matplotlib | 3.1.2
Numpy | 1.17.3
Scipy | 1.4.0
Basemap | 1.2.1

Strange indeed - I'm going to close this, and hopefully if someone else runs into this they will find this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Earthscience picture Earthscience  路  8Comments

yoonstation picture yoonstation  路  4Comments

Khalilsqu picture Khalilsqu  路  3Comments

jschaeff picture jschaeff  路  10Comments

JackWalpole picture JackWalpole  路  11Comments