I have data sorted by month of collection. I am trying to assign a varying color range specifically to season as well (ie. cooler months have cooler colors - light blue for October and gets darker towards January). I have been working from Continuous color scales and color bars in Python and this example Create colorbar from a source label (string) rather than integer? Python - #3 by spencerchad.
I cannot figure out how to prevent each section in colorscale from blending together – I would like it to look more categorical like in the example Create colorbar from a source label (string) rather than integer? Python - #3 by spencerchad.
Also if all of my months are categorized by number (Jan =1, Feb=2… Dec =12) in the dataset is there a way to just assign color to the month number rather than assigning to each ‘fraction’ of colorscale?
Below is my code and current figure.
color_names = [‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’, ‘May’, ‘June’, ‘July’, ‘Aug’, ‘Sept’, ‘Oct’, ‘Nov’, ‘Dec’]
color_vals = list(range(len(color_names)))
num_colors = len(color_vals)
colorscale = [
[0, ‘rgb(0,25,51)’], #jan
[0.083333, ‘rgb(0,102,102)’], #feb
[0.16666, ‘rgb(0,204,204)’], #mar
[0.24999, ‘rgb(0,255,255)’], #apr
[0.3333, ‘rgb(255,255,102)’], #may
[0.4166, ‘rgb(255,153,51)’], #june
[0.4999, ‘rgb(255,153,51)’], #jul
[0.58329, ‘rgb(255,0,0)’], #aug
[0.6666, ‘rgb(204,0,0)’], #sept
[0.74995, ‘rgb(204,229,255)’], #oct
[0.83328, ‘rgb(102,178,255)’], #nov
[0.9166, ‘rgb(0,128,255)’], #dec
[1, ‘rgb(0,76,153)’]
]cmin = -0.5
cmax = num_colors-0.5trace0=go.Scatter(x=O18, y=H2, mode=‘lines’, name=‘LMWL’, marker=dict(color=‘#000000’))
trace1=go.Scatter(x=df_upgrading.del18, y=df_upgrading.del2, marker = dict(size=7,
line=dict(width=1),
colorbar=dict(title=‘Month’,
tickvals= color_vals,
ticktext= color_names),
colorscale = colorscale,
cmin=cmin,
cmax=cmax,
color = df_upgrading.month),
mode=‘markers’, name=‘CT_all’)layout = go.Layout(xaxis=dict(range=[-18, -10]),
yaxis=dict(range=[-140,-100]),
showlegend=False)data = [trace0, trace1]
fig=go.Figure(data=data, layout=layout)plotly.offline.iplot(fig)