I want to use plotly to specify the color.
However, with the current code, using marker=dict(color=colors)
will naturally result in an error.
How can I specify the type and also the color at the same time?
import plotly.express as px
fig = px.scatter(
df,
x=x_axis,
y=y_axis,
color="species",
)
fig.show()
As an image, I want to specify something like this. color
is a list, and it contains the same kind of data as species
.
import seaborn as sns
def get_colorpalette(colorpalette, file_number):
palette = sns.color_palette(
colorpalette, file_number)
rgb = ['rgb({},{},{},{})'.format(*[x*256 for x in rgb],1)
for rgb in palette]
return rgb
colors = get_colorpalette('hls', graphNumber)
fig = px.scatter(
df,
x=x_axis,
y=y_axis,
color="species",
marker=dict(color=colors)
)
fig.show()
postscript
I have prepared color
in RGB, but it would be nice if I could specify the color in RGB in plotly.
The following is an example of how to specify a color in plotly.
import numpy as np
import seaborn as sns
import plotly.graph_objs as go
import plotly.offline as py
import plotly
def get_colorpalette(colorpalette, n_colors):
palette = sns.color_palette(
colorpalette, n_colors)
rgb = ['rgb({},{},{})'.format(*[x*256 for x in rgb])
for rgb in palette]
return rgb
n_legends = 12
x = np.arange(0, 1, .01)
y = np.random.rand(n_legends, 100) + \
np.arange(n_legends).reshape(-1, 1)
colors = get_colorpalette('hls', n_legends)
data = [
go.Scatter(
x=x, y=y[i], name='凡例 {:02d}'.format(i),
marker={'color':colors[i]})
for i in range(n_legends)]
fig = go.Figure(data=data)
py.iplot(fig)