PlotlyJS confidence band bug?

Hi all,

I’m trying to plot confidence bands using PlotlyJS.jl. It’s almost working, except that while the lines all start at x = 50, the confidence bands, for some reason, start at x = 0. This is for instance how I define one of the traces:

trace1 = scatter(;
  x = vcat(50:1000, reverse(50:1000)),
  y = vcat(df_train.ymax1, reverse(df_train.ymin1)),
  fillcolor="rgba(0, 100, 80, .2)",
  name = "Actual",

The output I get is:

Does someone know how to avoid this? (If the problem is not clear, please look at the bottom left corner of the plot. The question basically is how to remove the bands that appear between x=0 and x=50. They should start at x=50 [in this plot, they are hardly visible from that point on, but they are there].)

Here is a MWE illustrating the same problem:

using PlotlyJS

trace = scatter(;x=vcat(5:50, 50:-1:5), y=vcat(rand(46), rand(46) .- 2), fill="tozerox")

plot(trace, Layout())

My question is: how to prevent the confidence bands from starting at x=0?


Tried that already but doesn’t work. (In the MWE, yes, but not in my example.)

FWIW, in this example, both the lower and the uppper bound curves are plotted, and fill="tonexty" is used.

Add first as trace delimiting the band, the lower line, then the upper one, with fill= "tonexty"

using CSV, DataFrames, GLM, PlotlyJS

df ="test-data.csv", DataFrame)
model = lm(@formula(Y ~ X), df)
p = predict(model, df[!, [:X]], interval = :prediction, level = 0.9)
traces= [
         scatter(x=df[!, :X], y=p.lower, line_width=0, showlegend=false),           
         scatter(x=df[!, :X], y=p.upper, fill="tonexty", fillcolor="LightBlue",
                 line_width=0, showlegend=false),
         scatter(x=df[!, :X], y=p.prediction, mode="lines", line_width=2,line_color="RoyalBlue", name="reg line"),
         scatter(x=df[!, :X], y=df[!,:Y], mode="markers", marker_color="RoyalBlue", 
fig=Plot(traces, Layout(width=600, height=350))



Many thanks, that worked! Final plot:

Would be good to have this in the documentation (more helpful than the examples that are now given).