Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GridLayout has limited features #1769

Open
mbaudin47 opened this issue Feb 12, 2021 · 0 comments
Open

GridLayout has limited features #1769

mbaudin47 opened this issue Feb 12, 2021 · 0 comments

Comments

@mbaudin47
Copy link
Collaborator

mbaudin47 commented Feb 12, 2021

The new GridLayout class is extremely useful to see the data. However, we often combine various graphs in order to compare two informations:

  • a curve vs another curve,
  • a cloud versus a curve,
  • two clouds.

There are two different missing features:

  • When two GridLayout are created, it is not easy to merge them into a single one, because the add feature of Graph is not available: GridLayout.add(GridLayout) does not exist,
  • When a GridLayout is created, we may want to configure some services, such as the colors, or other features. But GridLayout.setColors(colors) does not exist.

The grid.add(other_grid) method would first check that the number of rows/columns match, otherwise an exception should be generated. Then each graph of other_grid would be added to each graph of grid.
The GridLayout.setColors(colors) would just propagate the effect of setColors to each graph of the grid.

Hence, the "workaround" is to configure or add each graph separately, putting each graph into the grid afterwards.
I write below two different use cases.

  • The first one creates two GridLayout and tries to merge them.
  • The second creates two GridLayout using DrawPairs and merges them.
import openturns as ot
import openturns.viewer as otv


def propagate_set_colors(grid, colors):
    nbRows = grid.getNbRows()
    nbColumns = grid.getNbColumns()
    for i in range(nbRows):
        for j in range(nbColumns):
            graph = grid.getGraph(i, j)
            graph.setColors(colors)
            grid.setGraph(i, j, graph)
    return grid

def propagate_add(grid, other_grid):
    nbRows = grid.getNbRows()
    nbColumns = grid.getNbColumns()
    for i in range(nbRows):
        for j in range(nbColumns):
            graph = grid.getGraph(i, j)
            other_graph = other_grid.getGraph(i, j)
            graph.add(other_graph)
            grid.setGraph(i, j, graph)
    return grid

palette = ot.DrawableImplementation.BuildDefaultPalette(2)

# Use case #1
nbrows = 2
nbcols = 3
# First
grid1 = ot.GridLayout(nbrows, nbcols)
for j in range(nbcols):
    beta = 1.0 + 2 * j
    distribution = ot.Gumbel(beta, 0.0)
    graph = distribution.drawPDF()
    graph.setLegends([r"$\beta$=%s" % (beta)])
    grid1.setGraph(0, j, graph)
    graph = distribution.drawCDF()
    graph.setLegends([r"$\beta$=%s" % (beta)])
    grid1.setGraph(1, j, graph)

grid1 = propagate_set_colors(grid1, [palette[0]])
otv.View(grid1)

# Second
grid2 = ot.GridLayout(nbrows, nbcols) # Same shape
for j in range(nbcols):
    mu = 1.0 + 2 * j
    distribution = ot.Normal(mu, 1.0)
    graph = distribution.drawPDF()
    graph.setLegends([r"$\mu$=%s" % (mu)])
    grid2.setGraph(0, j, graph)
    graph = distribution.drawCDF()
    graph.setLegends([r"$\mu$=%s" % (mu)])
    grid2.setGraph(1, j, graph)

grid2 = propagate_set_colors(grid2, [palette[1]])
otv.View(grid2)

# Add!
# grid1.add(grid2) # 'GridLayout' object has no attribute 'add'
grid1 = propagate_add(grid1, grid2)
otv.View(grid1)

# Use case #2
# Sample A
dim = 3
R = ot.CorrelationMatrix(dim)
R[0, 1] = 0.8
distribution = ot.Normal([3.0] * dim, [2.0]* dim, R)
size = 100
sample = distribution.getSample(size)
grid1 = ot.VisualTest.DrawPairs(sample)
# grid1.setColors([palette[0]]) # 'GridLayout' object has no attribute 'setColors'
grid1 = propagate_set_colors(grid1, [palette[0]])
otv.View(grid1)

# Sample B
dim = 3
R = ot.CorrelationMatrix(dim)
R[0, 1] = -0.2
distribution = ot.Normal([-2.0] * dim, [2.0]* dim, R)
size = 100
sample = distribution.getSample(size)
grid2 = ot.VisualTest.DrawPairs(sample)
grid2 = propagate_set_colors(grid2, [palette[1]])
otv.View(grid2)

# Add!
# grid1.add(grid1)  # 'GridLayout' object has no attribute 'add'
grid1 = propagate_add(grid1, grid2)
otv.View(grid1)

Figure for case A:
image

Figure for case B:
image

I try to identify other services that would be missing.

  • Propagating the title would be meaningless if the same title is applied to all graphs in the grid. This is the same for setXTitle and setYTitle.
  • Methods that could be propagated are: setLegendPosition, setLogScale, setAutomaticBoundingBox, setAxes, setBoundingBox, setDefaultColors, setLegendFontSize.

The application of these features is for othdrplot, which heavily uses grids of graphs : https://github.com/mbaudin47/othdrplot/blob/master/doc/examples/ProcessHighDensityRegionAlgorithm-3D-example.ipynb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants