Skip to content
Matthew Robinson edited this page Aug 7, 2016 · 2 revisions

Plotting Random Variables

Plot Dist

PlotDist is called to display a two-dimensional plot of a random variable. The first argument is the random variable to be plotted, and the second argument is an optional argument that defines the limits of the plots. If not limits are given, the supports of the random variable are used as the default. For distributions with infinite supports, the 1st and 99th percentile are used instead. The color arguments takes a string as input and allows the user to specify the color of the plot. If multiple PlotDist commands are issued, APPLPy will continue to overlay the current plot until a PlotClear() command is issued. After a plot is generated, the limits can be adjusted using PlotLimits, as in the example below. When available, APPLPy uses seaborn for plot formatting. If matplotlib is imported into a python interactive session, matplotlib commands can be used to further customize APPLPy plots.

Syntax

PlotDist(X,[support],opt=None,color='red',display=True)

Examples:

In [4]: X=TriangularRV(2,4,6)

In [5]: Y=TriangularRV(3,5,7)

In [6]: Z=Mixture([.4,.6],[X,Y])

In [7]: PlotDist(Z)

In [8]: PlotDist(Z,color='green')

Plot Dist Example

In [9]: X=ExponentialRV(1/3)

In [10]: Y=ExponentialRV(1/2)

In [11]: PlotDist(X,color='red')

In [12]: PlotDist(Y,color='blue')

In [13]: PlotLimits([0,12], axis = 'x')

Multiple Plots

The plot interface can be cleared using the PlotClear command. After that is issued, new plots will begin to overlay on top of a new plot interface. Also, matplotlib commands can be used to customize aspects of the plot, such as the title.

In [14]: PlotClear()

In [15]: Xstar = BootstrapRV(X.variate(n=100))

In [16]: PlotDist(CDF(X))

In [17]: PlotDist(CDF(Xstar))

In [18]: plt.title('Comparison of Exponential CDF and Bootstrapped EDF')

CDF Plots

Clone this wiki locally