Beispiel #1
0
def plot_data_dict(data_dict, plots = None, mode = 'static', hang = True, figure = None, size = None, **plot_preference_kwargs):
    """
    Make a plot of data in the format defined in data_dict
    :param data_dict: dict<str: plottable_data>
    :param plots: Optionally, a dict of <key: IPlot> identifying the plot objects to use (keys should
        be the same as those in data_dict).
    :return: The plots (same ones you provided if you provided them)
    """

    assert mode in ('live', 'static')
    if isinstance(data_dict, list):
        assert all(len(d) == 2 for d in data_dict), "You can provide data as a list of 2 tuples of (plot_name, plot_data)"
        data_dict = OrderedDict(data_dict)

    if plots is None:
        plots = {k: eplt.get_plot_from_data(v, mode = mode, **plot_preference_kwargs) for k, v in data_dict.iteritems()}

    if figure is None:
        if size is not None:
            from pylab import rcParams
            rcParams['figure.figsize'] = size
        figure = eplt.figure()
    n_rows, n_cols = vector_length_to_tile_dims(len(data_dict))
    for i, (k, v) in enumerate(data_dict.iteritems()):
        eplt.subplot(n_rows, n_cols, i+1)
        plots[k].update(v)
        plots[k].plot()
        eplt.title(k, fontdict = {'fontsize': 8})
    oldhang = eplt.isinteractive()
    eplt.interactive(not hang)
    eplt.show()
    eplt.interactive(oldhang)
    return figure, plots
Beispiel #2
0
def plot_data_dict(data_dict, plots = None, mode = 'static', hang = True, figure = None, size = None, **plot_preference_kwargs):
    """
    Make a plot of data in the format defined in data_dict
    :param data_dict: dict<str: plottable_data>
    :param plots: Optionally, a dict of <key: IPlot> identifying the plot objects to use (keys should
        be the same as those in data_dict).
    :return: The plots (same ones you provided if you provided them)
    """

    assert mode in ('live', 'static')
    if isinstance(data_dict, list):
        assert all(len(d) == 2 for d in data_dict), "You can provide data as a list of 2 tuples of (plot_name, plot_data)"
        data_dict = OrderedDict(data_dict)

    if plots is None:
        plots = {k: get_plot_from_data(v, mode = mode, **plot_preference_kwargs) for k, v in data_dict.items()}

    if figure is None:
        if size is not None:
            from pylab import rcParams
            rcParams['figure.figsize'] = size
        figure = plt.figure()
    n_rows, n_cols = vector_length_to_tile_dims(len(data_dict))
    for i, (k, v) in enumerate(data_dict.items()):
        plt.subplot(n_rows, n_cols, i + 1)
        plots[k].update(v)
        plots[k].plot()
        plt.title(k, fontdict = {'fontsize': 8})
    oldhang = plt.isinteractive()
    plt.interactive(not hang)
    plt.show()
    plt.interactive(oldhang)
    return figure, plots
def _create_subplot(fig=None, layout=None):

    if layout is None:
        layout = _newplot_settings['layout']
    if fig is None:
        fig = plt.gcf()
    n = len(fig.axes)
    n_rows, n_cols = (1, n+1) if layout in ('h', 'horizontal') else (n+1, 1) if layout in ('v', 'vertical') else \
        vector_length_to_tile_dims(n+1) if layout in ('g', 'grid') else bad_value(layout)
    for i in range(n):
        fig.axes[i].change_geometry(n_rows, n_cols, i + 1)
    ax = fig.add_subplot(n_rows, n_cols, n + 1)

    if not _newplot_settings['show_x']:
        ax.get_xaxis().set_visible(False)
    if not _newplot_settings['show_y']:
        ax.get_yaxis().set_visible(False)
    return ax
Beispiel #4
0
def _create_subplot(fig = None, layout = None, position = None, **subplot_args):

    if layout is None:
        layout = _newplot_settings['layout']
    if fig is None:
        fig = plt.gcf()
    n = len(fig.axes)
    n_rows, n_cols = (1, n+1) if layout in ('h', 'horizontal') else (n+1, 1) if layout in ('v', 'vertical') else \
        vector_length_to_tile_dims(n+1) if layout in ('g', 'grid') else bad_value(layout)
    for i in range(n):
        fig.axes[i].change_geometry(n_rows, n_cols, i+1)

    for arg in ('sharex', 'sharey'):
        if isinstance(_newplot_settings[arg], plt.Axes):
            subplot_args[arg]=_newplot_settings[arg]

    ax = fig.add_subplot(n_rows, n_cols, n+1, **subplot_args)

    if _newplot_settings['xlabel'] is not None:
        ax.set_xlabel(_newplot_settings['xlabel'])
    if _newplot_settings['ylabel'] is not None:
        ax.set_ylabel(_newplot_settings['ylabel'])

    if _newplot_settings['xlim'] is not None:
        ax.set_xlim(_newplot_settings['xlim'])
    if _newplot_settings['ylim'] is not None:
        ax.set_ylim(_newplot_settings['ylim'])

    if _newplot_settings['grid']:
        plt.grid()

    for arg in ('sharex', 'sharey'):
        if _newplot_settings[arg] is True:
            _newplot_settings[arg]=ax

    if not _newplot_settings['show_x']:
        ax.tick_params(axis='x', labelbottom='off')
        # ax.get_xaxis().set_visible(False)
    if not _newplot_settings['show_y']:
        ax.tick_params(axis='y', labelleft='off')
        # ax.get_yaxis().set_visible(False)
    return ax
Beispiel #5
0
def _extend_subplots(fig, subplot_name, plot_object):
    """
    :param fig: Name for figure to extend subplots on
    :param subplot_name: Name of the new subplot in that figure
    :param plot_object: The plotting object to display
    :return:
    """
    assert fig in _DBPLOT_FIGURES
    old_key_names = _DBPLOT_FIGURES[fig].subplots.keys()
    plt.figure(_DBPLOT_FIGURES[fig].figure.number)
    n_rows, n_cols = vector_length_to_tile_dims(len(old_key_names) + 1)
    gs = gridspec.GridSpec(n_rows, n_cols)
    for g, k in zip(
            gs, old_key_names
    ):  # (gs can be longer but zip will just go to old_key_names)
        ax = _DBPLOT_FIGURES[fig].subplots[k].axis
        ax.set_position(g.get_position(_DBPLOT_FIGURES[fig].figure))

    # Add the new plot
    ax = _DBPLOT_FIGURES[fig].figure.add_subplot(gs[len(old_key_names)])
    ax.set_title(subplot_name)
    _DBPLOT_FIGURES[fig].subplots[subplot_name] = _Subplot(
        axis=ax, plot_object=plot_object)