I am creating a plot with two y axes. first trace is a bar graph
second trace is a line chart
When the chart is rendered the secondary trace does not touch the sides of the graph as the data starts and stops where it lands.
is it possible to โfakeโ the secondary y axis to touch the sides?
Here is my code
import plotly.graph_objects as go
import plotly.express as px
# Load the gapminder dataset
gapminder = px.data.gapminder()
# Create a mask for Afghanistan
mask = gapminder["country"] == "Afghanistan"
fig = go.Figure()
# Add a trace for Afghanistan lifeExp data.
fig.add_trace(
go.Bar(
x=gapminder[mask]["year"],
y=gapminder[mask]["lifeExp"],
name="Life Expectancy",
)
)
# Add a trace for Afghanistan gdpPercap data,
fig.add_trace(
go.Scatter(
x=gapminder[mask]["year"],
y=gapminder[mask]["gdpPercap"],
fill="tozeroy",
yaxis="y2",
name="GDP Per Capita",
)
)
# Update layout to include a secondary y-axis and a title
fig.update_layout(
title="Life Expectancy vs GDP Per Capita",
xaxis=dict(
title="Years",
),
yaxis=dict(
title="Life Expectancy",
titlefont=dict(color="rgb(0, 0, 0)"),
tickfont=dict(color="rgb(148, 103, 189)"),
),
yaxis2=dict(
title="GDP Per Capita",
titlefont=dict(color="rgb(0, 0, 0)"),
tickfont=dict(color="rgb(0, 0, 0)"),
overlaying="y",
side="right",
)
)
fig.show()
is this possible?