openturns icon indicating copy to clipboard operation
openturns copied to clipboard

Grid graph with specific subplots

Open sofianehaddad opened this issue 4 years ago • 3 comments

The GridLayout allows using subplots easily :

import openturns as ot
grid = ot.GridLayout(2, 3)
for j in range(grid.getNbColumns()):
...    beta = 1.0 + j
...    grid.setGraph(0, j, ot.Gumbel(beta, 0.0).drawPDF())
...    grid.setGraph(1, j, ot.Gumbel(beta, 0.0).drawCDF())

And produce something like that:

Is there a way to generate more specific subplots, such as

Could we think about something like :

import openturns as ot
grid = ot.GridLayout(2, 1)
# Upper graph
grid.setGraph(0, 0, graph0)
# subplot second part in two specific ones
sub_layout = ot.GridLayout(1, 2)
sub_layout.setGraph(0, 0, graph1)
sub_layout.setGraph(0, 1, graph2)
# TODO/TOTHINK : set the grid ?
grid.setGraph(1, 0, sub_layout)

sofianehaddad avatar Sep 07 '20 09:09 sofianehaddad

I had this in mind but it's not currently supported. To enable this GridLayout must probably inherit GraphImplementation (that was my first version).

jschueller avatar Sep 07 '20 09:09 jschueller

It was a part of the discussion before to go to the implementation of GridLayout: do we need to have a hierarchical GridLayout or a flat one? The C++ part is pretty obvious to me, but not the matplotlib part...

regislebrun avatar Sep 07 '20 09:09 regislebrun

Another solution is to think about some aggregation, with some code like this:

import openturns as ot
# upper layout
layout1 = ot.GridLayout(1, 1)
grid.setGraph(0, 0, graph0)
# lower layout
layout2= ot.GridLayout(1, 2)
layout2.setGraph(0, 0, graph1)
layout2.setGraph(0, 1, graph2)
# Aggregating layouts
layout = ot.AggregatedLayout(2, 1,  (layout1, layout2))

sofianehaddad avatar Sep 07 '20 09:09 sofianehaddad