我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用matplotlib.pyplot.interactive()。
def analyze_lusolve(N): plt.clf() plt.interactive(True) I = InteractiveLUMatrix(N) plt.show(block=True) I.disconnect()
def interactive_matplotlib_context(on=True): old_mode = plt.isinteractive() plt.interactive(on) yield plt.interactive(old_mode)
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