def graph_from_function(ax, function, xmin, xmax, discr, xlabel="", ylabel="", marker=".", linestyle="solid", linewidth=1.5): """ Plot mathematic function Parameters ---------- ax : Axis the matplotlib axis object function : str the mathematic function xmin : int the x min xmax : int the x max discr : int the discretization of the interval between xmin and xmax xlabel : str the name of the x label ylabel : str the name of the y label marker : string the style of the marker to plot linestyle : string the style of the line to plot linewidth : float the width of the line to plot """ logger.log(logging.INFO, "[Graph] Graph from function") plots = [PlotCreator.get_instance().plot_from_function(function, xmin, xmax, discr, xlabel, ylabel)] plot(ax, plots, marker, linestyle, linewidth)
def graph_compare_plot_diff_from_fieldnames(ax, manager, x_fieldname, y_fieldnames, marker=".", linestyle="solid", linewidth=1.5): """ Plot the diff between two plots Parameters ---------- ax : Axis the matplotlib axis object manager : DataManager the data manager used to read data from csv file x_fieldname : str the fieldname of the x-axis variable to plot y_fieldnames : list(str) the list of fieldname of the y-axis variable to plot marker : string the style of the marker to plot linestyle : string the style of the line to plot linewidth : float the width of the line to plot """ plots = PlotCreator.get_instance().plot_from_fieldnames(manager, x_fieldname, y_fieldnames) if len(plots) == 2: graph_compare_plot_diff(ax, plots[0], plots[1], marker, linestyle, linewidth) else: logger.log(logging.ERROR, "[Graph] You can only compare two graphs (" + str(len(plots)) + " given)")
def graph_from_multiple_data(ax, x_data, y_datas, x_label, y_multiple_label, marker=".", linestyle="solid", linewidth=1.5): """ Plot data in a matplotlib object Parameters ---------- ax : Axis the matplotlib axis object x_data : list(int, float, ...) list of data (x-axis) y_datas : list(list(int, float, ...)) multiple list of data (y-axis) x_label : str the label of the x-axis y_multiple_label : str the list of label of the y-axis marker : string the style of the marker to plot linestyle : string the style of the line to plot linewidth : float the width of the line to plot """ logger.log(logging.INFO, "[Graph] Graph from multiple data") plots_to_display = PlotCreator.get_instance().plot_from_multiple_data(x_data, y_datas, x_label, y_multiple_label) plot(ax, plots_to_display, marker, linestyle, linewidth)
def compare_plots(self): """ Compare two plots in a graph """ plot_ids = [] for idx in self.__plot_list.curselection(): plot_ids.append(self.__plot_list.get(idx)) if len(plot_ids) == 2: plot1 = PlotCreator.get_instance().get_plot_from_stringify( plot_ids[0]) plot2 = PlotCreator.get_instance().get_plot_from_stringify( plot_ids[1]) if len(plot1.get_x()) == len(plot2.get_x()): PlotDialog(self.top, plot1, plot2, self.__marker_combo.get(), self.__line_combo.get(), float(self.__entry_line_width.get())) else: logger.log( logging.ERROR, "[PlotFrame] Plots do not have the same x interval") else: logger.log(logging.ERROR, "[PlotFrame] You can compare only two plots")
def create_plot_from_function(self): """ create plot from math functions """ logger.log( logging.INFO, "[FunctionDialog] Creating plot from math function " + self.__entry_function.get()) self.__plot = PlotCreator.get_instance().plot_from_function( self.__entry_function.get(), self.__entry_xmin.get(), self.__entry_xmax.get(), self.__entry_discr.get(), self.__entry_xlabel.get(), self.__entry_ylabel.get()) self.__plot.set_function(str(self.__entry_function.get())) self.quit()
def graph_from_function(ax, function_list, marker=".", linestyle="solid", linewidth=1.5): """ Plot data from fieldname in a matplotlib object Parameters ---------- ax : Axis the matplotlib axis object function_list : list(function) the list of function to plot marker : string the style of the marker to plot linestyle : string the style of the line to plot linewidth : float the width of the line to plot """ logger.log(logging.INFO, "[Graph] Graph from function") for func in function_list: function_to_plot = PlotCreator.get_instance().string_to_function(func.get_function()) ax.plot(func.get_interval(), function_to_plot(func.get_interval()), marker=marker, linestyle=linestyle, linewidth=linewidth)
def graph_from_fieldname(ax, manager, x_fieldname, y_fieldname, marker=".", linestyle="solid", linewidth=1.5): """ Plot data from fieldname in a matplotlib object Parameters ---------- ax : Axis the matplotlib axis object manager : DataManager the data manager used to read data from csv file x_fieldname : str the fieldname of the x-axis variable to plot y_fieldname : str the fieldname of the y-axis variable to plot marker : string the style of the marker to plot linestyle : string the style of the line to plot linewidth : float the width of the line to plot """ logger.log(logging.INFO, "[Graph] Graph from fieldname") plots = [PlotCreator.get_instance().plot_from_fieldname(manager, x_fieldname, y_fieldname)] plot(ax, plots, marker, linestyle, linewidth)
def graph_compare_plot_values_from_fieldnames(ax, manager, x_fieldname, y_fieldnames, threshold, on_graph): """ Plot the diff values between two plots Parameters ---------- ax : Axis the matplotlib axis object manager : DataManager the data manager used to read data from csv file x_fieldname : str the fieldname of the x-axis variable to plot y_fieldnames : list(str) the list of fieldname of the y-axis variable to plot threshold : the threshold for the display of the difference values on_graph : display the values on the graph or not """ plots = PlotCreator.get_instance().plot_from_fieldnames(manager, x_fieldname, y_fieldnames) if len(plots) == 2: graph_compare_plot_values(ax, plots[0], plots[1], threshold, on_graph) else: logger.log(logging.ERROR, "[Graph] You can only compare two graphs (" + str(len(plots)) + " given)")
def add_plot(self): """ Add_button action to add created plot in the list """ if len(self.__plot_frame) > 0: if self.__variable1_combo.get( ) != "" and self.__variable2_combo.get() != "": if self.__data_manager.manager_have_data(): plot = PlotCreator.get_instance().plot_from_fieldnames( self.__data_manager, self.__variable1_combo.get(), [self.__variable2_combo.get()]) logger.log(logging.INFO, "[MainFrame] Creating plot " + str(plot[0])) if self.__plot_frame_combo.get() == "all": for item in list(self.__plot_frame.values()): item.add_plot(plot[0]) else: self.__plot_frame[ self.__plot_frame_combo.get()].add_plot(plot[0]) else: logger.log(logging.ERROR, "[MainFrame] Data manager does not have data") else: logger.log(logging.ERROR, "[MainFrame] No variables selected") else: logger.log(logging.ERROR, "[MainFrame] No Plot frame opened")
def graph_from_plot_ids(ax, plot_ids, marker=".", linestyle="solid", linewidth=1.5): """ Plot list of plots from there ids in a matplotlib object Parameters ---------- ax : Axis the matplotlib axis object plot_ids : list(int) the list of plot ids marker : string the style of the marker to plot linestyle : string the style of the line to plot linewidth : float the width of the line to plot """ logger.log(logging.INFO, "[Graph] Graph from plot ids") plots_to_display = [] for plot_id in plot_ids: pattern = re.search('id=(.+?) ', plot_id) if pattern: found = int(pattern.group(1)) plots_to_display.append(PlotCreator.get_instance().get_plots_dict()[found]) plot(ax, plots_to_display, marker, linestyle, linewidth)