# Graphical copula validation # --------------------------- # # In this paragraph we visualize an estimated copula versus the data in the rank space. # # %% # First we create data marginals = [ot.Normal()] * 2 dist = ot.ComposedDistribution(marginals, ot.ClaytonCopula(3)) N = 500 sample = dist.getSample(N) # %% # We build a estimate copula from the previous sample using the :class:`~openturns.ClaytonCopulaFactory` : estimated = ot.ClaytonCopulaFactory().build(sample) # %% # We represent data as a cloud in the rank space : ranksTransf = ot.MarginalTransformationEvaluation( marginals, ot.MarginalTransformationEvaluation.FROM) rankSample = ranksTransf(sample) rankCloud = ot.Cloud(rankSample, 'blue', 'plus', 'sample') # %% # We can plot the graph with rank sample and estimated copula : myGraph = ot.Graph('Parametric estimation of the copula', 'X', 'Y', True, 'topleft') myGraph.setLegendPosition('bottomright') myGraph.add(rankCloud)
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View ot.RandomGenerator.SetSeed(0) factory = ot.ClaytonCopulaFactory() ref = factory.build() dimension = ref.getDimension() if dimension <= 2: sample = ref.getSample(50) distribution = factory.build(sample) if dimension == 1: distribution.setDescription(['$t$']) pdf_graph = distribution.drawPDF(256) cloud = ot.Cloud(sample, ot.Sample(sample.getSize(), 1)) cloud.setColor('blue') cloud.setPointStyle('fcircle') pdf_graph.add(cloud) fig = plt.figure(figsize=(10, 4)) plt.suptitle(str(distribution)) pdf_axis = fig.add_subplot(111) View(pdf_graph, figure=fig, axes=[pdf_axis], add_legend=False) else: sample = ref.getSample(500) distribution.setDescription(['$t_0$', '$t_1$']) pdf_graph = distribution.drawPDF([256] * 2) cloud = ot.Cloud(sample) cloud.setColor('red') cloud.setPointStyle('fcircle') pdf_graph.add(cloud) fig = plt.figure(figsize=(10, 4)) plt.suptitle(str(distribution))