You can use:
fig3 = go.Figure(data=fig1.data + fig2.data)
Where fig1 and fig2 are built using px.line() and px.scatter(), respectively. And fig3 is, as you can see, built using plotly.graph_objects.
Some details:
One approach that I use alot is building two figures fig1 and fig2 using plotly.express and then combine them using their data attributes together with a go.Figure / plotly.graph_objects object like this:
import plotly.express as px
import plotly.graph_objects as go
df = px.data.iris()
fig1 = px.line(df, x="sepal_width", y="sepal_length")
fig1.update_traces(line=dict(color = 'rgba(50,50,50,0.2)'))
fig2 = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig3 = go.Figure(data=fig1.data + fig2.data)
fig3.show()
Plot:

Videos
You can use:
fig3 = go.Figure(data=fig1.data + fig2.data)
Where fig1 and fig2 are built using px.line() and px.scatter(), respectively. And fig3 is, as you can see, built using plotly.graph_objects.
Some details:
One approach that I use alot is building two figures fig1 and fig2 using plotly.express and then combine them using their data attributes together with a go.Figure / plotly.graph_objects object like this:
import plotly.express as px
import plotly.graph_objects as go
df = px.data.iris()
fig1 = px.line(df, x="sepal_width", y="sepal_length")
fig1.update_traces(line=dict(color = 'rgba(50,50,50,0.2)'))
fig2 = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig3 = go.Figure(data=fig1.data + fig2.data)
fig3.show()
Plot:

EDIT: fixed typo.
This works great and is even more useful with flipSTAR's clarification regarding adding a global layout to the combined fig. However, sometimes a global layout doesn't cover everything. For example, in my case (a stacked bar and two single scatter plot lines), my global layout caused me to lose my scatter plot legends. Fortunately, you can add additional arguments to the combined fig by targeting the specific figures. e.g., given a hypothetical:
fig1 = px.bar(...)
fig2 = px.line(...)
fig3 = px.line(...)
all_fig = go.Figure(data=fig1.data + fig2.data + fig3.data, layout = fig1.layout)
Which is a bar chart and two scatter plots each with a single line, you can add the legends for each line with:
all_fig['data'][1]['showlegend']=True
all_fig['data'][1]['name']='Line 1 Name'
all_fig['data'][1]['hovertemplate']='Line 1 Name<br>x=%{x}<br>y=%{y}<extra></extra>'
all_fig['data'][2]['showlegend']=True
all_fig['data'][2]['name']='Line 2 Name'
all_fig['data'][2]['hovertemplate']='Line 2 Name<br>x=%{x}<br>y=%{y}<extra></extra>'
(the bar is all_fig['data'][0]).
For some reason, the name won't show up on hover unless you explicitly add it to 'hovertemplate.'
It turns out that the issue seems to be with plotly express. When I use plotly.graph_objects instead it works.
Sample code that works:
import plotly.graph_objects as go
fig = go.Figure(data=[go.Scatter(
x = df['time'],
y = df['y_value'],
mode = 'markers',
marker_size=df['size_value'],
marker=dict(
color=df['color_value']
)
)]
)
fig.show()
This is probably related to this Github issue - your example plot has on the order of 1000 data points, which is the point at which plotly-express alters its plotting strategy.
The solution is to manually specify the renderer as "svg":
fig = px.scatter(
result,
x='time',
y='y_value',
<other args>,
render_mode='svg'
)
For that you may use the color_discrete_sequence argument.
fig = px.scatter(df, x="sepal_width", y="sepal_length", color_discrete_sequence=['red'])
This argument is to use a custom color paletter for discrete color factors, but if you are not using any factor for color it will use the first element for all the points in the plot.
More about discrete color palletes: https://plotly.com/python/discrete-color/
As far as I understand your question, I would try to answer it.
The parameter 'color' only accepts the column names.
In your case, you can consider using update_traces()
import plotly.express as px
df = px.data.iris() # iris is a pandas DataFrame
fig = px.scatter(df, x="sepal_width", y="sepal_length")
fig.update_traces(marker=dict(
color='red'))
fig.show()
Reference: https://plotly.com/python/marker-style/