# Plotly graphics\_object determine discrete colors to be used

**URL:** <https://community.plotly.com/t/plotly-graphics-object-determine-discrete-colors-to-be-used/65989>\
**Category:** 📊 Plotly Python\
**Tags:** question\
**Created:** [July 12, 2022, 12:59pm UTC](https://community.plotly.com/t/plotly-graphics-object-determine-discrete-colors-to-be-used/65989 "2022-07-12T12:59:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amuls](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/amuls/32/19895_2.png) [@amuls](https://community.plotly.com/u/amuls)\
**Post date:** [July 12, 2022, 12:59pm UTC](https://community.plotly.com/t/plotly-graphics-object-determine-discrete-colors-to-be-used/65989/1 "2022-07-12T12:59:57Z")

</div>

Hi All,

I am new to plotly and dash, so this is my first question.

I have a dataframe with coordinates, each coordinate couple (E, N, U) have a quality level which is an integer ranging between 1 (best) and 7 (worst). I want to assign the colors to each quality (1: green, 2: yellow, … 7: red). Since these coordinates are represented on 3 subplots, so I work with ‘make\_subplots’ adding traces for each coordinate versus datatime using the go.Scatter function.

When using plotly.express, I was able to set the color on a single plot using

color=‘Q’, color\_discrete\_map=q\_plotly[‘color’]

where the latter is a dict linking the quality to the desired color. For this to work I had to change the Quality in the dataframe from int to str.

How could I get a similar result using the go.Scatter?

Tx/Alain

---

<div class="post-metadata">

**Author:** ![jlfsjunior](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jlfsjunior/32/16061_2.png) [@jlfsjunior](https://community.plotly.com/u/jlfsjunior)\
**Post date:** [July 13, 2022, 1:30pm UTC](https://community.plotly.com/t/plotly-graphics-object-determine-discrete-colors-to-be-used/65989/2 "2022-07-13T13:30:21Z")

</div>

Hi,

Welcome to the community! 🙂

Assuming the quality is in a column “Q” of a dataframe `df`, and `q_plotly={1: "green", ...}` maps the values in Q to color names, then you can do:

```nohighlight
go.Scatter(
    x=df[...],
    y=df[...],
    marker={
        "color": df["Q"].apply(lambda x: q_plotly[x])
    }
   # or marker_color = df["Q"]...., if you don't want to pass a full dict
) 

```

In other words, you can specify individual colors by passing an iterable (list or pd.Series) to `marker.color`, as well as to other marker properties (like symbol or size).

Lastly, you can also consider using “facet\_row” in plotly express and provide the column having the three “coordinates” E, N, U, if those are the 3 subplots you want to create (instead of using make\_subplot).

---

<div class="post-metadata">

**Author:** ![plotmaster422](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/plotmaster422/32/22680_2.png) [@plotmaster422](https://community.plotly.com/u/plotmaster422)\
**Post date:** [October 22, 2024, 1:43pm UTC](https://community.plotly.com/t/plotly-graphics-object-determine-discrete-colors-to-be-used/65989/3 "2024-10-22T13:43:16Z")

</div>

Am I right in saying the color property for go.Scatter must be a column in the dataframe / array of color values?

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [October 22, 2024, 3:52pm UTC](https://community.plotly.com/t/plotly-graphics-object-determine-discrete-colors-to-be-used/65989/4 "2024-10-22T15:52:52Z")

</div>

> [@plotmaster422](#):
>
> must be a column in the dataframe / array of color values

Yes. If you specify a single color, all markers will have the same color.
