It does locate in (0.3, 0.8)
import matplotlib.pyplot as plt
plt.plot(x,pdf_1)
plt.plot(x,pdf_2)
plt.plot(x,conv_pdf[:len(x)]) # Since you used 'full', shape of conv_pdf is len(pdf_1)+len(pdf_2)-1=199999. Corresponding to result in interval [0,2[. Which is expected
plt.axvline(0.3)
plt.axvline(0.8)

Only difference between this and your code, is my usage of matplotlib rather than plotly.
And, probably more importantly, the truncation, since full convolution has a bigger shape than the input arrays. Index i being Σaₘbᵢ₋ₘ
, so if you consider index 0 to be x=0, and index 99999 to be x=1, that is the estimation of ∫a(x)b(i/99999-x)dx
, which is (a*b)(i/99999)
. So a*b
in interval [0,1] is indeed conv_pdf[:100000]
. The fact that conv_pdf
has more value, simply match the fact that you also computed (a*b)(x)
for all x in [0,2[.
That is why I am confident in the fact that plotting conv_pdf[:100000]
is the right thing to do.
As for why you get another result, I don't really know. But I can surmise that is because plotly reacts differently from matplotlib when your x
array and y
array for a plot have different length. Matplotlib would just fail if you plt.plot(x,conv_pdf)
. While plotly apparently reinterpret, or interpolate, or something, the data. But the point is, it is quite normal that this line
fig.add_scatter(x=x_vec, y=conv_pdf, name='convolution')
has a strange behaviour, since x
and y
do not match in size
Edit
Out of curiosity, I've installed plotly, and tried your code: no shift. And no error raised.
So half of what I said is true: plotly does react differently than matplotlib. Matplotlib would fail, because conv_pdf
hasn't the same shape as x_vec
. Plotly, indeed doesn't.
But, at least with the version I have, it just truncates the plot, and plot only the part that makes sense (so it plots only 100000 first value of conv_pdf
and drop the rest. Exactly as I did with my plt.plot(x, conv_pdf[:100000])
.
So, my answer should have been rather a vote for "non reproducible or caused by a typo". Since, what you've here, is
- either a bug in your plotly version (bug probably related to the different size, tho. I would have hard time to imagine that any plotly version could just shif a plain
scatter(x,y)
with x and y of the same size).
- or a problem in your experiment (obviously, your code is not exactly what you posted, since you name the x coordinates
x
first, then x_vec
; so I take that the code you posted is an attempt to summarize experiments you made in a notebook or an interactive interpreter. So, are you sure that conv_pdf
is the correct one) ?
Either way, when I copy literaly your code in my interpreter, with the only correction of adding a x_vec=x
alias, I get with plotly the exact same plot than my previous one (but with the style of yours)
Result of your code (edit in edit: in the meantime, while I was typing this, you corrected your code. So, to be extrasure, I just redid the figure with a verbatim copy&paste of your cod, and this is what I get)
