3

I have just installed the lastest Plotly (3.0) and I have not been able to set the legend text colour.

This is my code:

import plotly.graph_objs as go
import numpy as np

x = np.random.randn(1000)
y = np.random.randn(1000)

fig = go.FigureWidget({'x':x,'y':y,'type':'histogram2dcontour','colorscale':'Viridis'}],
layout=go.Layout(title='test',width=700,plot_bgcolor='rgba(0,0,0,0)',
paper_bgcolor='rgba(0,0,0,0)'))

fig.layout.titlefont.color = 'orange'
fig.layout.xaxis.color = 'white'
fig.layout.yaxis.color = 'white'
fig.layout.legend.font.size = 2000
fig.layout.legend.font.color = 'red'

fig

As can be seen below the legend text below remains the same. Weirdly the attributes of fig.layout.legend.font.color include capitalise, isdigit class methods etc.

Is this a bug or am I missing something?

Any help much appreciated.

Thanks.

Legend text unchanged.

1 Answer 1

4

Because you are using histogram2contour the color-bar on the right is not a legend but actually an object called colorbar. To update it you can configure it's properties in your trace. I have an example below where I make the tick marks orange and the title red. I used Jupyter Notebooks to create the example so I had to configure it to offline but you don't have too. Here is the documentation for the color-bar object.

 import plotly.graph_objs as go
 from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
 init_notebook_mode(connected=True)

 import numpy as np

 x = np.random.uniform(-1, 1, size=500)
 y = np.random.uniform(-1, 1, size=500)

 trace = [go.Histogram2dContour(
         x = x,
         y = y,
     colorbar=dict(
         title='Colorbar',
         tickfont={'color':'#E90' },
         titlefont={"color":'#FF0000'}
     ),
 )]

 iplot(trace, filename = "Basic Histogram2dContour")

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that's great. Didn't realise colorscale was a separate attribute to the legend. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.