def plot( self, projection="cyl", resolution="l", continent_fill_color="0.9", water_fill_color="1.0", marker="v", size=15 ** 2, label=True, color="blue", color_per_network=False, colormap="jet", legend="upper left", time=None, show=True, outfile=None, **kwargs ): # @UnusedVariable """ Creates a preview map of all networks/stations in current inventory object. :type projection: str, optional :param projection: The map projection. Currently supported are: * ``"cyl"`` (Will plot the whole world.) * ``"ortho"`` (Will center around the mean lat/long.) * ``"local"`` (Will plot around local events) Defaults to ``"cyl"`` :type resolution: str, optional :param resolution: Resolution of the boundary database to use. Will be based directly to the basemap module. Possible values are: * ``"c"`` (crude) * ``"l"`` (low) * ``"i"`` (intermediate) * ``"h"`` (high) * ``"f"`` (full) Defaults to ``"l"`` :type continent_fill_color: Valid matplotlib color, optional :param continent_fill_color: Color of the continents. Defaults to ``"0.9"`` which is a light gray. :type water_fill_color: Valid matplotlib color, optional :param water_fill_color: Color of all water bodies. Defaults to ``"white"``. :type marker: str :param marker: Marker symbol (see :func:`matplotlib.pyplot.scatter`). :type size: float :param size: Marker size (see :func:`matplotlib.pyplot.scatter`). :type label: bool :param label: Whether to label stations with "network.station" or not. :type color: str :param color: Face color of marker symbol (see :func:`matplotlib.pyplot.scatter`). :type color_per_network: bool or dict :param color_per_network: If set to ``True``, each network will be drawn in a different color. A dictionary can be provided that maps network codes to color values (e.g. ``color_per_network={"GR": "black", "II": "green"}``). :type colormap: str, any matplotlib colormap, optional :param colormap: Only used if ``color_per_network=True``. Specifies which colormap is used to draw the colors for the individual networks. :type legend: str or None :param legend: Location string for legend, if networks are plotted in different colors (i.e. option ``color_per_network`` in use). See :func:`matplotlib.pyplot.legend` for possible values for legend location string. To disable legend set to ``None``. :type time: :class:`~obspy.core.utcdatetime.UTCDateTime` :param time: Only plot stations available at given point in time. :type show: bool :param show: Whether to show the figure after plotting or not. Can be used to do further customization of the plot before showing it. :type outfile: str :param outfile: Output file path to directly save the resulting image (e.g. ``"/tmp/image.png"``). Overrides the ``show`` option, image will not be displayed interactively. The given path/filename is also used to automatically determine the output format. Supported file formats depend on your matplotlib backend. Most backends support png, pdf, ps, eps and svg. Defaults to ``None``. .. rubric:: Example Cylindrical projection for global overview: >>> from obspy import read_inventory >>> inv = read_inventory() >>> inv.plot(label=False) # doctest:+SKIP .. plot:: from obspy import read_inventory inv = read_inventory() inv.plot(label=False) Orthographic projection, automatic colors per network: >>> inv.plot(projection="ortho", label=False, ... color_per_network=True) # doctest:+SKIP .. plot:: from obspy import read_inventory inv = read_inventory() inv.plot(projection="ortho", label=False, color_per_network=True) Local (azimuthal equidistant) projection, with custom colors: >>> colors = {'GR': 'blue', 'BW': 'green'} >>> inv.plot(projection="local", ... color_per_network=colors) # doctest:+SKIP .. plot:: from obspy import read_inventory inv = read_inventory() inv.plot(projection="local", color_per_network={'GR': 'blue', 'BW': 'green'}) """ from obspy.imaging.maps import plot_basemap import matplotlib.pyplot as plt # The empty ones must be kept as otherwise inventory files without # channels will end up with nothing. inv = self.select(time=time, keep_empty=True) # lat/lon coordinates, magnitudes, dates lats = [] lons = [] labels = [] colors = [] if color_per_network and not isinstance(color_per_network, dict): from matplotlib.cm import get_cmap cmap = get_cmap(name=colormap) codes = set([n.code for n in inv]) nums = np.linspace(0, 1, endpoint=False, num=len(codes)) color_per_network = dict([(code, cmap(n)) for code, n in zip(sorted(codes), nums)]) for net in inv: for sta in net: if sta.latitude is None or sta.longitude is None: msg = ( "Station '%s' does not have latitude/longitude " "information and will not be plotted." % label ) warnings.warn(msg) continue if color_per_network: label_ = " %s" % sta.code color_ = color_per_network.get(net.code, "k") else: label_ = " " + ".".join((net.code, sta.code)) color_ = color lats.append(sta.latitude) lons.append(sta.longitude) labels.append(label_) colors.append(color_) if not label: labels = None fig = plot_basemap( lons, lats, size, colors, labels, projection=projection, resolution=resolution, continent_fill_color=continent_fill_color, water_fill_color=water_fill_color, colormap=None, colorbar=False, marker=marker, title=None, show=False, **kwargs ) if legend is not None and color_per_network: ax = fig.axes[0] count = len(ax.collections) for code, color in sorted(color_per_network.items()): ax.scatter([0], [0], size, color, label=code, marker=marker) # workaround for older matplotlib versions try: ax.legend( loc=legend, fancybox=True, scatterpoints=1, fontsize="medium", markerscale=0.8, handletextpad=0.1 ) except TypeError: leg_ = ax.legend(loc=legend, fancybox=True, scatterpoints=1, markerscale=0.8, handletextpad=0.1) leg_.prop.set_size("medium") # remove collections again solely created for legend handles ax.collections = ax.collections[:count] if outfile: fig.savefig(outfile) else: if show: plt.show() return fig
def plot(self, projection='cyl', resolution='l', continent_fill_color='0.9', water_fill_color='1.0', marker="v", size=15**2, label=True, color='blue', time=None, show=True, outfile=None, **kwargs): # @UnusedVariable """ Creates a preview map of all stations in current network object. :type projection: str, optional :param projection: The map projection. Currently supported are: * ``"cyl"`` (Will plot the whole world.) * ``"ortho"`` (Will center around the mean lat/long.) * ``"local"`` (Will plot around local events) Defaults to "cyl" :type resolution: str, optional :param resolution: Resolution of the boundary database to use. Will be based directly to the basemap module. Possible values are: * ``"c"`` (crude) * ``"l"`` (low) * ``"i"`` (intermediate) * ``"h"`` (high) * ``"f"`` (full) Defaults to ``"l"`` :type continent_fill_color: Valid matplotlib color, optional :param continent_fill_color: Color of the continents. Defaults to ``"0.9"`` which is a light gray. :type water_fill_color: Valid matplotlib color, optional :param water_fill_color: Color of all water bodies. Defaults to ``"white"``. :type marker: str :param marker: Marker symbol (see :func:`matplotlib.pyplot.scatter`). :type label: bool :param label: Whether to label stations with "network.station" or not. :type color: str :param color: Face color of marker symbol (see :func:`matplotlib.pyplot.scatter`). :type time: :class:`~obspy.core.utcdatetime.UTCDateTime` :param time: Only plot stations available at given point in time. :type show: bool :param show: Whether to show the figure after plotting or not. Can be used to do further customization of the plot before showing it. :type outfile: str :param outfile: Output file path to directly save the resulting image (e.g. ``"/tmp/image.png"``). Overrides the ``show`` option, image will not be displayed interactively. The given path/filename is also used to automatically determine the output format. Supported file formats depend on your matplotlib backend. Most backends support png, pdf, ps, eps and svg. Defaults to ``None``. .. rubric:: Example Cylindrical projection for global overview: >>> from obspy import read_inventory >>> net = read_inventory()[0] >>> net.plot(label=False) # doctest:+SKIP .. plot:: from obspy import read_inventory net = read_inventory()[0] net.plot(label=False) Orthographic projection: >>> net.plot(projection="ortho") # doctest:+SKIP .. plot:: from obspy import read_inventory net = read_inventory()[0] net.plot(projection="ortho") Local (azimuthal equidistant) projection: >>> net.plot(projection="local") # doctest:+SKIP .. plot:: from obspy import read_inventory net = read_inventory()[0] net.plot(projection="local") """ from obspy.imaging.maps import plot_basemap import matplotlib.pyplot as plt # lat/lon coordinates, magnitudes, dates lats = [] lons = [] labels = [] for sta in self.select(time=time).stations: label_ = " " + ".".join((self.code, sta.code)) if sta.latitude is None or sta.longitude is None: msg = ("Station '%s' does not have latitude/longitude " "information and will not be plotted." % label) warnings.warn(msg) continue lats.append(sta.latitude) lons.append(sta.longitude) labels.append(label_) if not label: labels = None fig = plot_basemap(lons, lats, size, color, labels, projection=projection, resolution=resolution, continent_fill_color=continent_fill_color, water_fill_color=water_fill_color, colormap=None, marker=marker, title=None, show=False, **kwargs) if outfile: fig.savefig(outfile) else: if show: plt.show() return fig
def plot(self, projection='cyl', resolution='l', continent_fill_color='0.9', water_fill_color='1.0', marker="v", size=15**2, label=True, color='blue', time=None, show=True, outfile=None, **kwargs): # @UnusedVariable """ Creates a preview map of all stations in current network object. :type projection: str, optional :param projection: The map projection. Currently supported are: * ``"cyl"`` (Will plot the whole world.) * ``"ortho"`` (Will center around the mean lat/long.) * ``"local"`` (Will plot around local events) Defaults to "cyl" :type resolution: str, optional :param resolution: Resolution of the boundary database to use. Will be based directly to the basemap module. Possible values are: * ``"c"`` (crude) * ``"l"`` (low) * ``"i"`` (intermediate) * ``"h"`` (high) * ``"f"`` (full) Defaults to ``"l"`` :type continent_fill_color: Valid matplotlib color, optional :param continent_fill_color: Color of the continents. Defaults to ``"0.9"`` which is a light gray. :type water_fill_color: Valid matplotlib color, optional :param water_fill_color: Color of all water bodies. Defaults to ``"white"``. :type marker: str :param marker: Marker symbol (see :func:`matplotlib.pyplot.scatter`). :type label: bool :param label: Whether to label stations with "network.station" or not. :type color: str :param color: Face color of marker symbol (see :func:`matplotlib.pyplot.scatter`). :type time: :class:`~obspy.core.utcdatetime.UTCDateTime` :param time: Only plot stations available at given point in time. :type show: bool :param show: Whether to show the figure after plotting or not. Can be used to do further customization of the plot before showing it. :type outfile: str :param outfile: Output file path to directly save the resulting image (e.g. ``"/tmp/image.png"``). Overrides the ``show`` option, image will not be displayed interactively. The given path/file name is also used to automatically determine the output format. Supported file formats depend on your matplotlib backend. Most backends support png, pdf, ps, eps and svg. Defaults to ``None``. .. rubric:: Example Cylindrical projection for global overview: >>> from obspy import read_inventory >>> net = read_inventory()[0] >>> net.plot(label=False) # doctest:+SKIP .. plot:: from obspy import read_inventory net = read_inventory()[0] net.plot(label=False) Orthographic projection: >>> net.plot(projection="ortho") # doctest:+SKIP .. plot:: from obspy import read_inventory net = read_inventory()[0] net.plot(projection="ortho") Local (azimuthal equidistant) projection: >>> net.plot(projection="local") # doctest:+SKIP .. plot:: from obspy import read_inventory net = read_inventory()[0] net.plot(projection="local") """ from obspy.imaging.maps import plot_basemap import matplotlib.pyplot as plt # lat/lon coordinates, magnitudes, dates lats = [] lons = [] labels = [] for sta in self.select(time=time).stations: label_ = " " + ".".join((self.code, sta.code)) if sta.latitude is None or sta.longitude is None: msg = ("Station '%s' does not have latitude/longitude " "information and will not be plotted." % label) warnings.warn(msg) continue lats.append(sta.latitude) lons.append(sta.longitude) labels.append(label_) if not label: labels = None fig = plot_basemap(lons, lats, size, color, labels, projection=projection, resolution=resolution, continent_fill_color=continent_fill_color, water_fill_color=water_fill_color, colormap=None, marker=marker, title=None, show=False, **kwargs) if outfile: fig.savefig(outfile) else: if show: plt.show() return fig
#cat.plot(method='basemap', fig=fig, title=None) lats = [] lons = [] labels = [] mags = [] colors = [] times = [] for event in cat: origin = event.preferred_origin() or event.origins[0] lats.append(origin.latitude) lons.append(origin.longitude) times.append(origin.time) magnitude = event.preferred_magnitude() or event.magnitudes[0] mag = magnitude.mag mags.append(mag) colors.append('k') #fig = plot_basemap(lons, lats, 22., 'g', show=False, fig=fig, continent_fill_color='0.5', resolution='i') fig = plot_basemap(lons, lats, 22., 'g', show=False, fig=fig, continent_fill_color='0.9', resolution='h') ax = fig.axes[0] ax.scatter([],[], 22., 'g', label='Earthquake', marker="o") plt.legend(loc=9, ncol=3, bbox_to_anchor=(0.5,-0.01), scatterpoints=1) fig.savefig('Map.pdf',format='PDF', dpi=600) fig.savefig('Map.png',format='png', dpi=600)
def plot(self, projection='cyl', resolution='l', continent_fill_color='0.9', water_fill_color='1.0', marker="v", size=15**2, label=True, color='blue', color_per_network=False, colormap="jet", legend="upper left", time=None, show=True, outfile=None, **kwargs): # @UnusedVariable """ Creates a preview map of all networks/stations in current inventory object. :type projection: str, optional :param projection: The map projection. Currently supported are: * ``"cyl"`` (Will plot the whole world.) * ``"ortho"`` (Will center around the mean lat/long.) * ``"local"`` (Will plot around local events) Defaults to ``"cyl"`` :type resolution: str, optional :param resolution: Resolution of the boundary database to use. Will be based directly to the basemap module. Possible values are: * ``"c"`` (crude) * ``"l"`` (low) * ``"i"`` (intermediate) * ``"h"`` (high) * ``"f"`` (full) Defaults to ``"l"`` :type continent_fill_color: Valid matplotlib color, optional :param continent_fill_color: Color of the continents. Defaults to ``"0.9"`` which is a light gray. :type water_fill_color: Valid matplotlib color, optional :param water_fill_color: Color of all water bodies. Defaults to ``"white"``. :type marker: str :param marker: Marker symbol (see :func:`matplotlib.pyplot.scatter`). :type size: float :param size: Marker size (see :func:`matplotlib.pyplot.scatter`). :type label: bool :param label: Whether to label stations with "network.station" or not. :type color: str :param color: Face color of marker symbol (see :func:`matplotlib.pyplot.scatter`). :type color_per_network: bool or dict :param color_per_network: If set to ``True``, each network will be drawn in a different color. A dictionary can be provided that maps network codes to color values (e.g. ``color_per_network={"GR": "black", "II": "green"}``). :type colormap: str, any matplotlib colormap, optional :param colormap: Only used if ``color_per_network=True``. Specifies which colormap is used to draw the colors for the individual networks. :type legend: str or None :param legend: Location string for legend, if networks are plotted in different colors (i.e. option ``color_per_network`` in use). See :func:`matplotlib.pyplot.legend` for possible values for legend location string. To disable legend set to ``None``. :type time: :class:`~obspy.core.utcdatetime.UTCDateTime` :param time: Only plot stations available at given point in time. :type show: bool :param show: Whether to show the figure after plotting or not. Can be used to do further customization of the plot before showing it. :type outfile: str :param outfile: Output file path to directly save the resulting image (e.g. ``"/tmp/image.png"``). Overrides the ``show`` option, image will not be displayed interactively. The given path/file name is also used to automatically determine the output format. Supported file formats depend on your matplotlib backend. Most backends support png, pdf, ps, eps and svg. Defaults to ``None``. .. rubric:: Example Cylindrical projection for global overview: >>> from obspy import read_inventory >>> inv = read_inventory() >>> inv.plot(label=False) # doctest:+SKIP .. plot:: from obspy import read_inventory inv = read_inventory() inv.plot(label=False) Orthographic projection, automatic colors per network: >>> inv.plot(projection="ortho", label=False, ... color_per_network=True) # doctest:+SKIP .. plot:: from obspy import read_inventory inv = read_inventory() inv.plot(projection="ortho", label=False, color_per_network=True) Local (azimuthal equidistant) projection, with custom colors: >>> colors = {'GR': 'blue', 'BW': 'green'} >>> inv.plot(projection="local", ... color_per_network=colors) # doctest:+SKIP .. plot:: from obspy import read_inventory inv = read_inventory() inv.plot(projection="local", color_per_network={'GR': 'blue', 'BW': 'green'}) """ from obspy.imaging.maps import plot_basemap import matplotlib.pyplot as plt # The empty ones must be kept as otherwise inventory files without # channels will end up with nothing. inv = self.select(time=time, keep_empty=True) # lat/lon coordinates, magnitudes, dates lats = [] lons = [] labels = [] colors = [] if color_per_network and not isinstance(color_per_network, dict): from matplotlib.cm import get_cmap cmap = get_cmap(name=colormap) codes = set([n.code for n in inv]) nums = np.linspace(0, 1, endpoint=False, num=len(codes)) color_per_network = dict([(code, cmap(n)) for code, n in zip(sorted(codes), nums)]) for net in inv: for sta in net: if sta.latitude is None or sta.longitude is None: msg = ("Station '%s' does not have latitude/longitude " "information and will not be plotted." % label) warnings.warn(msg) continue if color_per_network: label_ = " %s" % sta.code color_ = color_per_network.get(net.code, "k") else: label_ = " " + ".".join((net.code, sta.code)) color_ = color lats.append(sta.latitude) lons.append(sta.longitude) labels.append(label_) colors.append(color_) if not label: labels = None fig = plot_basemap(lons, lats, size, colors, labels, projection=projection, resolution=resolution, continent_fill_color=continent_fill_color, water_fill_color=water_fill_color, colormap=None, colorbar=False, marker=marker, title=None, show=False, **kwargs) if legend is not None and color_per_network: ax = fig.axes[0] count = len(ax.collections) for code, color in sorted(color_per_network.items()): ax.scatter([0], [0], size, color, label=code, marker=marker) # workaround for older matplotlib versions try: ax.legend(loc=legend, fancybox=True, scatterpoints=1, fontsize="medium", markerscale=0.8, handletextpad=0.1) except TypeError: leg_ = ax.legend(loc=legend, fancybox=True, scatterpoints=1, markerscale=0.8, handletextpad=0.1) leg_.prop.set_size("medium") # remove collections again solely created for legend handles ax.collections = ax.collections[:count] if outfile: fig.savefig(outfile) else: if show: plt.show() return fig