Change default configuration

I’m playing around with using plotly as my default plotting package for scientific computing. Mostly I work in Jupyter notebooks, but I have a default colorscheme with dark backgrounds. In matplotlib it is possible to change the default colors of the plots to match almost every layout and I would really like to replicate this in plotly.

Is there any way to change the default colors of offline plots in Jupyter notebooks?

I wrote a small code example which I hope covers you needs:

import pandas as pd
import plotly.graph_objs as go
import plotly.io as pio
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode(connected=True)

# make a fig and use the color layout as template
colorlist = ['rgb(0,60, {:d})'.format(40*i) for i in range(10)]
fig = go.Figure(layout = dict(colorway = colorlist))

templated_fig = pio.to_templated(fig)
pio.templates['my_template'] = templated_fig.layout.template
pio.templates.default = 'my_template'

# plot a new figure

x = np.linspace(0,2*np.pi,100)
y = np.sin(x)

newfig = go.Figure()
for i in range (10):
    newfig.add_scatter(x=x,y=y*i/10)

iplot(newfig)

(Moderator edit: Added fenced code block https://help.github.com/articles/creating-and-highlighting-code-blocks/)

1 Like

Hi @CarlAndersson,

Just to add to @Alexboiboi’s helpful answer, theming support was added to plotly.py version 3.4.0. Here is the announcement blog post on it https://medium.com/@plotlygraphs/introducing-plotly-py-theming-b644109ac9c7.

Hope that helps!
-Jon

This is great!

Seems like I started with really good timing!

Thank’s @Alexboiboi and @jmmease for all the help! :smile: