Zijian Zhao
Zijian Zhao

Reputation: 1

Plotly: How to extend the colorscheme of a plotly express scatterplot?

This is my code. But some colors are recycled. I need 52 different kinds of color. How can I solve this problem?

fig = px.scatter(Xt[:,0], Xt[:,1], color=DF["ScientifName"])
fig.show()

enter image description here

Upvotes: 0

Views: 289

Answers (1)

r-beginners
r-beginners

Reputation: 35230

There is a function to create arbitrary color types. The desired graph will be created by setting the created color list to color. See this for details.

import plotly.express as px
from plotly.colors import n_colors
import numpy as np

x = np.random.randint(0,53,52)
y = np.random.randint(0,53,52)

red_blue = n_colors('rgb(0, 0, 255)', 'rgb(255, 0, 0)', 52, colortype = 'rgb')

fig = px.scatter(x, y, color=red_blue)
fig.show()

enter image description here

Upvotes: 2

Related Questions