Data Visualization Examples
Begin by loading the Statistics package.
with(Statistics):
Combining Visualizations
A := <5, 2, 5, 8, 4, 5, 10, 5>:
B := map(t -> t-.5, A):
Generate bar chart and line chart.
P := ColumnGraph(A, legend = ["Data Set A"]):
Q := LineChart(B, color = red, thickness = 3, symbol = circle, symbolsize = 10, legend = ["Data Set B"]):
Superimpose the two plots and display the result.
plots[display](P, Q, title = "Bar Chart and Line Chart", axis[2] = [gridlines = [7, thickness = 2, linestyle = dash, color = white]]);
Pie Chart
Generate a pie chart.
T := <a, b, c, a, a, b, a, a, a, b, b, c, c, 1, 2, 3, a, 1>:
PieChart(T, sector = 0..180, color = red..yellow);
Sampling from the Beta Distribution
Generate a random sample drawn from the non-central Beta distribution. Generate a box plot and a histogram and display them in a single plot.
X := RandomVariable(NonCentralBeta(1, 2, 3)):
S := Sample(X, 10^4):
P := BoxPlot(S, orientation = horizontal, offset = -.6, width = .1, deciles = false):
Q := Histogram(S):
R := DensityPlot(X, range = 0..1, thickness = 3):
plots[display](P, Q, R, gridlines = true);
Use a probability plot to compare a sample distribution and the original distribution.
T := Sample(X, 10^2):
ProbabilityPlot(T, X);
Exploring Data Sets
You can use the Explore command to interactively explore characteristics of datasets, such as point density using the ScatterPlot and SunflowerPlot commands:
Y := Vector( [Sample( RandomVariable(Normal(0, 1)), 200 ), Sample( RandomVariable(Normal(2.6, 1)), 200 )] ):
Z := Vector( [Sample( RandomVariable(Normal(0, 1)), 200 ), Sample( RandomVariable(Normal(2.6, 1)), 200 )] ):
ExcisePoints := proc( fractionexcised, dataset1, dataset2, plottype ) uses Statistics; local plotopts; plotopts := view = [min(dataset1)..max(dataset1), min(dataset2)..max(dataset2)]; `if`( plottype = "SunflowerPlot", SunflowerPlot( Excise(evalf[3](fractionexcised), dataset1, dataset2 ), plotopts ), ScatterPlot( Excise(evalf[3](fractionexcised), dataset1, dataset2 ), plotopts ) ); end proc:
Explore( ExcisePoints( fractionexcised, Y, Z, plottype ), parameters = [[plottype = ["ScatterPlot","SunflowerPlot"], label = ` `, placement = bottom], [ fractionexcised = -1.0 .. 1.0, label = `Fraction Excised` ] ], initialvalues = [fractionexcised = 0], title = "Excising Data" );
ScatterPlotSunflowerPlot
Note: Before interacting with this interactive example, you need to execute the code. (Either execute the entire worksheet, or execute the first command to load the package and then execute all the commands in this Exploring Data Sets section.)
Return to Index for Example Worksheets
See Also
Statistics, Statistics Visualization Overview
Download Help Document