Icon

kn_​example_​python_​graphic_​scatterplot

KNIME & Python Graphics - Scatterplot with continuous hues and sizes with Seaborn

KNIME & Python Graphics - Scatterplot with continuous hues and sizes with Seaborn

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

KNIME & Python Graphics - Scatterplot with continuous hues and sizes with Seabornadapted from: https://seaborn.pydata.org/examples/scatterplot_sizes.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/scatterplot_sizes.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_x_scale = knio.flow_variables['x_scale']var_y_a_variable = knio.flow_variables['variable_y_a']var_y_a_label = knio.flow_variables['label_y_a']var_y_scale = knio.flow_variables['y_scale']var_y_b_variable = knio.flow_variables['variable_y_b']var_y_b_label = knio.flow_variables['label_y_b']var_size = knio.flow_variables['variable_size']var_size_a = int(knio.flow_variables['variable_size_a'])var_size_b = int(knio.flow_variables['variable_size_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/scatterplot_sizes.htmlcmap = sns.cubehelix_palette(rot=-.2, as_cmap=True)g = sns.relplot( data=input_table, x=var_x_variable, y=var_y_a_variable, hue=var_y_b_variable, size=var_size, palette=cmap, sizes=(var_size_a, var_size_b),)g.set(xscale=var_x_scale, yscale=var_y_scale)g.ax.xaxis.grid(True, "minor", linewidth=.25)g.ax.yaxis.grid(True, "minor", linewidth=.25)g.despine(left=True, bottom=True)##################################################g.fig.set_size_inches(16, 9)#add overall titleg.fig.suptitle(var_title)g.fig.text(0.1, 0.05, 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 locate and create/data/ folderwith absolute paths1.920 x 1.080PNG filefrom_knime_scatterplot.pngplanets.parquetright mouse clickto set the parameters Collect LocalMetadata Image To Table Renderer to Image Table To Image Image Writer (Port) Parquet Reader Python graphics - Scatterplotwith continuous hues and sizes KNIME & Python Graphics - Scatterplot with continuous hues and sizes with Seabornadapted from: https://seaborn.pydata.org/examples/scatterplot_sizes.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/scatterplot_sizes.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_x_scale = knio.flow_variables['x_scale']var_y_a_variable = knio.flow_variables['variable_y_a']var_y_a_label = knio.flow_variables['label_y_a']var_y_scale = knio.flow_variables['y_scale']var_y_b_variable = knio.flow_variables['variable_y_b']var_y_b_label = knio.flow_variables['label_y_b']var_size = knio.flow_variables['variable_size']var_size_a = int(knio.flow_variables['variable_size_a'])var_size_b = int(knio.flow_variables['variable_size_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/scatterplot_sizes.htmlcmap = sns.cubehelix_palette(rot=-.2, as_cmap=True)g = sns.relplot( data=input_table, x=var_x_variable, y=var_y_a_variable, hue=var_y_b_variable, size=var_size, palette=cmap, sizes=(var_size_a, var_size_b),)g.set(xscale=var_x_scale, yscale=var_y_scale)g.ax.xaxis.grid(True, "minor", linewidth=.25)g.ax.yaxis.grid(True, "minor", linewidth=.25)g.despine(left=True, bottom=True)##################################################g.fig.set_size_inches(16, 9)#add overall titleg.fig.suptitle(var_title)g.fig.text(0.1, 0.05, 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 locate and create/data/ folderwith absolute paths1.920 x 1.080PNG filefrom_knime_scatterplot.pngplanets.parquetright mouse clickto set the parametersCollect LocalMetadata Image To Table Renderer to Image Table To Image Image Writer (Port) Parquet Reader Python graphics - Scatterplotwith continuous hues and sizes

Nodes

Extensions

Links