How to use _create_figure method in autotest

Best Python code snippet using autotest_python

plotter.py

Source:plotter.py Github

copy

Full Screen

...21 for plot_name, figure_ in self.plots.items():22 target_file_name = f'{plot_name}.{self.file_extension}'23 target_file_path = f'{self.target_directory}/{target_file_name}'24 figure_.savefig(target_file_path, dpi=150)25 def _create_figure(self) -> tuple[Figure, Axes]:26 figure_ = figure(figsize=self.figure_size)27 figure_.set_tight_layout('True')28 axis = figure_.add_subplot()29 return figure_, axis30 @abstractmethod31 def create_plots(self):32 pass33class LinePlotter(Plotter, ABC):34 def _create_figure(self) -> tuple[Figure, Axes]:35 figure_, axis = super()._create_figure()36 axis.xaxis.set_major_locator(MaxNLocator(integer=True))37 return figure_, axis38 @abstractmethod39 def create_plots(self):40 pass41class ClientLearningPlotter(LinePlotter):42 def __init__(self, metrics_collector: MetricsCollector):43 super().__init__(metrics_collector)44 self.target_directory = f'{generated_data_path.plots}/learning_plots'45 def create_plots(self):46 for client_id, client_metrics in self.metrics_collector.clients_metrics.items():47 client_accuracy_plot_name = f'client_{client_id}_accuracy_plot'48 client_loss_plot_name = f'client_{client_id}_loss_plot'49 self.plots[client_accuracy_plot_name] = self.__create_client_accuracy_plot(client_id, client_metrics)50 self.plots[client_loss_plot_name] = self.__create_client_loss_plot(client_id, client_metrics)51 all_clients_accuracy_plot_name = f'clients_accuracy_comparison_plot'52 all_clients_loss_plot_name = f'clients_loss_comparison_plot'53 self.plots[all_clients_accuracy_plot_name] = self.__create_all_clients_accuracy_comparison()54 self.plots[all_clients_loss_plot_name] = self.__create_all_clients_loss_comparison()55 def __create_client_accuracy_plot(self, client_id: int, client_metrics: ClientMetrics) -> Figure:56 figure_, axis = self._create_figure()57 accuracy_line = axis.plot(client_metrics.iterations, client_metrics.accuracy,58 label='Funkcja dokładności uczenia')59 val_accuracy_line = axis.plot(client_metrics.iterations, client_metrics.val_accuracy,60 label='Funkcja dokładności walidacji')61 axis.set_title(f'Wykres dokładności (ang. accuracy) procesu uczenia modelu dla klienta \n'62 f'o identyfikatorze "{client_id}"')63 axis.set_xlabel('Iteracje')64 axis.set_ylabel('Dokładność modelu')65 axis.grid(True)66 axis.legend(handles=[*accuracy_line, *val_accuracy_line], loc='upper left')67 return figure_68 def __create_client_loss_plot(self, client_id: int, client_metrics: ClientMetrics) -> Figure:69 figure_, axis = self._create_figure()70 loss_line = axis.plot(client_metrics.iterations, client_metrics.loss, label='Funkcja strat uczenia')71 val_loss_line = axis.plot(client_metrics.iterations, client_metrics.val_loss, label='Funkcja strat walidacji')72 axis.set_title(f'Wykres strat (ang. loss) procesu uczenia modelu dla klienta \n'73 f'o identyfikatorze "{client_id}"')74 axis.set_xlabel('Iteracje')75 axis.set_ylabel('Wartosc funkcji strat')76 axis.grid(True)77 axis.legend(handles=[*loss_line, *val_loss_line], loc='upper right')78 return figure_79 def __create_all_clients_accuracy_comparison(self):80 figure_, axis = self._create_figure()81 accuracy_lines = []82 for client_id, client_metrics in self.metrics_collector.clients_metrics.items():83 accuracy_lines.append(axis.plot(client_metrics.iterations, client_metrics.val_accuracy,84 label=f'Model klienta o id "{client_id}"'))85 axis.set_title(f'Wykres dokładności (ang. accuracy) procesu uczenia modelu dla \nwszystkich klientów.')86 axis.set_xlabel('Iteracje')87 axis.set_ylabel('Dokładność modelu')88 axis.grid(True)89 axis.legend(handles=[line[0] for line in accuracy_lines], loc='upper left')90 return figure_91 def __create_all_clients_loss_comparison(self):92 figure_, axis = self._create_figure()93 loss_lines = []94 for client_id, client_metrics in self.metrics_collector.clients_metrics.items():95 loss_lines.append(axis.plot(client_metrics.iterations, client_metrics.val_loss,96 label=f'Model klienta o id "{client_id}"'))97 axis.set_title(f'Wykres strat (ang. loss) procesu uczenia modelu dla \nwszystkich klientów.')98 axis.set_xlabel('Iteracje')99 axis.set_ylabel('Wartosc funkcji strat')100 axis.grid(True)101 axis.legend(handles=[line[0] for line in loss_lines], loc='upper right')102 return figure_103class TraditionalParticipantLearningPlotter(LinePlotter):104 def __init__(self, metrics_collector: MetricsCollector):105 super().__init__(metrics_collector)106 self.target_directory = f'{generated_data_path.plots}/learning_plots'107 def create_plots(self):108 metrics = self.metrics_collector.traditional_participant_training_metrics109 client_accuracy_plot_name = f'{metrics.full_name}_accuracy_plot'110 client_loss_plot_name = f'client_{metrics.full_name}_loss_plot'111 self.plots[client_accuracy_plot_name] = self._create_accuracy_plot(metrics)112 self.plots[client_loss_plot_name] = self._create_loss_plot(metrics)113 def _create_accuracy_plot(self, metrics: TraditionalParticipantTrainingMetrics) -> Figure:114 figure_, axis = self._create_figure()115 accuracy_line = axis.plot(metrics.iterations, metrics.accuracy, label='Funkcja dokładności uczenia')116 val_accuracy_line = axis.plot(metrics.iterations, metrics.val_accuracy, label='Funkcja dokładności walidacji')117 axis.set_title(f'Wykres dokładności (ang. accuracy) procesu uczenia')118 axis.set_xlabel('Iteracje')119 axis.set_ylabel('Dokładność modelu')120 axis.grid(True)121 axis.legend(handles=[*accuracy_line, *val_accuracy_line], loc='upper left')122 return figure_123 def _create_loss_plot(self, metrics: TraditionalParticipantTrainingMetrics) -> Figure:124 figure_, axis = self._create_figure()125 loss_line = axis.plot(metrics.iterations, metrics.loss, label='Funkcja strat uczenia')126 val_loss_line = axis.plot(metrics.iterations, metrics.val_loss, label='Funkcja strat walidacji')127 axis.set_title(f'Wykres strat (ang. loss) procesu uczenia')128 axis.set_xlabel('Iteracje')129 axis.set_ylabel('Wartosc funkcji strat')130 axis.grid(True)131 axis.legend(handles=[*loss_line, *val_loss_line], loc='upper right')132 return figure_133class ServerTestingPlotter(LinePlotter):134 def __init__(self, metrics_collector: MetricsCollector):135 super(ServerTestingPlotter, self).__init__(metrics_collector)136 self.server_metrics = self.metrics_collector.server_metrics137 self.target_directory = f'{generated_data_path.plots}/learning_plots'138 def create_plots(self):139 figure_, axis = self._create_figure()140 accuracy_line = axis.plot(self.server_metrics.iterations, self.server_metrics.accuracy,141 label='Funkcja dokładności')142 loss_line = axis.plot(self.server_metrics.iterations, self.server_metrics.loss, label='Funkcja strat')143 axis.set_title(f'Wykres dokładności (ang. accuracy) oraz strat (ang. loss) \ndla modelu globalnego')144 axis.set_xlabel('Iteracje')145 axis.set_ylabel('Wartość')146 axis.grid(True)147 axis.legend(handles=[*accuracy_line, *loss_line], loc='upper left')148 self.plots['server_accuracy_and_loss'] = figure_149class ConfusionMatrixMaker(Plotter):150 def __init__(self, metrics_collector: MetricsCollector):151 super(ConfusionMatrixMaker, self).__init__(metrics_collector)152 self.target_directory = f'{generated_data_path.plots}/confusion_matrixes'153 self.font_scale = 2.2154 self.figure_size = (6, 6)155 self.font_size = 22156 def create_plots(self):157 for participant, predictions in self.metrics_collector.predictions.items():158 classes = participant.dataset_used_for_predictions.classes159 number_of_classes = len(classes)160 matrix = confusion_matrix(predictions.max_label, predictions.predicted_max_label)161 self.figure_size = 2 * (2 * number_of_classes,)162 figure_, axis = self._create_figure()163 box_labels = self.__get_box_labels(matrix, number_of_classes)164 heat_map = heatmap(matrix, cmap='Blues', linecolor='black', linewidths=1, xticklabels=classes,165 yticklabels=classes, annot=box_labels, fmt='', cbar=False,166 annot_kws={"size": self.font_size},)167 heat_map.set_xticklabels(labels=heat_map.get_xticklabels(), fontsize=self.font_size)168 heat_map.set_yticklabels(labels=heat_map.get_yticklabels(), fontsize=self.font_size)169 if isinstance(participant, Server):170 axis.set_title(f'Macierz pomyłek dla modelu globalnego')171 elif isinstance(participant, Client):172 axis.set_title(f'Macierz pomyłek dla klienta o identyfikatorze "{participant.id}"')173 else:174 axis.set_title(f'Macierz pomyłek')175 axis.title.set_fontsize(self.font_size)176 axis.set_xlabel('Klasa prawdziwa', fontsize=self.font_size)...

