I have a specific Pareto distribution. For example,
Pareto(beta=0.00317985, alpha=0.147365, gamma=1.0283)
which I obtained from this answer and now I want to plot a graph of its Probability Density Function (PDF) in matplotlib. So I believe that the x-axis will be all positive real numbers, and the y-axis will be the same.
How exactly can I obtain the appropriate PDF information and plot it? Programmatically obtaining the mathematical PDF function or coordinates is a requirement for this question.
UPDATE:
The drawPDF
method returns a Graph object that contains coordinates for the PDF. However, I don't know how to access these coordinates programmatically. I certainly don't want to convert the object to a string nor use a regex to pull out the information:
In [45]: pdfg = distribution.drawPDF()
In [46]: pdfg
Out[46]: class=Graph name=pdf as a function of X0 implementation=class=GraphImplementation name=pdf as a function of X0 title= xTitle=X0 yTitle=PDF axes=ON grid=ON legendposition=topright legendFontSize=1
drawables=[class=Drawable name=Unnamed implementation=class=Curve name=Unnamed derived from class=DrawableImplementation name=Unnamed legend=X0 PDF data=class=Sample name=Unnamed implementation=class=Sam
pleImplementation name=Unnamed size=129 dimension=2 data=[[-1610.7,0],[-1575.83,0],[-1540.96,0],[-1506.09,0],[-1471.22,0],[-1436.35,0],[-1401.48,0],[-1366.61,0],...,[-1331.7,6.95394e-06],[2852.57,6.85646e-06]] color
=red fillStyle=solid lineStyle=solid pointStyle=none lineWidth=2]
I assume that you want to perform different tasks:
Each of these needs requires a different script. Please let me detail them.
I first create the
Pareto
distribution:To plot the PDF, use
drawPDF()
method. This creates aot.Graph
which can be viewed directly in Jupyter Notebook or IPython. We can force the creation of the plot withView
:This plots:
To compute the PDF at a single point, use
computePDF(x)
, wherex
is aot.Point()
. This can also be a Pythonlist
ortuple
or 1D numpyarray
, as the conversion is automatically managed by OpenTURNS:The previous script prints:
To compute the PDF for a range of values, we can use the
computePDF(x)
, where x is aot.Sample()
. This can also be a Pythonlist
of lists or a 2D numpyarray
, as the conversion is automatically managed by OpenTURNS.The previous script prints: