Home > OS >  Plotly : How to increase the number of colors in line plot?
Plotly : How to increase the number of colors in line plot?

Time:01-21

I'd to plot a simple line plot but if I have more than 10 variables, plolty use the same color twice, how can I avoid it and always have a new color for a new variable ?

import pandas as pd
import numpy as np
pd.set_option("plotting.backend", "plotly")

df=pd.DataFrame(np.random.rand(100, 12)).cumsum()
df.plot()

using 12 colors

CodePudding user response:

Effectively it's documented here https://plotly.com/python/discrete-color/. You are using interface to plotly express

Code below using a different set of colors.

import pandas as pd
import numpy as np
pd.set_option("plotting.backend", "plotly")

df=pd.DataFrame(np.random.rand(100, 12)).cumsum()
color_seq = ['#AA0DFE',
 '#3283FE',
 '#85660D',
 '#782AB6',
 '#565656',
 '#1C8356',
 '#16FF32',
 '#F7E1A0',
 '#E2E2E2',
 '#1CBE4F',
 '#C4451C',
 '#DEA0FD',
 '#FE00FA',
 '#325A9B',
 '#FEAF16',
 '#F8A19F',
 '#90AD1C',
 '#F6222E',
 '#1CFFCE',
 '#2ED9FF',
 '#B10DA1',
 '#C075A6',
 '#FC1CBF',
 '#B00068',
 '#FBE426',
 '#FA0087']

df.plot(color_discrete_sequence=color_seq)


  •  Tags:  
  • Related