# Python View and Color Manager

**URL:** <https://forum.knime.com/t/python-view-and-color-manager/21110>\
**Category:** KNIME Extensions\
**Tags:** scripting\
**Created:** [February 18, 2020, 3:41am UTC](https://forum.knime.com/t/python-view-and-color-manager/21110 "2020-02-18T03:41:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![codvknime](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/c/838e76/32.png) [@codvknime](https://forum.knime.com/u/codvknime)\
**Post date:** [February 18, 2020, 3:41am UTC](https://forum.knime.com/t/python-view-and-color-manager/21110/1 "2020-02-18T03:41:40Z")

</div>

Hi All, I’ve come across this thread linking Color Manager to R View

> [@R View and Color Manager](https://forum.knime.com/t/r-view-and-color-manager/1984):
>
> Hi, is there any possibility to integrate a Color Model made by the Color Manager into the R View ? As far as I have seen it, the color information seems to be lost inside the R View node. Thanks a lot !

I’m wondering if anybody has made the same approach in Python View?

Thanks 😄

---

<div class="post-metadata">

**Author:** ![paolotamag](https://forum-cdn.knime.com/user_avatar/forum.knime.com/paolotamag/32/1061_2.png) [@paolotamag](https://forum.knime.com/u/paolotamag)\
**Post date:** [February 27, 2020, 4:20pm UTC](https://forum.knime.com/t/python-view-and-color-manager/21110/2 "2020-02-27T16:20:05Z")

</div>

Hi @codvknime,  
I had a quick look but it looks like a [pandas DataFrame](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html) (that is what is being converted and imported in the [Python View](https://kni.me/n/nkxvHXZo2XWkCPUI) node) is not able to store the colors attached to the KNIME Table by the Color Manager node. I will open a ticket and make sure developers are made aware of this and provide an easy workaround. Sorry for the inconvenience.

@MarcelW are you aware of a workaround?

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [February 28, 2020, 5:35pm UTC](https://forum.knime.com/t/python-view-and-color-manager/21110/3 "2020-02-28T17:35:29Z")

</div>

I am not exactly sure how one would store a piece of colour information with a Pandas data frame. I constructed a script that would extract the colour settings from the KNIME colour manager and store them as a Python dictionary object and save that as a pickle file.

 ![image](https://forum-cdn.knime.com/uploads/default/original/2X/0/0b6e689855f5943abbfcc4b7fcec2f70cf6e38fc.png)

This dictionary will later be loaded back into the Python script and be used as a palette with seaborn or as a colour dictionary for matplotlib.

![image](https://forum-cdn.knime.com/uploads/default/original/2X/c/c5b2b13e0f11984d11b239399575f32b215d9618.png)

OK admittedly not the most straightforward solution but hey it can be done after all.

 ![iris_plot_without_color_dictionary](https://forum-cdn.knime.com/uploads/default/original/2X/8/8351d9e3b7fd3ca723502f2d15518129034a33e9.png)

After you throw in the Color Manager

 ![image](https://forum-cdn.knime.com/uploads/default/original/2X/7/7bb5c179093f3943945bd722679e7e28e1e0ba46.png)

The result from Python looks like this.

 ![iris_plot_with_color_dictionary](https://forum-cdn.knime.com/uploads/default/original/2X/3/3ec72ec0d5ee7f6aff32c53eda4fe994d6dadbe1.png)

For the fun of it there is also a Jupyter notebook included in a subfolder /script/ that I used to first test the concept.

> **[Transform KNIME Color Manager to Python Color Dictionary – mlauber71](https://hub.knime.com/mlauber71/spaces/Public/latest/forum/kn_forum_python_color_manager)**
>
> Inspired by a forum question I constructed a Python script that would transform KNIME Color manager colors into a Python dictionary that could be used to colou…

---

<div class="post-metadata">

**Author:** ![MarcelW](https://forum-cdn.knime.com/user_avatar/forum.knime.com/marcelw/32/352_2.png) [@MarcelW](https://forum.knime.com/u/MarcelW)\
**Post date:** [February 28, 2020, 10:22pm UTC](https://forum.knime.com/t/python-view-and-color-manager/21110/4 "2020-02-28T22:22:46Z")

</div>

Assuming you are using the Color Manager for nominal columns only, you could also simply append the actual (integer) R, G, B, A values of each row’s color as additional columns, using the Extract Color and Joiner nodes.

[Here](https://hub.knime.com/marcelw/spaces/Public/latest/color_manager_and_python) is an example that does this. Note that I did not implement the Python side that actually uses the color values as @mlauber71’s example already illustrates how this can be done.

Marcel

---

<div class="post-metadata">

**Author:** ![codvknime](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/c/838e76/32.png) [@codvknime](https://forum.knime.com/u/codvknime)\
**Post date:** [March 18, 2020, 8:50am UTC](https://forum.knime.com/t/python-view-and-color-manager/21110/5 "2020-03-18T08:50:39Z")

</div>

Wow! This is exactly what I need. A lot of charts I’m using in my workflows are Python View charts.

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [March 25, 2020, 8:50am UTC](https://forum.knime.com/t/python-view-and-color-manager/21110/6 "2020-03-25T08:50:40Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
