def plot_raster(spike_trains, with_histogram=True, population=None, node_groups=None, times=None, title=None, show=True, save_as=None):
    "will create a raster plot (plus optional histogram) from a SpikeTrains object or SONATA Spike-Trains file. Will\n    return the figure\n\n    By default will display all nodes, if you want to only display a subset of nodes and/or group together different\n    nodes (by node_id) by dot colors and labels then you can use the node_groups, which should be a list of dicts::\n\n        plot_raster('/path/to/my/spike.h5',\n        node_groups=[{'node_ids': range(0, 70), 'c': 'b', 'label': 'pyr'},      # first 70 nodes are blue pyr cells\n                     {'node_ids': range(70, 100), 'c': 'r', 'label': 'inh'}])   # last 30 nodes are red inh cells\n\n    The histogram will not be grouped.\n\n    :param spike_trains: SpikeTrains object or path to a (SONATA) spikes file.\n    :param with_histogram: If True the a histogram will be shown as a small subplot below the scatter plot. Default\n        True.\n    :param population: string. If a spikes-file contains more than one population of nodes, use this to determine which\n        nodes to actually plot. If only one population exists and population=None then the function will find it by\n        default.\n    :param node_groups: None or list of dicts. Used to group sets of nodes by labels and color. Each grouping should\n        be a dictionary with a 'node_ids' key with a list of the ids. You can also add 'label' and 'c' keys for\n        label and color. If None all nodes will be labeled and colored the same.\n    :param times: (float, float). Used to set start and stop time. If not specified will try to find values from spiking\n        data.\n    :param title: str, Use to add a title. Default no tile\n    :param show: bool to display or not display plot. default True.\n    :param save_as: None or str: file-name/path to save the plot as a png/jpeg/etc. If None or empty string will not\n        save plot.\n    :return: matplotlib figure.Figure object\n    "
    spike_trains = __get_spike_trains(spike_trains=spike_trains)
    pop = __get_population(spike_trains=spike_trains, population=population)
    (node_groups, selected_ids) = __get_node_groups(spike_trains=spike_trains, node_groups=node_groups, population=pop)
    show_legend = False
    (min_id, max_id) = (np.inf, (- 1))
    spikes_df = spike_trains.to_dataframe(population=pop, with_population_col=False)
    spikes_df = spikes_df[spikes_df['node_ids'].isin(selected_ids)]
    if (times is not None):
        (min_ts, max_ts) = (times[0], times[1])
        spikes_df = spikes_df[((spikes_df['timestamps'] >= times[0]) & (spikes_df['timestamps'] <= times[1]))]
    else:
        min_ts = np.min(spikes_df['timestamps'])
        max_ts = np.max(spikes_df['timestamps'])
    if with_histogram:
        (fig, axes) = plt.subplots(2, 1, gridspec_kw={'height_ratios': [7, 1]}, squeeze=True)
        raster_axes = axes[0]
        bottom_axes = hist_axes = axes[1]
    else:
        (fig, axes) = plt.subplots(1, 1)
        bottom_axes = raster_axes = axes
        hist_axes = None
    for node_grp in node_groups:
        grp_ids = node_grp.pop('node_ids')
        grp_spikes = spikes_df[spikes_df['node_ids'].isin(grp_ids)]
        show_legend = (show_legend or ('label' in node_grp))
        min_id = np.min([np.min(grp_ids), min_id])
        max_id = np.max([np.max(grp_ids), max_id])
        raster_axes.scatter(grp_spikes['timestamps'], grp_spikes['node_ids'], lw=0, s=8, **node_grp)
    if show_legend:
        raster_axes.legend(loc='upper right')
    if title:
        raster_axes.set_title(title)
    raster_axes.set_ylabel('node_ids')
    raster_axes.set_ylim((min_id - 0.5), (max_id + 1))
    raster_axes.set_xlim(min_ts, (max_ts + 1))
    bottom_axes.set_xlabel('timestamps ({})'.format(spike_trains.units(population=pop)))
    if with_histogram:
        hist_axes.hist(spikes_df['timestamps'], 100)
        hist_axes.set_xlim((min_ts - 0.5), (max_ts + 1))
        hist_axes.axes.get_yaxis().set_visible(False)
        raster_axes.set_xticks([])
    if save_as:
        plt.savefig(save_as)
    if show:
        plt.show()
    return fig
will create a raster plot (plus optional histogram) from a SpikeTrains object or SONATA Spike-Trains file. Will
return the figure

By default will display all nodes, if you want to only display a subset of nodes and/or group together different
nodes (by node_id) by dot colors and labels then you can use the node_groups, which should be a list of dicts::

    plot_raster('/path/to/my/spike.h5',
    node_groups=[{'node_ids': range(0, 70), 'c': 'b', 'label': 'pyr'},      # first 70 nodes are blue pyr cells
                 {'node_ids': range(70, 100), 'c': 'r', 'label': 'inh'}])   # last 30 nodes are red inh cells

The histogram will not be grouped.

:param spike_trains: SpikeTrains object or path to a (SONATA) spikes file.
:param with_histogram: If True the a histogram will be shown as a small subplot below the scatter plot. Default
    True.
