Icon

kn_​example_​python_​graphic_​lineplot_​sns_​different_​x_​axis

KNIME & Python Graphics - Seaborn Multiple line plot with different x-axis

KNIME & Python Graphics - Seaborn Multiple line plot with different x-axis

adapted from: https://www.easytweaks.com/python-plot-multiple-lines-matplotlib-seaborn/



KNIME & Python Graphics - Seaborn Multiple line plot with different x-axisadapted from: https://www.easytweaks.com/python-plot-multiple-lines-matplotlib-seaborn/https://forum.knime.com/t/multiple-line-plot-with-different-x-axis/48493/2?u=mlauber71 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_overall_x_label = knio.flow_variables['overall_x_label']var_overall_y_label =knio.flow_variables['overall_y_label']var_label_one = knio.flow_variables['label_one']var_one_x = knio.flow_variables['variable_one_x']var_one_y = knio.flow_variables['variable_one_y']var_label_two = knio.flow_variables['label_two']var_two_x = knio.flow_variables['variable_two_x']var_two_y = knio.flow_variables['variable_two_y']sns.set_theme(style="whitegrid")sns.set_style("whitegrid")sns.set(rc={'figure.figsize':(16,9)})################################################### https://www.easytweaks.com/python-plot-multiple-lines-matplotlib-seaborn/# How to plot multiple lines with Python, Seaborn, Pandas and Matplotlib?fig, ax_one = plt.subplots(figsize=(16, 9))ax_one = sns.lineplot(x=var_one_x, y=var_one_y, data=input_table, label=var_label_one)ax_two = sns.lineplot(x=var_two_x, y=var_two_y, data=input_table, label=var_label_two)# set y-axis labelax_one.set_xlabel(var_overall_x_label,fontsize=12)ax_one.set_ylabel(var_overall_y_label,fontsize=12)ax_one.annotate(var_footnote, (0,0), (0, -40), xycoords='axes fraction', textcoords='offset points', va='top', size=8)# set a title for the plotfig.suptitle(var_title ,fontsize=18, ha='center')################################################### Create buffer to write intobuffer = BytesIO()# Create plot and write it into the bufferfig.savefig(buffer, format='svg')# The output is the content of the bufferoutput_image = buffer.getvalue()knio.output_images[0] = output_image YouTube - Advanced Visualizations with Python and KNIMEhttps://youtu.be/mG2SZiKG9zo?t=2108 1.920 x 1.080PNG filefrom_knime_lineplot_different_x_axis.pngright mouse clickto set the parameterstwo_data_sets.xlsx Image To Table Renderer to Image Table To Image Image Writer (Port) Python Graphics - Seaborn Multipleline plot with different x-axis Excel Reader KNIME & Python Graphics - Seaborn Multiple line plot with different x-axisadapted from: https://www.easytweaks.com/python-plot-multiple-lines-matplotlib-seaborn/https://forum.knime.com/t/multiple-line-plot-with-different-x-axis/48493/2?u=mlauber71 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_overall_x_label = knio.flow_variables['overall_x_label']var_overall_y_label =knio.flow_variables['overall_y_label']var_label_one = knio.flow_variables['label_one']var_one_x = knio.flow_variables['variable_one_x']var_one_y = knio.flow_variables['variable_one_y']var_label_two = knio.flow_variables['label_two']var_two_x = knio.flow_variables['variable_two_x']var_two_y = knio.flow_variables['variable_two_y']sns.set_theme(style="whitegrid")sns.set_style("whitegrid")sns.set(rc={'figure.figsize':(16,9)})################################################### https://www.easytweaks.com/python-plot-multiple-lines-matplotlib-seaborn/# How to plot multiple lines with Python, Seaborn, Pandas and Matplotlib?fig, ax_one = plt.subplots(figsize=(16, 9))ax_one = sns.lineplot(x=var_one_x, y=var_one_y, data=input_table, label=var_label_one)ax_two = sns.lineplot(x=var_two_x, y=var_two_y, data=input_table, label=var_label_two)# set y-axis labelax_one.set_xlabel(var_overall_x_label,fontsize=12)ax_one.set_ylabel(var_overall_y_label,fontsize=12)ax_one.annotate(var_footnote, (0,0), (0, -40), xycoords='axes fraction', textcoords='offset points', va='top', size=8)# set a title for the plotfig.suptitle(var_title ,fontsize=18, ha='center')################################################### Create buffer to write intobuffer = BytesIO()# Create plot and write it into the bufferfig.savefig(buffer, format='svg')# The output is the content of the bufferoutput_image = buffer.getvalue()knio.output_images[0] = output_image YouTube - Advanced Visualizations with Python and KNIMEhttps://youtu.be/mG2SZiKG9zo?t=2108 1.920 x 1.080PNG filefrom_knime_lineplot_different_x_axis.pngright mouse clickto set the parameterstwo_data_sets.xlsxImage To Table Renderer to Image Table To Image Image Writer (Port) Python Graphics - Seaborn Multipleline plot with different x-axis Excel Reader

Nodes

Extensions

Links