Issue with setting axis range for 2D density heatmap

I am trying to plot a 2D density distribution of true vs predicted y values. To compare across datasets, I want to make the 2D distribution โ€œfillโ€ the complete range of values (0 - 1.0)

However, despite setting range_x and range_y, my plot shows an empty grid for the bins where no values exist (when I want the colour at value 0 to be extended to these regions).

Code:

import plotly.express as px 
n = 1000 
fig = px.density_heatmap(
    x=y_true[:n], y=y_pred[:n],
    title="True versus Predicted values",
    labels={"x": "True", "y": "Predicted"},
    marginal_x="histogram",
    marginal_y="histogram",

    color_continuous_scale=px.colors.sequential.Viridis,
    range_x=[0, 1.0],
    range_y=[0, 1.0],
)

width = 800
fig.update_layout(
    # force to be square 
    width=width,
    height=width,
)
fig.show()

How do I enforce the grid to be filled at all ranges that I am setting?

Hey @kamurani welcome to the forums.

Thatโ€™s the expected behavior. In general, plotly graphs depend directly on the data. This means, missing data is not being plotted.

My recommendation would be to add the missing datapoints, i.e fill with zeroes.