Full Screen

Full Screen

tay_plots.py

Source:tay_plots.py Github

copy

Full Screen

...65 else:66 y_vals = [_number_from_token(n, value_index) for n in tokens[1:]]67 c, f, l = _format_and_label(label, radius, all_lines, dataset)68 plt.plot(x_vals, y_vals, f, color=c, label=l)69def _create_figure(out_filename, in_filenames, value_index, value_label, plot_see_radii, plot_structures, ylim, all_lines):70 fig = plt.figure(figsize=(7, 3.2))71 ax = plt.axes()72 plt.xlabel("Depth correction")73 plt.ylabel(value_label)74 dataset = 075 for in_filename in in_filenames:76 _create_plots_from_file(in_filename,77 out_filename=out_filename,78 value_index=value_index,79 value_label=value_label,80 plot_see_radii=plot_see_radii,81 plot_structures=plot_structures,82 all_lines=all_lines,83 dataset=dataset)84 dataset += 185 if ylim is not None:86 plt.ylim([0, ylim])87 plt.gca().xaxis.set_major_locator(mticker.MultipleLocator(1))88 plt.legend(bbox_to_anchor=(1, 1), loc="upper left");89 plt.tight_layout()90 plt.show()91 # fig.savefig('%s.png' % out_filename)92# _create_figure('plot1', ['plot_uniform_runtimes'], 0, 'Milliseconds per step', [0], ['CpuSimple', 'CpuGrid'], None, False)93# _create_figure('plot2', ['plot_uniform_runtimes'], 0, 'Milliseconds per step', [2], ['CpuSimple', 'CpuGrid'], None, True)94# _create_figure('plot3', ['plot_uniform_runtimes'], 0, 'Milliseconds per step', [0, 1, 2], ['CpuTree'], 300, False)95# _create_figure('plot4', ['plot_uniform_runtimes'], 0, 'Milliseconds per step', [0, 1, 2], ['CpuTree', 'CpuGrid'], 100, False)96# _create_figure('plot5', ['plot_uniform_runtimes'], 0, 'Milliseconds per step', [0, 1, 2], ['CpuGrid', 'GpuSimple (direct)'], 100, False)97# _create_figure('plot6', ['plot_uniform_runtimes'], 0, 'Milliseconds per step', [0, 1, 2], ['GpuSimple (direct)', 'GpuSimple (indirect)'], None, False)98# _create_figure('plot7', ['plot_uniform_telemetry'], 3, 'Narrow / broad phase ratio (%)', [0, 1, 2], ['CpuSimple', 'CpuTree', 'CpuGrid'], None, False)99# _create_figure('plot8', ['plot_uniform_telemetry'], 0, 'Thread unbalancing (%)', [0, 1, 2], ['CpuSimple', 'CpuTree', 'CpuGrid'], None, False)100# _create_figure('plot9', ['plot_uniform_runtimes', 'plot_clump_runtimes'], 0, 'Milliseconds per step', [0], ['CpuGrid', 'CpuTree'], None, False)...

Full Screen

Full Screen

make_graphs.py

Source:make_graphs.py Github

copy

Full Screen

...3import matplotlib.pyplot as plt4def _load_df():5 df = pd.read_csv("internet_speeds_dataset.csv", index_col="Date")6 return df7def _create_figure(df, col_name, fig_num, title=None):8 plt.figure(fig_num)9 if title is not None:10 plt.title(title)11 else:12 plt.title(f"{col_name} over Time")13 plt.ylabel(col_name)14 df[col_name].plot()15 plt.xticks(rotation=90)16 plt.show(block=False)17def draw_graphs():18 df = _load_df()19 print(df.columns)20 _create_figure(df, "Download (Mb/s)", 1)21 _create_figure(df, "Upload (Mb/s)", 2)22 plt.show(block=True)23if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful