3

Is there a standard, effective way of producing a QQ-Plot using Plotly?

I would be interested in testing the normal/log-normal fit of my data.

1 Answer 1

13

Alright, here is how I think the state of affairs is now [2020 edit]:

Say we have 500 random draws from a distribution which we think might be the lognormal distribution:

X_lognorm = np.random.lognormal(mean=0.0, sigma=1.7, size=500)

Plotting

Imports

import numpy as np
from scipy import stats
import plotly.graph_objects as go

Run plotly

qq = stats.probplot(X_lognorm, dist='lognorm', sparams=(1))
x = np.array([qq[0][0][0], qq[0][0][-1]])

fig = go.Figure()
fig.add_scatter(x=qq[0][0], y=qq[0][1], mode='markers')
fig.add_scatter(x=x, y=qq[1][1] + qq[1][0]*x, mode='lines')
fig.layout.update(showlegend=False)
fig.show()

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

I applied this to a plotly dash script but I had to make the figure as a go.Figure object. That is, instead of fig = dict(data=data, layout=layout) I had fig = go.Figure(data, layout=layout) .
Things have changed since 2018 :) I have updated the code (not the plot though). It's much simpler now.
Hey, the docs say "probplot generates a probability plot, which should not be confused with a Q-Q or a P-P plot. Statsmodels has more extensive functionality of this type, see statsmodels.api.ProbPlot" which might be worth bearing in mind if you explicitly want a qq plot (docs = docs.scipy.org/doc/scipy/reference/generated/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.