Icon

matplotlib_​bar_​color_​demo

This is an example showing how to control bar color and legend entries using the color and label parameters of bar. Note that labels with a preceding underscore won't show up in the legend.

<Python View Source Code>import knime.scripting.io as knioimport numpy as npimport matplotlib.pyplot as pltfig, ax = plt.subplots()data = knio.input_tables[0].to_pandas()fruits = np.array(data['fruits'])counts = np.array(data['counts'])bar_labels = ['red', 'blue', '_red', 'orange']bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']ax.bar(fruits, counts, label=bar_labels, color=bar_colors)ax.set_ylabel('fruit supply')ax.set_title('Fruit supply by kind and color')ax.legend(title='Fruit color')# Assign the figure to the output_view variableknio.output_view = knio.view(fig) # alternative: knio.view_matplotlib() dataBar color demo Table Creator Python View <Python View Source Code>import knime.scripting.io as knioimport numpy as npimport matplotlib.pyplot as pltfig, ax = plt.subplots()data = knio.input_tables[0].to_pandas()fruits = np.array(data['fruits'])counts = np.array(data['counts'])bar_labels = ['red', 'blue', '_red', 'orange']bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']ax.bar(fruits, counts, label=bar_labels, color=bar_colors)ax.set_ylabel('fruit supply')ax.set_title('Fruit supply by kind and color')ax.legend(title='Fruit color')# Assign the figure to the output_view variableknio.output_view = knio.view(fig) # alternative: knio.view_matplotlib() dataBar color demo Table Creator Python View

Nodes

Extensions

Links