Best Python code snippet using autotest_python
make_plots.py
Source:make_plots.py
...58 dataset_to_disease_abv(x)59 for x in df['dge']60 ]61 return df62def handle_plot(bp, xloc, yloc, legend_title, use_ncol=False):63 bp.set_xlabel("")64 ylabel = bp.get_ylabel()65 bp.set_ylabel("AUC-ROC" if ylabel == 'auc' else "AUC-PR")66 handles, labels = bp.get_legend_handles_labels()67 bp.legend(68 handles,69 labels,70 ncol=len(labels) if use_ncol else 1,71 loc=(xloc, yloc),72 title=legend_title73 )74 bp.set_xticklabels(75 bp.get_xticklabels(),76 rotation=3077 )78def main():79 """"""80 thiner = 0.581 subfolder = 'part1'82 results = get_dataframe(os.path.join(results_base_folder, subfolder))83 results['eval'] = [change_labels[x] for x in results['eval']]84 results['sort2'] = [85 0 if x == 'STRING' else 2 if x == 'BEL' else 186 for x in results['eval']87 ]88 results = results.sort_values(by=['sort1', 'sort2', 'dge_relabel'])89 # Prepare results90 for metric in ['auc', 'aps']:91 for key, datasets in DGE_DATASETS.items():92 bp = sns.boxplot(93 data=results[results['dge'].isin(datasets)],94 x='dge_relabel',95 y=metric,96 hue='eval',97 width=thiner if key == 'nonad' else 198 )99 handle_plot(bp, 0.1, 0.45, 'Network')100 fig = bp.get_figure()101 fig.tight_layout()102 fig.savefig(os.path.join(results_base_folder, f'compare1_{metric}_{key}.png')) # AUC non-AD and AD103 plt.close()104 subfolder = 'part3' # Weighting105 results = get_dataframe(os.path.join(results_base_folder, subfolder))106 results['eval'] = [107 'Yes' if x == 'weighted' else 'No'108 for x in results['eval']109 ]110 results = results.sort_values(by=['sort1', 'dge_relabel', 'eval'])111 # Prepare results112 for metric in ['auc', 'aps']:113 bp = sns.boxplot(114 data=results,115 x='dge_relabel',116 y=metric,117 hue='eval',118 width=thiner119 )120 handle_plot(bp, 0.05, 0.3, 'Weighting')121 fig = bp.get_figure()122 fig.tight_layout()123 fig.subplots_adjust(left=0.07)124 fig.set_size_inches(12.8, 4.8)125 fig.savefig(os.path.join(results_base_folder, f'compare4_{metric}.png')) # AUC non-AD and AD126 plt.close()127 subfolder = 'part4' # g2v128 results = get_dataframe(os.path.join(results_base_folder, subfolder))129 results = results.sort_values(by=['sort1', 'dge_relabel', 'eval'])130 # Prepare results131 for metric in ['auc', 'aps']:132 for analyzed_param in set(results['param']):133 colors = sns.color_palette()134 # swap blue to the default g2v param135 # dim = 128, nw = 10, wl = 80, ws = 5136 if analyzed_param in ['Dimension', 'Walk Length']:137 (colors[0], colors[2]) = (colors[2], colors[0])138 elif analyzed_param in ['Num Walks', 'Window Size']:139 (colors[0], colors[1]) = (colors[1], colors[0])140 bp = sns.boxplot(141 data=results[results['param'] == analyzed_param],142 x='dge_relabel',143 y=metric,144 hue='eval',145 palette=colors146 )147 handle_plot(bp, 0.01, 0.05, analyzed_param, use_ncol=True)148 fig = bp.get_figure()149 fig.tight_layout()150 fig.subplots_adjust(left=0.07)151 fig.set_size_inches(12.8, 4.8)152 param = ''.join(analyzed_param.split(' '))153 fig.savefig(os.path.join(results_base_folder, f'compare5_{metric}_{param}.png')) # AUC non-AD and AD154 plt.close()155 subfolder = 'part6'156 results = get_dataframe(os.path.join(results_base_folder, subfolder))157 results['eval'] = [158 'Yes' if x == 'phewas' else 'No'159 for x in results['eval']160 ]161 results['dge_relabel'] = [change_labels[x] for x in results['dge']]162 results = results.sort_values(by=['sort1', 'dge_relabel', 'eval'])163 # Prepare results164 for metric in ['auc', 'aps']:165 bp = sns.boxplot(166 data=results,167 x='dge_relabel',168 y=metric,169 hue='eval',170 width=thiner171 )172 handle_plot(bp, 0.1, 0.3, 'Using PheWAS')173 fig = bp.get_figure()174 fig.tight_layout()175 fig.subplots_adjust(left=0.07)176 fig.set_size_inches(12.8, 4.8)177 fig.savefig(os.path.join(results_base_folder, f'compare2_{metric}.png')) # AUC non-AD and AD178 plt.close()179 subfolder = 'part2'180 results = get_dataframe(os.path.join(results_base_folder, subfolder))181 results['sort2'] = [182 0 if x == 'cv' else 1 if x == 'nested_cv' else 2183 for x in results['eval']184 ]185 results['eval'] = [186 'Logistic regression' if x == 'cv' else 'Nested logistic regression' if x == 'nested_cv' else 'Biased SVM'187 for x in results['eval']188 ]189 results['dge_relabel'] = [change_labels[x] for x in results['dge']]190 results = results.sort_values(by=['sort1', 'dge_relabel', 'sort2'])191 # Prepare results192 for metric in ['auc', 'aps']:193 bp = sns.boxplot(194 data=results,195 x='dge_relabel',196 y=metric,197 hue='eval',198 width=thiner + 0.1199 )200 handle_plot(bp, 0.01, 0.01, 'Classification')201 fig = bp.get_figure()202 fig.tight_layout()203 fig.subplots_adjust(left=0.07)204 fig.set_size_inches(12.8, 4.8)205 fig.savefig(os.path.join(results_base_folder, f'compare3_{metric}.png')) # AUC non-AD and AD206 plt.close()207 subfolder = 'link_prediction' # Link prediction208 results = get_dataframe(os.path.join(results_base_folder, subfolder))209 results['eval'] = [210 'Yes' if x else 'No'211 for x in results['eval']212 ]213 results = results.sort_values(by=['sort1', 'dge_relabel', 'eval'])214 # Prepare results215 for metric in ['auc', 'aps']:216 bp = sns.boxplot(217 data=results,218 x='dge_relabel',219 y=metric,220 hue='eval',221 width=thiner222 )223 handle_plot(bp, 0.05, 0.3, 'Use DGE')224 fig = bp.get_figure()225 fig.tight_layout()226 fig.subplots_adjust(left=0.07)227 fig.set_size_inches(12.8, 4.8)228 fig.savefig(os.path.join(results_base_folder, f'compare7_{metric}.png')) # AUC non-AD and AD229 plt.close()230 subfolder = 'link_prediction' # Link prediction vs OpenTargets231 results = get_dataframe(os.path.join(results_base_folder, subfolder))232 ot_results = pd.read_csv(os.path.join(results_base_folder, 'ot_target_prediction.tsv'), sep='\t')233 ot_results['dge_relabel'] = [change_labels[x] for x in ot_results['dge']]234 ot_results['eval'] = 'OpenTargets'235 ot_results['tr'] = 0236 ot_results['sort1'] = [237 dataset_to_disease_abv(x)238 for x in ot_results['dge']239 ]240 results = results[results['eval']]241 results['eval'] = 'Link Prediction'242 results = results.append(ot_results, ignore_index=False, sort=True)243 results = results.sort_values(by=['sort1', 'dge_relabel', 'eval'])244 # Prepare results245 for metric in ['auc', 'aps']:246 bp = sns.boxplot(247 data=results,248 x='dge_relabel',249 y=metric,250 hue='eval',251 width=thiner252 )253 handle_plot(bp, 0.005, 0.4, 'Method')254 fig = bp.get_figure()255 fig.tight_layout()256 fig.subplots_adjust(left=0.07)257 fig.set_size_inches(12.8, 4.8)258 fig.savefig(os.path.join(results_base_folder, f'compare7_vs_ot_{metric}.png')) # AUC non-AD and AD259 plt.close()260 subfolder = 'link_prediction2' # Link 5fcv261 results = get_dataframe(os.path.join(results_base_folder, subfolder))262 results = results.sort_values(by=['sort1', 'dge_relabel', 'eval'])263 relabel_param = {264 'd': 'Dimension',265 'wl': 'Walk Length',266 'nw': 'Number of Walks',267 'ws': 'Window size'268 }269 results['param'] = [270 relabel_param[x]271 for x in results['param']272 ]273 # Prepare results274 for metric in ['auc', 'aps']:275 for analyzed_param in set(results['param']):276 default_color = sns.color_palette()[0]277 colors = sns.color_palette("ch:2.5,-.2,dark=.3")278 # Assign blue to the default g2v param279 # dim = 128, nw = 10, wl = 80, ws = 5280 if analyzed_param in ['Dimension', 'Walk Length']:281 colors[2] = default_color282 elif analyzed_param in ['Number of Walks', 'Window size']:283 colors[1] = default_color284 bp = sns.boxplot(285 data=results[results['param'] == analyzed_param],286 x='dge_relabel',287 y=metric,288 hue='eval',289 palette=colors290 )291 handle_plot(bp, 0.01, 0.05, analyzed_param, use_ncol=True)292 fig = bp.get_figure()293 fig.tight_layout()294 fig.subplots_adjust(left=0.07)295 fig.set_size_inches(12.8, 4.8)296 param = ''.join(analyzed_param.split(' '))297 fig.savefig(os.path.join(results_base_folder, f'compare7g2v_{metric}_{param}.png')) # AUC non-AD and AD298 plt.close()299 subfolder = 'link_prediction3' # Link prediction vs OpenTargets300 sns.color_palette("muted")301 results = get_dataframe(os.path.join(results_base_folder, subfolder))302 results['dge_relabel'] = [change_labels[x] for x in results['dge']]303 results['eval'] = [304 'Yes' if x else 'No'305 for x306 in results['eval']307 ]308 results = results.sort_values(by=['sort1', 'dge_relabel', 'eval'])309 # Prepare results310 for metric in ['auc', 'aps']:311 bp = sns.boxplot(312 data=results,313 x='dge_relabel',314 y=metric,315 hue='eval',316 width=thiner317 )318 handle_plot(bp, 0.005, 0.4, 'Use DGE')319 fig = bp.get_figure()320 fig.tight_layout()321 fig.subplots_adjust(left=0.07)322 fig.set_size_inches(12.8, 4.8)323 fig.savefig(os.path.join(results_base_folder, f'compare7cv_{metric}.png')) # AUC non-AD and AD324 plt.close()325if __name__ == '__main__':...
sps.py
Source:sps.py
...10#common11def handle_connection(request_str : str):12 req = json.loads(request_str)13 if req.get("req_type") == "plot&data":14 handle_plot(req)15#plot16def handle_plot(request):17 fig = plt.figure(1)18 plt.plot(19 request.get("plot_spe").get("data"),20 figure = fig21 )22 plt.draw()23 plt.pause(0.001)24## plot utility25#simple plot26def plot(data,title='',x_axis_label='',y_axis_label=''):27 dataOut = {28 "req_type" : "plot&data",29 "plot_spe" : {30 "data" : data,...
plotter.py
Source:plotter.py
...18 #plt.legend(loc=0)19 20 plt.draw()21 22def handle_plot(req):23 t = time.time()24 plt.clf()25 ax = plt.subplot(111)26 plt.subplots_adjust(top=0.6)27 for plot_data in req.plots:28 plot(plot_data)29 labels = [line.get_label() for line in ax.lines]30 plt.figlegend(ax.lines, labels, 'upper right')31 plt.savefig(location + str(t) + '.png')32 33 return PlotResponse()34def plot_server():35 rospy.init_node('plotter')36 s = rospy.Service('plot', Plot, handle_plot)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!