1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#! /usr/bin/env python
import openturns as ot
import math as m
ot.TESTPREAMBLE()
# Instantiate one distribution object
dim = 1
meanPoint = ot.Point(dim, 1.0)
meanPoint[0] = 0.5
sigma = ot.Point(dim, 1.0)
sigma[0] = 2.0
R = ot.CorrelationMatrix(dim)
distribution1 = ot.Normal(meanPoint, sigma, R)
# Instantiate another distribution object
meanPoint[0] = -1.5
sigma[0] = 4.0
distribution2 = ot.Normal(meanPoint, sigma, R)
# Test for sampling
size = 2000
nBars = 20
sample1 = distribution1.getSample(size)
sample2 = distribution2.getSample(size)
# Construct histograms
epsilon = 0.1
min1 = sample1.getMin()[0]
max1 = sample1.getMax()[0] + epsilon
min2 = sample2.getMin()[0]
max2 = sample2.getMax()[0] + epsilon
tmp = ot.Point(2)
tmp[0] = (max1 - min1) / nBars
data1 = ot.Sample(nBars, tmp)
tmp[0] = (max2 - min2) / nBars
data2 = ot.Sample(nBars, tmp)
for i in range(size):
index = int(m.floor((sample1[i, 0] - min1) / (max1 - min1) * nBars))
data1[index, 1] += 1
index = int(m.floor((sample2[i, 0] - min2) / (max2 - min2) * nBars))
data2[index, 1] += 1
# Create an empty graph
myGraph = ot.Graph("Some barplots", "y", "frequency", True, "topleft")
# Create the first barplot
myBarPlot1 = ot.BarPlot(data1, min1, "blue", "shaded", "dashed", "histogram1")
# Then, draw it
myGraph.add(myBarPlot1)
# Check that the correct files have been generated by computing their
# checksum
# Create the second barplot
myBarPlot2 = ot.BarPlot(data2, min2, "red", "solid", "solid", "histogram2")
# Add it to the graph and draw everything
myGraph.add(myBarPlot2)
|