Can a shape such as a rectangle have a smooth color gradient in Plotly?
I define the shape with a solid fill color as:
shapes=[dict(
type='rect',
xref='x',
yref='paper',
x0=box_from, x1=box_to,
y0=0, y1=1,
fillcolor='Green',
opacity=0.07,
layer='below',
line=dict(width=0),
)]
But I'd like the box not to have a solid color fill, but to have a smooth color gradient.
fillcolor
aren't very extensive:colorscales
don't apply to shapes:My guess is the answer is a simple "not supported", but perhaps someone else knows better.
Someone will correct me if I'm wrong but I think that no, there is no straight implementation to fill with a gradient a shape. But to achieve a similar results you could plot several lines inside the rectangle specifying decreasing rgb values.
For example I added this for loop after the first rectangle definition in the documentation code (changing also the rectangle fillcolor to white).
for i in range(100):
fig.add_shape(type='line',
xref="x",
yref="y",
x0=2.5,
x1=3.5,
y0=i*(2/100),
y1=i*(2/100),
line=dict(
color='rgb({}, {}, {})'.format((i/100*255),(i/100*255),(i/100*255)),
width=3,
))
And the result is:
I know it's impractical and that it can increase a bit the running time but if you care only about the aesthetic it does the job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With