Icon

kn_​example_​python_​graphic_​lineplot_​two_​categories_​facet

KNIME & Python Graphics - Seaborn Line Plots with 2 Categories using FacetGrid

KNIME & Python Graphics - Seaborn Line Plots with 2 Categories using FacetGrid

adapted from: https://www.marsja.se/seaborn-line-plots-multiple/

KNIME & Python Graphics - Seaborn Line Plots with 2 Categories using FacetGridadapted from: https://www.marsja.se/seaborn-line-plots-multiple/ import knime.scripting.io as knio#Import Libraryfrom io import BytesIOimport osimport pandas as pdimport seaborn as snsimport matplotlib as mplimport matplotlib.pyplot as pltinput_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_y_c_variable = knio.flow_variables['variable_y_c']var_y_c_label = knio.flow_variables['label_y_c']sns.set_theme(style="whitegrid")sns.set(rc={'figure.figsize':(16,9)})################################################### https://www.marsja.se/seaborn-line-plots-multiple/# https://www.marsja.se/seaborn-line-plots-multiple/# Seaborn Line Plots with 2 Categories using FacetGrid: # If we, on the other hand, want to look at many categories at the same time, when creating a Seaborn line graph with multiple lines, we can use FacetGrid:g = sns.FacetGrid(input_table, col=var_y_c_variable, hue=var_y_b_variable)g = g.map(sns.lineplot, var_x_variable, var_y_a_variable, ci=None).add_legend()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_lineplot_two_categories_facet.pngwages.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_*import Wages datawages.tableRowIDwages.parquet Image To Table Renderer to Image Table To Image Image Writer (Port) Parquet Reader Python Script Python graphics - Seaborn Line Plotswith 2 Categories using FacetGrid Variable toTable Row Python Script Table Writer RowID Parquet Writer KNIME & Python Graphics - Seaborn Line Plots with 2 Categories using FacetGridadapted from: https://www.marsja.se/seaborn-line-plots-multiple/ import knime.scripting.io as knio#Import Libraryfrom io import BytesIOimport osimport pandas as pdimport seaborn as snsimport matplotlib as mplimport matplotlib.pyplot as pltinput_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_y_c_variable = knio.flow_variables['variable_y_c']var_y_c_label = knio.flow_variables['label_y_c']sns.set_theme(style="whitegrid")sns.set(rc={'figure.figsize':(16,9)})################################################### https://www.marsja.se/seaborn-line-plots-multiple/# https://www.marsja.se/seaborn-line-plots-multiple/# Seaborn Line Plots with 2 Categories using FacetGrid: # If we, on the other hand, want to look at many categories at the same time, when creating a Seaborn line graph with multiple lines, we can use FacetGrid:g = sns.FacetGrid(input_table, col=var_y_c_variable, hue=var_y_b_variable)g = g.map(sns.lineplot, var_x_variable, var_y_a_variable, ci=None).add_legend()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_lineplot_two_categories_facet.pngwages.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_*import Wages datawages.tableRowIDwages.parquet Image To Table Renderer to Image Table To Image Image Writer (Port) Parquet Reader Python Script Python graphics - Seaborn Line Plotswith 2 Categories using FacetGrid Variable toTable Row Python Script Table Writer RowID Parquet Writer

Nodes

Extensions

Links