I was wondering how to get all the names of available colorscales in plotly in a list.
Wanted:
import plotly
import plotly.offline as py
import plotly.graph_objs as go
import plotly.figure_factory as ff
import plotly.tools as tls
from plotly.offline import plot, iplot, init_notebook_mode
init_notebook_mode(connected=False)
colorscales = plotly.something.something
import plotly.graph_objs as go
x = ['Albania', 'Denmark', 'France', 'Finland', 'USSR']
y = [4, 2, 3, 5, 9]
fig = go.FigureWidget(data=[go.Bar(x=x, y=y,
marker={'color': y,
'colorscale': 'Viridis'})])
fig
Here I want to replace 'Viridis' by colorscales[0] and choose whatever colormap it gives.
You can get all the individual colorscale name by using the inspect module while iterating over the known color modules:
import inspect
colorscale_names = []
colors_modules = ['carto', 'colorbrewer', 'cmocean', 'cyclical',
'diverging', 'plotlyjs', 'qualitative', 'sequential']
for color_module in colors_modules:
colorscale_names.extend([name for name, body
in inspect.getmembers(getattr(px.colors, color_module))
if isinstance(body, list)])
All the names are now available in the list colorscale_names (including those from PLOTLY_SCALES since they are replicated in the color modules). There are some duplicates, which you could remove by casting it to a set.
Here are all the names printed in columns.
from textwrap import fill
print(fill(''.join(sorted({f'{x: <{15}}' for x in colorscale_names})), 75))
Accent Aggrnyl Agsunset Alphabet Antique
Armyrose Blackbody Bluered Blues Blugrn
Bluyl Bold BrBG Brwnyl BuGn
BuPu Burg Burgyl Cividis D3
Dark2 Dark24 Darkmint Earth Edge
Electric Emrld Fall G10 Geyser
GnBu Greens Greys HSV Hot
IceFire Inferno Jet Light24 Magenta
Magma Mint OrRd Oranges Oryel
PRGn Paired Pastel Pastel1 Pastel2
Peach Phase PiYG Picnic Pinkyl
Plasma Plotly Plotly3 Portland Prism
PuBu PuBuGn PuOr PuRd Purp
Purples Purpor Rainbow RdBu RdGy
RdPu RdYlBu RdYlGn Redor Reds
Safe Set1 Set2 Set3 Spectral
Sunset Sunsetdark T10 Teal Tealgrn
Tealrose Temps Tropic Twilight Viridis
Vivid YlGn YlGnBu YlOrBr YlOrRd
algae amp balance curl deep
delta dense gray haline ice
matter mrybm mygbm oxy phase
scale_pairs scale_sequence solar speed tempo
thermal turbid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With