def plot_time_vs_position(self, end='source', dimension='x', traced=True, picked=True, ax=None, outfile=None, event_colors={}, default_color=DEFAULT_TRAVELTIME_COLOR): """ Plot traveltimes in each rayfan vs. position. :param end: Optional. Specifies which end of the raypath to plot as on the abscissa. Options are: 'source' (default) or 'receiver'. :param dimension: Specifies which dimension of the raypath end to plot on the abscissa. Options are: 'x' (default), 'y', or 'z'. :param ax: Optional. A :class:`matplotlib.Axes.axes` object to plot into. Default is to create a new figure and axes. :param traced: Optional. Determines whether or not to plot raytraced travel times, if they exist. Default is ``True``. :param picked: Optional. Determines whether or not to plot picked travel times, if they exist. Default is ``True``. :param outfile: Output file string. 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. Default is ``None``. :param event_colors: Optional. Dictionary of event names and colors to use for plotting traveltimes for different events. If ``event_colors`` is not given, or if an event ID is not in ``event_colors``, traveltimes are plotted in the color given by ``default_color``. :param default_color: Optional. Color to use when plotting traveltimes for events not in ``event_colors``. Default is black. """ if ax is None: fig = plt.figure() ax = fig.add_subplot(111) show = True else: show = False end_opts = {'source': 0, 'receiver': -1} dim_opts = {'x': 0, 'y': 1, 'z': 2} iend = end_opts[end] idim = dim_opts[dimension] for rfn in self.rayfans: x = [p[iend][idim] for p in rfn.paths] if picked: for i, t in enumerate(rfn.pick_times): c = get_dict_default(rfn.event_ids[i], event_colors, default_color) ax.errorbar(x[i], t, yerr=rfn.pick_errors[i], fmt=c + '.', markersize=0, capsize=0) if traced: for i, t in enumerate(rfn.travel_times): c = get_dict_default(rfn.event_ids[i], event_colors, default_color) ax.scatter(x[i], t, marker='.', color=c, s=1, linewidths=0) plt.xlabel('{:} {:} (km)'.format(end, dimension)) plt.ylabel('t (s)') if outfile: fig.savefig(outfile) elif show: plt.show() else: plt.draw()
def plot_raypaths(self, dim=[0, 2], ax=None, receivers=True, sources=True, outfile=None, event_colors={}, default_color=DEFAULT_RAYPATH_COLOR): """ Plot all raypaths. :param dim: Coordinate dimensions to plot paths into. Default is z vs. x (``dim=[0,2]``). :param ax: A :class:`matplotlib.Axes.axes` object to plot into. Default is to create a new figure and axes. :param receivers: Determines whether or not to plot symbols at the receiver locations. Default is ``True``. :param sources: Determines whether or not to plot symbols at the source locations. Default is ``False``. :param outfile: Output file string. 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. Default is ``None``. :param event_colors: Optional. Dictionary of event names and colors to use for plotting raypaths for different events. If ``event_colors`` is not given, or if an event ID is not in ``event_colors``, raypaths are plotted in the color given by ``default_color``. :param default_color: Optional. Color to use when plotting raypaths for events not in ``event_colors``. Default is grey. """ if ax is None: fig = plt.figure() ax = fig.add_subplot(111) reverse = True show = True else: reverse = False show = False for irfn, rfn in enumerate(self.rayfans): for i, path in enumerate(rfn.paths): x = [p[dim[0]] for p in path] y = [p[dim[1]] for p in path] c = get_dict_default(rfn.event_ids[i], event_colors, default_color) ax.plot(x, y, color=c) if receivers: x = rfn.paths[i][-1][dim[0]] y = rfn.paths[i][-1][dim[1]] ax.plot(x, y, 'vy') if sources: x = rfn.endpoints[i][dim[0]] y = rfn.endpoints[i][dim[1]] ax.plot(x, y, '*r') if reverse: ax.set_ylim(ax.get_ylim()[::-1]) if outfile: fig.savefig(outfile) elif show: plt.show() else: plt.draw()