Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly: Change transparency of fillcolor

I'm trying to change the default color of a fillcolor in Plotly to another transparent one, but when I change the fillcolor it is not transparent anymore.

trace = (go.Scatter(x=[30,45],y=[3000,3000],
                fill='tozeroy', 
#                     fillcolor='green',
#                     fillcolor='rgb(26,150,65,0.5)',
#                     fillcolor=dict(color='rgb(26,150,65,0.5)'),
#              fillcolor=dict(marker=dict(color='rgb(26,150,65,0.5)')),
                opacity=0.1,
                showlegend=False,
                hoverinfo='none',
                mode='none'))
py.offline.iplot(go.Figure(data=[trace]))

This default call results in the following: default fillcolor

and when I use fillcolor='green' it results in this nontransparent color: fillcolor = green

The commented code results in the default case again.

like image 276
Hans Bambel Avatar asked Jun 05 '18 15:06

Hans Bambel


People also ask

How do you change opacity in plotly?

Marker Opacity To maximise visibility of density, it is recommended to set the opacity inside the marker marker:{opacity:0.5} . If multiple traces exist with high density, consider using marker opacity in conjunction with trace opacity.

How do you remove background color in plotly?

Plotly Express Set Transparent Color To create a transparent background, we can use the update_layout() function and bass the plot_bgcolor and paper_bgcolor transparent values.

How do you change the color of a scatter plot in plotly?

There should be a legend next to the graph with points with all the colors from the df , and whenever a color x clicked, the respective coloring of row x is applied (that is, marker_color becomes df[x] ).

What does Add_trace do in plotly?

Adding Traces New traces can be added to a plot_ly figure using the add_trace() method. This method accepts a plot_ly figure trace and adds it to the figure. This allows you to start with an empty figure, and add traces to it sequentially.


2 Answers

You would need to use rgba to specify the alpha channel as well, rgb ignores the transparency.

import plotly
trace = plotly.graph_objs.Scatter(x=[30,45],y=[3000,3000],
                                  fill='tozeroy', 
                                  fillcolor='rgba(26,150,65,0.5)',
                                  mode='none')
plotly.offline.iplot(plotly.graph_objs.Figure(data=[trace]))

enter image description here

like image 119
Maximilian Peters Avatar answered Oct 22 '22 08:10

Maximilian Peters


Looks like there is for traces. opacity=0.5 is an argument. https://plotly.com/python/marker-style/

like image 41
Quint Avatar answered Oct 22 '22 09:10

Quint