Reputation: 17154
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.
Upvotes: 4
Views: 5414
Reputation: 808
The following are all colorscales in plotly
['aggrnyl', 'agsunset', 'algae', 'amp', 'armyrose', 'balance',
'blackbody', 'bluered', 'blues', 'blugrn', 'bluyl', 'brbg',
'brwnyl', 'bugn', 'bupu', 'burg', 'burgyl', 'cividis', 'curl',
'darkmint', 'deep', 'delta', 'dense', 'earth', 'edge', 'electric',
'emrld', 'fall', 'geyser', 'gnbu', 'gray', 'greens', 'greys',
'haline', 'hot', 'hsv', 'ice', 'icefire', 'inferno', 'jet',
'magenta', 'magma', 'matter', 'mint', 'mrybm', 'mygbm', 'oranges',
'orrd', 'oryel', 'peach', 'phase', 'picnic', 'pinkyl', 'piyg',
'plasma', 'plotly3', 'portland', 'prgn', 'pubu', 'pubugn', 'puor',
'purd', 'purp', 'purples', 'purpor', 'rainbow', 'rdbu', 'rdgy',
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
Upvotes: 1
Reputation: 27370
Update: there is now a dedicated documentation page for this, including swatches at https://plotly.com/python/builtin-colorscales/
This file contains most of what you’re looking for.
So probably from plotly._plotly_utils.colors import PLOTLY_SCALES
will allow you to do colorscales = PLOTLY_SCALES.keys()
although this is meant to be an internal object.
I should add that there are other color scales that Plotly will recognize by name but those aren’t available as a neat import like this as they are in other modules like plotly.express.colors.sequential
or plotly.express.colors.cyclical
etc.
Upvotes: 2
Reputation: 48929
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
Upvotes: 4
Reputation: 17154
I am not aware how to get all the names in a single list but what I usually do is make a typo in colorscale
name e.g. Viridis1
instead of Viridis
, then look at the error messages and copy the list of available colorscales.
Its not the best way to do it, but it works.
Upvotes: 0