I have a line graph with 2 lines that I want to fill with 2 different colors, which I do with with fill=‘tozeroy’ in the scatter object. When I add this attribute though, the axis automatically adjusts to include 0. Is there some other way to accomplish the axis control without losing the fill behavior?
Edit: Here’s some sample code
import plotly.graph_objs as go
from plotly.subplots import make_subplots
figure = make_subplots(specs=[[{"secondary_y": True}]])
trace1 = go.Scatter(x=[1,2,3,4,5,6,7,8,9],
y=[10,11,12,12,11,10,9,9,9],
mode='lines',
opacity=0.7,
name='Line1',
textposition='bottom center',
line=dict(width=1.25, color='rgb(0, 0, 255)'),
fill='tozeroy',
fillcolor='rgba(77, 77, 255, 0.5)',
connectgaps=False,
)
trace2 = go.Scatter(x=[1,2,3,4,5,6,7,8,9],
y=[11,13,16,12,9,8,6,6,6],
mode='lines',
opacity=0.7,
name='Line2',
textposition='bottom center',
line=dict(width=1.5, color='rgb(255, 0, 0)'),
fill='tozeroy',
fillcolor='rgba(255, 77, 77, 0.7)',
connectgaps=False,
)
figure.add_trace(trace1)
figure.add_trace(trace2)
figure.update_layout(height=600,
title="test",
xaxis={"title": "Date",
'rangeselector': {'buttons': list(
[{'count': 1, 'label': '1D', 'step': 'day', 'stepmode': 'backward'},
{'count': 7, 'label': '7D', 'step': 'day', 'stepmode': 'backward'},
{'count': 1, 'label': 'MTD', 'step': 'month', 'stepmode': 'todate'},
{'step': 'all'}])},
'rangeslider': {'visible': True}, 'type': 'date'},
yaxis={"title": "units"})
figure.show()
I want this appearance, but the axis should scale to ~4 rather than 0, just as it does without fill=‘tozeroy’