Icon

kn_​example_​python_​graphic_​violinplots_​grouped

KNIME & Python Graphics -Grouped violinplots with split violins - also export PNG to Excel

KNIME & Python Graphics -Grouped violinplots with split violins - also export PNG to Excel

adapted from: https://seaborn.pydata.org/examples/grouped_violinplots.html

KNIME & Python Graphics -Grouped violinplots with split violins - also export PNG to Exceladapted from: https://seaborn.pydata.org/examples/grouped_violinplots.html import knime.scripting.io as knio#Import Libraryfrom io import BytesIOimport osimport pandas as pdimport seaborn as snssns.set_theme(style="whitegrid")# https://seaborn.pydata.org/examples/grouped_violinplots.htmlinput_table = knio.input_tables[0].to_pandas()var_title = knio.flow_variables['title_graphic']var_footnote = knio.flow_variables['footnote_graphic']var_x_variable = knio.flow_variables['variable_x']var_x_label = knio.flow_variables['label_x']var_y_a_variable = knio.flow_variables['variable_y_a']var_y_a_label = knio.flow_variables['label_y_a']var_y_b_variable = knio.flow_variables['variable_y_b']var_y_b_label = knio.flow_variables['label_y_b']#define figure size# sns.set(rc={"figure.figsize":(16, 9)}) #width=8, height=4sns.set(rc={'figure.figsize':(16,9)})################################################### https://seaborn.pydata.org/examples/grouped_violinplots.html# Draw a nested violinplot and split the violins for easier comparisong = sns.violinplot(data=input_table, x=var_x_variable, y=var_y_a_variable, hue=var_y_b_variable, split=True, inner="quart", linewidth=1, palette={"Yes": "b", "No": ".85"})sns.despine(left=True)g.set(xlabel=var_x_label, ylabel=var_y_a_label, title=var_title)##################################################fig_out = g.get_figure()fig_out.set_size_inches(16, 9)fig_out.text(0.1, 0.05, var_footnote ,fontsize=10)#add overall title# g.fig.suptitle(var_title)# Create buffer to write intobuffer = BytesIO()# Create plot and write it into the bufferfig_out.savefig(buffer, format='svg')# The output is the content of the bufferoutput_image = buffer.getvalue()knio.output_images[0] = output_image # create flow variable named random with 0 <= value <= 100import knime.scripting.io as knio# place the PNG file into an Excel file# https://stackoverflow.com/a/15483814import openpyxlvar_image_path = knio.flow_variables['context.workflow.data-path'] +"from_knime_violinplot_grouped.png"var_excel_path = knio.flow_variables['context.workflow.data-path'] +"from_knime_violinplot_grouped.xlsx"wb = openpyxl.Workbook()ws = wb.worksheets[0]img = openpyxl.drawing.image.Image(var_image_path)img.anchor = 'A1'ws.add_image(img)wb.save(var_excel_path) locate and create/data/ folderwith absolute paths1.920 x 1.080PNG filefrom_knime_violinplot_grouped.pngtips.parquetknio.flow_variables['var_py_version_pandas'] = pd.__version__knio.flow_variables['var_py_version_numpy'] = np.__version__knio.flow_variables['var_py_version'] = sys.version_infoknio.flow_variables['var_sys_path'] = sys.pathright mouse clickto set the parametersvar_*https://stackoverflow.com/a/15483814Export the PNG file to Excel Collect LocalMetadata Image To Table Renderer to Image Table To Image Image Writer (Port) Parquet Reader Python Script Python graphics - Groupedviolinplots with split violins Variable toTable Row Python Script Merge Variables KNIME & Python Graphics -Grouped violinplots with split violins - also export PNG to Exceladapted from: https://seaborn.pydata.org/examples/grouped_violinplots.html import knime.scripting.io as knio#Import Libraryfrom io import BytesIOimport osimport pandas as pdimport seaborn as snssns.set_theme(style="whitegrid")# https://seaborn.pydata.org/examples/grouped_violinplots.htmlinput_table = knio.input_tables[0].to_pandas()var_title = knio.flow_variables['title_graphic']var_footnote = knio.flow_variables['footnote_graphic']var_x_variable = knio.flow_variables['variable_x']var_x_label = knio.flow_variables['label_x']var_y_a_variable = knio.flow_variables['variable_y_a']var_y_a_label = knio.flow_variables['label_y_a']var_y_b_variable = knio.flow_variables['variable_y_b']var_y_b_label = knio.flow_variables['label_y_b']#define figure size# sns.set(rc={"figure.figsize":(16, 9)}) #width=8, height=4sns.set(rc={'figure.figsize':(16,9)})################################################### https://seaborn.pydata.org/examples/grouped_violinplots.html# Draw a nested violinplot and split the violins for easier comparisong = sns.violinplot(data=input_table, x=var_x_variable, y=var_y_a_variable, hue=var_y_b_variable, split=True, inner="quart", linewidth=1, palette={"Yes": "b", "No": ".85"})sns.despine(left=True)g.set(xlabel=var_x_label, ylabel=var_y_a_label, title=var_title)##################################################fig_out = g.get_figure()fig_out.set_size_inches(16, 9)fig_out.text(0.1, 0.05, var_footnote ,fontsize=10)#add overall title# g.fig.suptitle(var_title)# Create buffer to write intobuffer = BytesIO()# Create plot and write it into the bufferfig_out.savefig(buffer, format='svg')# The output is the content of the bufferoutput_image = buffer.getvalue()knio.output_images[0] = output_image # create flow variable named random with 0 <= value <= 100import knime.scripting.io as knio# place the PNG file into an Excel file# https://stackoverflow.com/a/15483814import openpyxlvar_image_path = knio.flow_variables['context.workflow.data-path'] +"from_knime_violinplot_grouped.png"var_excel_path = knio.flow_variables['context.workflow.data-path'] +"from_knime_violinplot_grouped.xlsx"wb = openpyxl.Workbook()ws = wb.worksheets[0]img = openpyxl.drawing.image.Image(var_image_path)img.anchor = 'A1'ws.add_image(img)wb.save(var_excel_path) locate and create/data/ folderwith absolute paths1.920 x 1.080PNG filefrom_knime_violinplot_grouped.pngtips.parquetknio.flow_variables['var_py_version_pandas'] = pd.__version__knio.flow_variables['var_py_version_numpy'] = np.__version__knio.flow_variables['var_py_version'] = sys.version_infoknio.flow_variables['var_sys_path'] = sys.pathright mouse clickto set the parametersvar_*https://stackoverflow.com/a/15483814Export the PNG file to Excel Collect LocalMetadata Image To Table Renderer to Image Table To Image Image Writer (Port) Parquet Reader Python Script Python graphics - Groupedviolinplots with split violins Variable toTable Row Python Script Merge Variables

Nodes

Extensions

Links