Icon

kn_​example_​python_​graphic_​histogram_​trivariate_​two_​categories

KNIME & Python Graphics - Trivariate histogram with two categorical variables with Seaborn

KNIME & Python Graphics - Trivariate histogram with two categorical variables with Seaborn

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

KNIME & Python Graphics - Trivariate histogram with two categorical variables with Seabornadapted from: https://seaborn.pydata.org/examples/three_variable_histogram.html import knime.scripting.io as knio#Import Libraryfrom io import BytesIOimport osimport pandas as pdimport seaborn as snssns.set_theme(style="dark")# https://seaborn.pydata.org/examples/three_variable_histogram.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']var_x_log = knio.flow_variables['x_log_scale']var_y_log = knio.flow_variables['y_log_scale']#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/three_variable_histogram.htmlg = sns.displot( data=input_table, x=var_x_variable, y=var_y_a_variable, col=var_y_b_variable, log_scale=(True, False), col_wrap=4, height=4, aspect=.7)g.set_axis_labels(var_x_label, var_y_a_label)g.fig.set_size_inches(16, 9)#add overall titleg.fig.suptitle(var_title, y=1.025)g.fig.text(0.025, -0.025, var_footnote ,fontsize=10)################################################### Create buffer to write intobuffer = BytesIO()# Create plot and write it into the bufferg.savefig(buffer, format='svg')# The output is the content of the bufferoutput_image = buffer.getvalue()knio.output_images[0] = output_image 1.920 x 1.080PNG filefrom_knime_histogram_trivariate_two_categories.pngdiamonds.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_* Image To Table Renderer to Image Table To Image Image Writer (Port) Parquet Reader Python Script Python graphics - Trivariate histogramwith two categorical variables Variable toTable Row KNIME & Python Graphics - Trivariate histogram with two categorical variables with Seabornadapted from: https://seaborn.pydata.org/examples/three_variable_histogram.html import knime.scripting.io as knio#Import Libraryfrom io import BytesIOimport osimport pandas as pdimport seaborn as snssns.set_theme(style="dark")# https://seaborn.pydata.org/examples/three_variable_histogram.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']var_x_log = knio.flow_variables['x_log_scale']var_y_log = knio.flow_variables['y_log_scale']#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/three_variable_histogram.htmlg = sns.displot( data=input_table, x=var_x_variable, y=var_y_a_variable, col=var_y_b_variable, log_scale=(True, False), col_wrap=4, height=4, aspect=.7)g.set_axis_labels(var_x_label, var_y_a_label)g.fig.set_size_inches(16, 9)#add overall titleg.fig.suptitle(var_title, y=1.025)g.fig.text(0.025, -0.025, var_footnote ,fontsize=10)################################################### Create buffer to write intobuffer = BytesIO()# Create plot and write it into the bufferg.savefig(buffer, format='svg')# The output is the content of the bufferoutput_image = buffer.getvalue()knio.output_images[0] = output_image 1.920 x 1.080PNG filefrom_knime_histogram_trivariate_two_categories.pngdiamonds.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_* Image To Table Renderer to Image Table To Image Image Writer (Port) Parquet Reader Python Script Python graphics - Trivariate histogramwith two categorical variables Variable toTable Row

Nodes

Extensions

Links