Problem:
I don’t like the middle colour (the brown), that is automatically defined as a mix of both colours defined in range_colors=['#ff1a1a', '#7cfc00'].
Thus, I would like to manually define it. I have tried range_colors=['#ff1a1a', '#0000ff', '#7cfc00'], but range_colors expects a list of length 2 only — I get following error message: “plotly.exceptions.PlotlyError: Both ‘range_colors’ or ‘measure_colors’ must be a list of two valid colors.”
Question:
How to manually define the middle colour of the bullet chart?
I took a look at the code, and it’s not possible to specify a custom list of colors in the figure factory right now, but I think this would make sense so feel free to open a feature request at https://github.com/plotly/plotly.py.
In the meantime, your best option is to modify the figure factory result before displaying the figure. Here’s an example of coloring the middle bar blue in your example above
# Imports
import plotly.graph_objs as go
import plotly.figure_factory as ff
# Create initial bullet chart
fig = ff.create_bullet(
orientation='h',
ranges='range',
range_colors=['#ff1a1a', '#7cfc00'],
measures='data',
measure_colors=['#ffffff', '#333333'],
data=[dict(
range=[.4, .5, 1],
data=[0, 0.8],
)],
)
# Filter down to the 'ranges' bars
bar = [bar for bar in fig.data if bar.name == 'ranges']
# Set the color of the middle bar to blue
bar[1].marker.color = 'blue'
# Display figure
go.FigureWidget(fig)
Thanks for bringing that up @ebosi, the solution option wasn’t enabled for this category, but I just turned it on so you should be able to mark answers as solutions in the Python category now.
-Jon