:param population: string. If a spikes-file contains more than one population of nodes, use this to determine which
    nodes to actually plot. If only one population exists and population=None then the function will find it by
    default.
:param node_groups: None or list of dicts. Used to group sets of nodes by labels and color. Each grouping should
    be a dictionary with a 'node_ids' key with a list of the ids. You can also add 'label' and 'c' keys for
    label and color. If None all nodes will be labeled and colored the same.
:param times: (float, float). Used to set start and stop time. If not specified will try to find values from spiking
    data.
:param title: str, Use to add a title. Default no tile
:param show: bool to display or not display plot. default True.
:param save_as: None or str: file-name/path to save the plot as a png/jpeg/etc. If None or empty string will not
    save plot.
:return: matplotlib figure.Figure object
def plot_raster(spike_trains, with_histogram=True, population=None, node_groups=None, times=None, title=None, show=True, save_as=None):
    "will create a raster plot (plus optional histogram) from a SpikeTrains object or SONATA Spike-Trains file. Will\n    return the figure\n\n    By default will display all nodes, if you want to only display a subset of nodes and/or group together different\n    nodes (by node_id) by dot colors and labels then you can use the node_groups, which should be a list of dicts::\n\n        plot_raster('/path/to/my/spike.h5',\n        node_groups=[{'node_ids': range(0, 70), 'c': 'b', 'label': 'pyr'},      # first 70 nodes are blue pyr cells\n                     {'node_ids': range(70, 100), 'c': 'r', 'label': 'inh'}])   # last 30 nodes are red inh cells\n\n    The histogram will not be grouped.\n\n    :param spike_trains: SpikeTrains object or path to a (SONATA) spikes file.\n    :param with_histogram: If True the a histogram will be shown as a small subplot below the scatter plot. Default\n        True.\n    :param population: string. If a spikes-file contains more than one population of nodes, use this to determine which\n        nodes to actually plot. If only one population exists and population=None then the function will find it by\n        default.\n    :param node_groups: None or list of dicts. Used to group sets of nodes by labels and color. Each grouping should\n        be a dictionary with a 'node_ids' key with a list of the ids. You can also add 'label' and 'c' keys for\n        label and color. If None all nodes will be labeled and colored the same.\n    :param times: (float, float). Used to set start and stop time. If not specified will try to find values from spiking\n        data.\n    :param title: str, Use to add a title. Default no tile\n    :param show: bool to display or not display plot. default True.\n    :param save_as: None or str: file-name/path to save the plot as a png/jpeg/etc. If None or empty string will not\n        save plot.\n    :return: matplotlib figure.Figure object\n    "
    spike_trains = __get_spike_trains(spike_trains=spike_trains)
    pop = __get_population(spike_trains=spike_trains, population=population)
    (node_groups, selected_ids) = __get_node_groups(spike_trains=spike_trains, node_groups=node_groups, population=pop)
    show_legend = False
    (min_id, max_id) = (np.inf, (- 1))
    spikes_df = spike_trains.to_dataframe(population=pop, with_population_col=False)
    spikes_df = spikes_df[spikes_df['node_ids'].isin(selected_ids)]
    if (times is not None):
        (min_ts, max_ts) = (times[0], times[1])
        spikes_df = spikes_df[((spikes_df['timestamps'] >= times[0]) & (spikes_df['timestamps'] <= times[1]))]
    else:
        min_ts = np.min(spikes_df['timestamps'])
        max_ts = np.max(spikes_df['timestamps'])
    if with_histogram:
        (fig, axes) = plt.subplots(2, 1, gridspec_kw={'height_ratios': [7, 1]}, squeeze=True)
        raster_axes = axes[0]
        bottom_axes = hist_axes = axes[1]
    else:
        (fig, axes) = plt.subplots(1, 1)
        bottom_axes = raster_axes = axes
        hist_axes = None
    for node_grp in node_groups:
        grp_ids = node_grp.pop('node_ids')
        grp_spikes = spikes_df[spikes_df['node_ids'].isin(grp_ids)]
        show_legend = (show_legend or ('label' in node_grp))
        min_id = np.min([np.min(grp_ids), min_id])
        max_id = np.max([np.max(grp_ids), max_id])
        raster_axes.scatter(grp_spikes['timestamps'], grp_spikes['node_ids'], lw=0, s=8, **node_grp)
    if show_legend:
        raster_axes.legend(loc='upper right')
    if title:
        raster_axes.set_title(title)
    raster_axes.set_ylabel('node_ids')
    raster_axes.set_ylim((min_id - 0.5), (max_id + 1))
    raster_axes.set_xlim(min_ts, (max_ts + 1))
    bottom_axes.set_xlabel('timestamps ({})'.format(spike_trains.units(population=pop)))
    if with_histogram:
        hist_axes.hist(spikes_df['timestamps'], 100)
        hist_axes.set_xlim((min_ts - 0.5), (max_ts + 1))
        hist_axes.axes.get_yaxis().set_visible(False)
        raster_axes.set_xticks([])
    if save_as:
        plt.savefig(save_as)
    if show:
        plt.show()
    return fig