def plot_ICBounds(x_test, y_test, nTest, sigma) : 
    vUp =  [[x_test[i][0], y_test[i][0] + sigma ] for i in range(nTest)]
    vLow = [[x_test[i][0], y_test[i][0] - sigma ] for i in range(nTest)]
    polyData = [[vLow[i], vLow[i+1], vUp[i+1], vUp[i]] for i in range(nTest-1)]
    polygonList = [ot.Polygon(polyData[i], "grey", "grey") for i in range(nTest-1)]
    boundsPoly = ot.PolygonArray(polygonList)
    return boundsPoly
Пример #2
0
 def CreatePolygonArray(polyData, color):
     numberOfPolygons = len(polyData)
     polygonList = [
         ot.Polygon(polyData[i], color, color)
         for i in range(numberOfPolygons)
     ]
     polygonArray = ot.PolygonArray(polygonList)
     return polygonArray
Пример #3
0
def drawInTheBounds(vLow,vUp,n_test):
    """
    Draw the area within the bounds.
    """
    palette = ot.Drawable.BuildDefaultPalette(2)
    myPaletteColor = palette[0]
    polyData = [[vLow[i], vLow[i+1], vUp[i+1], vUp[i]] for i in range(n_test-1)]
    polygonList = [ot.Polygon(polyData[i], myPaletteColor, myPaletteColor) for i in range(n_test-1)]
    boundsPoly = ot.PolygonArray(polygonList)
    return boundsPoly
 def fill_between(lower, upper, legend, color):
     """Draw a shaded area between two curves."""
     disc = len(lower)
     poly_data = [[lower[i], lower[i + 1], upper[i + 1], upper[i]]
                  for i in range(disc - 1)]
     polygon = [
         ot.Polygon(poly_data[i], color, color) for i in range(disc - 1)
     ]
     bounds_poly = ot.PolygonArray(polygon)
     bounds_poly.setLegend(legend)
     return bounds_poly
def plot_kriging_bounds(vLow,vUp,n_test):
    '''
    From two lists containing the lower and upper bounds of the region, 
    create a PolygonArray.
    '''
    palette = ot.Drawable.BuildDefaultPalette(2)
    myPaletteColor = palette[1]
    polyData = [[vLow[i], vLow[i+1], vUp[i+1], vUp[i]] for i in range(n_test-1)]
    polygonList = [ot.Polygon(polyData[i], myPaletteColor, myPaletteColor) for i in range(n_test-1)]
    boundsPoly = ot.PolygonArray(polygonList)
    boundsPoly.setLegend("95% bounds")
    return boundsPoly
        def fill_between_(lower, upper, legend):
            """Draw a shaded area between two curves."""
            disc = len(lower)
            palette = ot.Drawable.BuildDefaultPalette(2)[1]
            poly_data = [[lower[i], lower[i + 1], upper[i + 1], upper[i]]
                         for i in range(disc - 1)]

            polygon = [
                ot.Polygon(poly_data[i], palette, palette)
                for i in range(disc - 1)
            ]
            bounds_poly = ot.PolygonArray(polygon)
            bounds_poly.setLegend(legend)

            return bounds_poly
Пример #7
0
def plot_kriging_bounds(dataLower, dataUpper, n_test, color=[120, 1.0, 1.0]):
    """
    From two lists containing the lower and upper bounds of the region,
    create a PolygonArray.
    Default color is green given by HSV values in color list.
    """
    vLow = [[x_test[i, 0], dataLower[i, 0]] for i in range(n_test)]
    vUp = [[x_test[i, 0], dataUpper[i, 0]] for i in range(n_test)]
    myHSVColor = ot.Polygon.ConvertFromHSV(color[0], color[1], color[2])
    polyData = [[vLow[i], vLow[i+1], vUp[i+1], vUp[i]]
                for i in range(n_test-1)]
    polygonList = [ot.Polygon(polyData[i], myHSVColor, myHSVColor)
                   for i in range(n_test-1)]
    boundsPoly = ot.PolygonArray(polygonList)
    return boundsPoly
Пример #8
0
Y1 = ot.CompositeRandomVector(f1, X)
Y2 = ot.CompositeRandomVector(f2, X)
Y3 = ot.CompositeRandomVector(f3, X)

# %%
# We define three basic events :math:`E_1=\{(x_0,x_1)~:~x_0 < 0 \}`, :math:`E_2=\{(x_0,x_1)~:~x_1 > 0 \}` and :math:`E_3=\{(x_0,x_1)~:~x_0+x_1>0 \}`.
e1 = ot.ThresholdEvent(Y1, ot.Less(), 0.0)
e2 = ot.ThresholdEvent(Y2, ot.Greater(), 0.0)
e3 = ot.ThresholdEvent(Y3, ot.Greater(), 0.0)

