def _replot_mpl_curve(ax, curve, plot_kwargs): """ Replot the given matplotlib curve with new kwargs :param ax: The axis that the curve will be plotted on :param curve: The curve that will be replotted :param plot_kwargs: Kwargs for the plot that will be passed onto matplotlib """ remove_curve_from_ax(curve) if isinstance(curve, Line2D): [ plot_kwargs.pop(arg, None) for arg in ['capsize', 'capthick', 'ecolor', 'elinewidth', 'errorevery'] ] new_curve = ax.plot(curve.get_xdata(), curve.get_ydata(), **plot_kwargs)[0] elif isinstance(curve, ErrorbarContainer): # Because of "error every" option, we need to store the original # error bar data on the curve or we will lose data on re-plotting x, y, xerr, yerr = getattr(curve, 'errorbar_data', get_data_from_errorbar_container(curve)) new_curve = ax.errorbar(x, y, xerr=xerr, yerr=yerr, **plot_kwargs) setattr(new_curve, 'errorbar_data', [x, y, xerr, yerr]) else: raise ValueError( "Curve must have type 'Line2D' or 'ErrorbarContainer'. Found '{}'" .format(type(curve))) return new_curve
def remove_selected_curves(self): """ Remove selected curves from figure and curves list. If there are no curves left on the axes remove that axes from the axes combo box """ ax = self.get_selected_ax() if ax.legend_: self.legend_props = LegendProperties.from_legend(ax.legend_) # Remove curves from ax and remove from curve names dictionary curves_to_remove_names = self.view.get_selected_curves_names() for name in curves_to_remove_names: remove_curve_from_ax(self.curve_names_dict[name]) self.curve_names_dict.pop(name) self.set_apply_to_all_buttons_enabled() ax = self.get_selected_ax() # Update the legend and redraw FigureErrorsManager.update_limits_and_legend(ax, self.legend_props) ax.figure.canvas.draw() # Remove the curve from the curve selection list if self.remove_selected_curve_list_entry(): return self.update_view()
def remove_selected_curve(self): """ Remove selected curve from figure and combobox. If there are no curves left on the axes remove that axes from the axes combo box """ ax = self.get_selected_ax() if ax.legend_: self.legend_props = LegendProperties.from_legend(ax.legend_) waterfall = False if isinstance(ax, MantidAxes): waterfall = ax.is_waterfall() if waterfall: # Waterfall plots are reset so they can be reconverted after the curve is removed. x, y = ax.waterfall_x_offset, ax.waterfall_y_offset ax.update_waterfall(0, 0) # If the curves have a fill, the one which corresponds to the curve being removed also needs to be removed. current_curve_index = self.view.select_curve_combo_box.currentIndex( ) i = 0 for collection in ax.collections: if isinstance(collection, PolyCollection): if current_curve_index == i: ax.collections.remove(collection) break i = i + 1 # Remove curve from ax and remove from curve names dictionary remove_curve_from_ax(self.get_selected_curve()) self.curve_names_dict.pop(self.view.get_selected_curve_name()) self.set_apply_to_all_buttons_enabled() # If there is now only one curve on a waterfall plot, the plot becomes non-waterfall. if waterfall: ax.update_waterfall(x, y) if len(ax.get_lines()) <= 1: ax.set_waterfall(False) ax = self.get_selected_ax() # Update the legend and redraw FigureErrorsManager.update_limits_and_legend(ax, self.legend_props) ax.figure.canvas.draw() # Remove the curve from the curve selection combo box if self.remove_selected_curve_combo_box_entry(): return self.update_view()
def remove_selected_curve(self): """ Remove selected curve from figure and combobox. If there are no curves left on the axes remove that axes from the axes combo box """ # Remove curve from ax and remove from curve names dictionary remove_curve_from_ax(self.get_selected_curve()) self.curve_names_dict.pop(self.view.get_selected_curve_name()) ax = self.get_selected_ax() # Update the legend and redraw self.update_limits_and_legend(ax) ax.figure.canvas.draw() # Remove the curve from the curve selection combo box if self.remove_selected_curve_combo_box_entry(): return self.update_view()
def remove_selected_curve(self): """ Remove selected curve from figure and combobox. If there are no curves left on the axes remove that axes from the axes combo box """ ax = self.get_selected_ax() if ax.legend_: self.legend_props = LegendProperties.from_legend(ax.legend_) # Remove curve from ax and remove from curve names dictionary remove_curve_from_ax(self.get_selected_curve()) self.curve_names_dict.pop(self.view.get_selected_curve_name()) self.set_apply_to_all_buttons_enabled() ax = self.get_selected_ax() # Update the legend and redraw self.update_limits_and_legend(ax, self.legend_props) ax.figure.canvas.draw() # Remove the curve from the curve selection combo box if self.remove_selected_curve_combo_box_entry(): return self.update_view()
def replot_curve(ax, curve, plot_kwargs): """Replot the given curve with new kwargs""" remove_curve_from_ax(curve) if isinstance(curve, Line2D): [plot_kwargs.pop(arg, None) for arg in ['capsize', 'capthick', 'ecolor', 'elinewidth', 'errorevery']] new_curve = ax.plot(curve.get_xdata(), curve.get_ydata(), **plot_kwargs)[0] elif isinstance(curve, ErrorbarContainer): # Because of "error every" option, we need to store the original # errorbar data on the curve or we will lose data on re-plotting x, y, xerr, yerr = getattr(curve, 'errorbar_data', get_data_from_errorbar_container(curve)) new_curve = ax.errorbar(x, y, xerr=xerr, yerr=yerr, **plot_kwargs) setattr(new_curve, 'errorbar_data', [x, y, xerr, yerr]) else: raise ValueError("Curve must have type 'Line2D' or " "'ErrorbarContainer'. Found '{}'" "".format(type(curve))) ax.relim() ax.autoscale() return new_curve