Icon

kn_​example_​python_​iris_​graphics

Examples of using Python to generate graphics (using the isris dataset)

Examples of using Python to generate graphics (using the isris dataset)

3. Create and Export Graphics. Original inspiration. Later modified with ChatGPThttps://www.kaggle.com/xuhewen/iris-dataset-visualization-and-machine-learning Original Post:https://forum.knime.com/t/running-python-script-gives-error/14517/2?u=mlauber71 Examples of using Python to generate graphics (using the isris dataset) import knime.scripting.io as knioimport numpy as npimport pandas as pdimport seaborn as snsimport matplotlib.pyplot as pltfrom sklearn import preprocessingfrom io import BytesIOiris = knio.input_tables[0].to_pandas()# https://www.kaggle.com/xuhewen/iris-dataset-visualization-and-machine-learningiris.rename(columns={'Sepal.Length':'SepalLengthCm' ,'Sepal.Width':'SepalWidthCm' }, inplace=True)# kdeplot using seabornsns.set(style='darkgrid')setosa = iris.query("Species=='Iris-setosa'")versicolor = iris.query("Species=='Iris-versicolor'")virginica = iris.query("Species=='Iris-virginica'")f, ax = plt.subplots(figsize=(8, 8))# Updated kdeplot callsax = sns.kdeplot(data=setosa, x="SepalWidthCm", y="SepalLengthCm", cmap="Greens", shade=True, shade_lowest=False)ax = sns.kdeplot(data=versicolor, x="SepalWidthCm", y="SepalLengthCm", cmap="Reds", shade=True, shade_lowest=False)ax = sns.kdeplot(data=virginica, x="SepalWidthCm", y="SepalLengthCm", cmap="Blues", shade=True, shade_lowest=False)f.savefig(knio.flow_variables['iris1_filePath_location']) # The output is the content of the buffer# output_image = buffer.getvalue()# Pass the transformed table to the first output port of the node.knio.output_tables[0] = knio.Table.from_pandas(iris) Exploring the Power of Python Graphics with KNIME: A Collection of Exampleshttps://medium.com/p/841df87b5563 locate and create/data/ folderwith absolute pathsexport graphics directly fromPython within KNIMEiris1_filePathusing bundled python extensionsns.pairplotiris1_filePathiris1_filePathimport_imageimport_imageimport_imageimport_imageimport_imageiris.csviris_plot3.pngsns.kdeplotiris_plot1.pngscatteriris_plot2.png Collect LocalMetadata Python Script Python View Renderer to Image Image To Table Table To Image Renderer to Image Table To Image Image To Table Image To Table Table To Image Renderer to Image Create File/FolderVariables Path to String(Variable) Read Images Table Creator ConstantValue Column String to URI Table To Image CSV Reader Image Writer (Port) Python View Image Writer (Port) Python View Image Writer (Port) 3. Create and Export Graphics. Original inspiration. Later modified with ChatGPThttps://www.kaggle.com/xuhewen/iris-dataset-visualization-and-machine-learning Original Post:https://forum.knime.com/t/running-python-script-gives-error/14517/2?u=mlauber71 Examples of using Python to generate graphics (using the isris dataset) import knime.scripting.io as knioimport numpy as npimport pandas as pdimport seaborn as snsimport matplotlib.pyplot as pltfrom sklearn import preprocessingfrom io import BytesIOiris = knio.input_tables[0].to_pandas()# https://www.kaggle.com/xuhewen/iris-dataset-visualization-and-machine-learningiris.rename(columns={'Sepal.Length':'SepalLengthCm' ,'Sepal.Width':'SepalWidthCm' }, inplace=True)# kdeplot using seabornsns.set(style='darkgrid')setosa = iris.query("Species=='Iris-setosa'")versicolor = iris.query("Species=='Iris-versicolor'")virginica = iris.query("Species=='Iris-virginica'")f, ax = plt.subplots(figsize=(8, 8))# Updated kdeplot callsax = sns.kdeplot(data=setosa, x="SepalWidthCm", y="SepalLengthCm", cmap="Greens", shade=True, shade_lowest=False)ax = sns.kdeplot(data=versicolor, x="SepalWidthCm", y="SepalLengthCm", cmap="Reds", shade=True, shade_lowest=False)ax = sns.kdeplot(data=virginica, x="SepalWidthCm", y="SepalLengthCm", cmap="Blues", shade=True, shade_lowest=False)f.savefig(knio.flow_variables['iris1_filePath_location']) # The output is the content of the buffer# output_image = buffer.getvalue()# Pass the transformed table to the first output port of the node.knio.output_tables[0] = knio.Table.from_pandas(iris) Exploring the Power of Python Graphics with KNIME: A Collection of Exampleshttps://medium.com/p/841df87b5563 locate and create/data/ folderwith absolute pathsexport graphics directly fromPython within KNIMEiris1_filePathusing bundled python extensionsns.pairplotiris1_filePathiris1_filePathimport_imageimport_imageimport_imageimport_imageimport_imageiris.csviris_plot3.pngsns.kdeplotiris_plot1.pngscatteriris_plot2.pngCollect LocalMetadata Python Script Python View Renderer to Image Image To Table Table To Image Renderer to Image Table To Image Image To Table Image To Table Table To Image Renderer to Image Create File/FolderVariables Path to String(Variable) Read Images Table Creator ConstantValue Column String to URI Table To Image CSV Reader Image Writer (Port) Python View Image Writer (Port) Python View Image Writer (Port)

Nodes

Extensions

Links