# %%
# The restriction of the domain :math:`E_1` to :math:`[-4,4] \times [-4, 4]` is the grey area.
myGraph = ot.Graph(r'Representation of the event $E_1$', r'$x_1$', r'$x_2$',
                   True, '')
data = [[-4, -4], [0, -4], [0, 4], [-4, 4]]
myPolygon = ot.Polygon(data)
myPolygon.setColor('grey')
myPolygon.setEdgeColor('black')
myGraph.add(myPolygon)
view = otv.View(myGraph)
axes = view.getAxes()
_ = axes[0].set_xlim(-4.0, 4.0)
_ = axes[0].set_ylim(-4.0, 4.0)

# %%
# The restriction of the domain :math:`E_2` to :math:`[-4,4] \times [-4, 4]` is the grey area.
myGraph = ot.Graph(r'Representation of the event $E_2$', r'$x_1$', r'$x_2$',
                   True, '')
data = [[-4, 0], [4, 0], [4, 4], [-4, 4]]
myPolygon = ot.Polygon(data)
myPolygon.setColor('grey')
Пример #9
0
    # Polygon
    size = 50
    cursor = [0.] * 2
    data1 = ot.Sample(size, 2)  # polygon y = 2x for x in [-25]
    data2 = ot.Sample(size, 2)  # polygon y = x*x for x in [-11]
    for i in range(size):
        tmp = 7. * i / size + 2
        cursor[0] = tmp
        cursor[1] = 2 * tmp
        data1[i] = cursor
        tmp = 9. * i / size + 1
        cursor[0] = tmp
        cursor[1] = tmp * tmp
        data2[i] = cursor
    graph = ot.Graph('Some polygons', 'x1', 'x2', True, 'topright', 1.0)
    myPolygon1 = ot.Polygon(data1)
    myPolygon1.setColor('blue')
    myPolygon1.setLegend('polygon 1')
    graph.add(myPolygon1)
    myPolygon2 = ot.Polygon(data2)
    myPolygon2.setColor('red')
    myPolygon2.setLegend('polygon 2')
    graph.add(myPolygon2)
    # graph.draw('curve11.png')
    view = View(graph)
    # view.save('curve11.png')
    view.ShowAll(block=True)

    # PolygonArray
    generator = ot.Normal(2)
    size = 5
Пример #10
0
for i in range(size):
    tmp = 7. * i / size + 2
    cursor[0] = tmp
    cursor[1] = 2 * tmp
    data1[i] = cursor

    tmp = 9. * i / size + 1
    cursor[0] = tmp
    cursor[1] = tmp * tmp
    data2[i] = cursor

# Create an empty graph
graph = ot.Graph("Polygons example", "x1", "x2", True, "", 1.0)

# Create the first polygon
myPolygon1 = ot.Polygon(data1)
myPolygon1.setColor("blue")

# Then, draw it
graph.add(myPolygon1)

# Create the second polygon
myPolygon2 = ot.Polygon(data2)
myPolygon2.setColor("red")

# Add it to the graph and draw everything
graph.add(myPolygon2)
graph.setLogScale(1)

fig = plt.figure(figsize=(5, 5))
View(graph, figure=fig)
Пример #11
0
graph_meta = meta.draw(xMin, xMax)
data = graph_meta.getDrawable(0).getData()
xGrid = data.getMarginal(0)
covGrid = result.getConditionalCovariance(xGrid)
a = ot.DistFunc.qNormal(0.975)
c = ot.Cloud([data[2]])
c.setPointStyle("square")
c.setColor("green")
c.setLegend("95% confidence bound")
dataLower = [[data[i, 0], data[i, 1] - a * covGrid[i, i]]
             for i in range(len(data))]
dataUpper = [[data[i, 0], data[i, 1] + a * covGrid[i, i]]
             for i in range(len(data))]
bounds = ot.PolygonArray([
    ot.Polygon(
        [dataLower[i], dataLower[i + 1], dataUpper[i + 1], dataUpper[i]],
        "green", "green") for i in range(len(dataLower) - 1)
])
graph = ot.Graph()
graph.setLegendPosition("bottomright")
graph.setAxes(True)
graph.setGrid(True)
graph.add(c)
graph.add(bounds)

d = f.draw(xMin, xMax).getDrawable(0)
d.setLineStyle("dashed")
d.setColor("magenta")
d.setLineWidth(2)
graph.add(d)
graph.add(graph_meta)
Пример #12
0
import openturns as ot
from openturns.viewer import View

ot.RandomGenerator.SetSeed(0)
generator = ot.Normal(2)
size = 5
array = []
palette = ot.Drawable.BuildDefaultPalette(size)
for i in range(size):
    vertices = generator.getSample(3)
    array.append(ot.Polygon(vertices, palette[i], palette[size - i - 1]))

graph = ot.Graph('PolygonArray example', 'x1', 'x2', True, '', 1.0)
graph.add(ot.PolygonArray(array))

View(graph, figure_kwargs={'figsize': (4, 4)})