# Passing a discrete variable (string) as color in scatter plot

**URL:** <https://community.plotly.com/t/passing-a-discrete-variable-string-as-color-in-scatter-plot/8824>\
**Category:** 📊 Plotly Python\
**Created:** [March 7, 2018, 4:02pm UTC](https://community.plotly.com/t/passing-a-discrete-variable-string-as-color-in-scatter-plot/8824 "2018-03-07T16:02:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![grgr](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@grgr](https://community.plotly.com/u/grgr)\
**Post date:** [March 7, 2018, 4:02pm UTC](https://community.plotly.com/t/passing-a-discrete-variable-string-as-color-in-scatter-plot/8824/1 "2018-03-07T16:02:17Z")

</div>

How can I pass a discrete variable (string) as color in (3d) scatter plot?

I managed to get that for a continuous variable (float), simply with

`marker=dict(...,color = my_cont_var, ...)`

…but it doesn’t work for a discrete one.

Thanks for your help 🙂

---

<div class="post-metadata">

**Author:** ![grgr](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@grgr](https://community.plotly.com/u/grgr)\
**Post date:** [March 7, 2018, 4:33pm UTC](https://community.plotly.com/t/passing-a-discrete-variable-string-as-color-in-scatter-plot/8824/2 "2018-03-07T16:33:08Z")

</div>

ok, I found here the solution

> **[Scatter Plots](https://plot.ly/pandas/line-and-scatter/#scatter-plot-with-grouped-traces)**
>
> How to make scatter plots with Pandas dataframes. Seven examples of basic and colored scatter plots.

(it might be still useful for whoever has the same question)

However, would be great if this will be _implemented in a way one does not need to write a `for` loop_

Thanks again

---

<div class="post-metadata">

**Author:** ![grgr](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@grgr](https://community.plotly.com/u/grgr)\
**Post date:** [March 7, 2018, 5:21pm UTC](https://community.plotly.com/t/passing-a-discrete-variable-string-as-color-in-scatter-plot/8824/3 "2018-03-07T17:21:13Z")

</div>

…or better [the answer to this similar question](https://community.plotly.com/t/how-to-add-100-traces-in-a-plot-without-using-an-api-call-each-time/2885/2)
