0

I am using Plotly and Python 3 for data visualization. It is known to me that default number of colors in Plotly is 10 and are repeated in cycle if more elements than 10.

I do not want to use this approach to bring more colors in my 3D scattegram: How to create discrete colormap with n colors using Plotly cause the colors look too similar.

I am looking for a solution that would assign one unique qualitative color to each element (cluster) in my code. Here is my code:

fig_tSNE = px.scatter_3d(x = projections[:,0],
                      y = projections[:,1],
                      z = projections[:,2],                  
                      color = to_be_plotted['Cluster'],
                      color_discrete_sequence = px.colors.sequential.PuBu)

Thanks for help.

Mr.Slow
  • 490
  • 1
  • 1
  • 16
  • 1
    You can build your own palette, with as many colors you want. Just make a list of colors and assign it to `color_discrete_sequence` – alec_djinn Nov 01 '22 at 14:01
  • 1
    Can you add a minimal reproducible example ? "_cause the colors look too similar_", this is too subjective. Could it not rather be because of having too many cluster elements ? See [this post](https://graphicdesign.stackexchange.com/questions/3682/where-can-i-find-a-large-palette-set-of-contrasting-colors-for-coloring-many-d) – EricLavault Nov 01 '22 at 14:30

1 Answers1

1

As Alec said in the comment, you can build your color palette. Alternatively, you can use one of the available discrete color maps.

import plotly.express as px
import numpy as np

n = 100
ncat = 20
xx = np.random.uniform(-10, 10, n)
yy = np.random.uniform(-10, 10, n)
zz = np.random.uniform(-10, 10, n)
cc = np.random.uniform(0, ncat, n).astype(int).astype(str)
px.scatter_3d(x=xx, y=yy, z=zz, color=cc, color_discrete_sequence=px.colors.qualitative.Alphabet)

enter image description here

Davide_sd
  • 10,578
  • 3
  • 18
  • 30
  • Thanks for your answer. What does the ncat stand for? I cannot use plotly qualitative disrete maps for a maxium number of colors they contain is 24 ("Light24"/"Dark24")...or? – Mr.Slow Nov 03 '22 at 08:18
  • Since you didn't provide data, I had to come up with something. `ncat` stands for "number of categories". – Davide_sd Nov 03 '22 at 08:23