FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

MEP28 : Semi-graphical specification of subplots layout by rougier · Pull Request #4384 · matplotlib/matplotlib · GitHub

Repository navigation

MEP28 : Semi-graphical specification of subplots layout - #4384

Closed
rougier wants to merge 10 commits into
matplotlib:masterfrom
rougier:MEP28
Closed

rougier wants to merge 10 commits into
matplotlib:masterfrom
rougier:MEP28

Conversation

rougier commented Apr 27, 2015

Copy link
Copy Markdown
Member

[Work in Progress]

This is an early draft for a semi-graphical specification of subplots layout. The main idea is to use an array of strings to specify the location and relative size of subplots. Very early draft far from complete but I think feedbacks are needed at this point.

tacaswell added this to the proposed next point release milestone Apr 27, 2015

Copy link
Copy Markdown
Contributor

Wonderful idea. I think the most common usecases could be implemented via gridspec.

Copy link
Copy Markdown
Contributor

Actually capturing the common use cases is quiete easy:

import matplotlib.pyplot as plt    
def parase_layout(s):
    s = [list(i) for i in s]
    s_T = transpose_list(s)
    n_cols = len(s[0])
    n_rows = len(s)    
    added_axes = {}    
    for i, row in enumerate(s):
        for j, ch in enumerate(row):
            if not ch in added_axes:
                width = n_rows-row.index(ch)-row[::-1].index(ch)
                height = n_cols-s_T[j].index(ch)-s_T[j][::-1].index(ch)
                added_axes[ch] = ((i,j), width, height)
    return added_axes, (n_rows, n_cols)

def transpose_list(l):
    return map(list, zip(*l))

def layout(s):
    d, (nr, nc) = parase_layout(s)
    gs = plt.GridSpec(nr, nc)
    for pos, width, height in d.values():    
        t = gs[pos[0]:pos[0]+height, pos[1]:pos[1]+width]
        plt.subplot(t)

s = ['AAB', 'AAB', 'CCC']
layout(s)

Comment thread doc/devel/MEP/MEP28.rst Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Assuming the case "AaB", is the width of A and B equal or is A smaller?

Copy link
Copy Markdown
Member

Do the values of the chars used to describe the layout matter? I.e. what about "MPL" to produce:

┌────────┐┌────────┐┌────────┐
│   M    ││   P    ││   L    │
│        ││        ││        │
│        ││        ││        │
└────────┘└────────┘└────────┘

What about non-latin characters, like Greek? "ΓγΔδ"
What about non-latin characters that don't have capital letters, like Chinese or Arabic? Seeing how in Chinese a single character can represent a whole word, or even more, it feels like the Chinese should write even better descriptors then what single chars allow for us in English.

rougier commented Apr 28, 2015

Copy link
Copy Markdown
Member Author

@OceanWolf You're right, I don't seen any reason to not use utf8 character but the ascii restriction might make thing simpler in a first version.

For your example, I think it makes sense to write A,B,C = layout("MPL") or M,P,L = layout("MPL")

Copy link
Copy Markdown
Member

Great, I just love seeing code written as generically as possible. I see the hassles that firefox now have rewriting virtually their entire codebase to support languages that don't work right-to-left-top-to-bottom. It has taken them years to sort that out, and still it continues...

Comment thread doc/devel/MEP/MEP28.rst Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Being able to use Python triple-quoted strings here might also be nice:

layout("""
AB
CD
""")

Here, it would to s.strip().split('\n') to get to the "list of strings" as currently specified here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, but I'm not fan of the line return. I would prefer something like:

layout("""AB
          CB""")

or maybe:

layout("AB",
       "CB")

rougier commented Apr 28, 2015

Copy link
Copy Markdown
Member Author

@mdboom Sorry, I missed you comment. I try to modify the MEP along with comments but then github interfaces hides outdated comments.

The A/a thing was suggested on the mailing list but I agree it's a bit strange. We could also have keyword arguments to specify where to add colorbars but I can't think of an intuitive syntax.

For your example, I would love to have:

  AaB
  CDE

  ┌───────┐┌─┐      ┌───────┐
  │ A     ││ │      │ B     │
  │       ││ │      │       │
  │       ││ │      │       │
  └───────┘└─┘      └───────┘
  ┌───────┐┌───────┐┌───────┐
  │ C     ││ D     ││ E     │
  │       ││       ││       │
  │       ││       ││       │
  └───────┘└───────┘└───────┘

Copy link
Copy Markdown
Member

If I understand how it works, the letters just group axes together with repeated letters indicating that that axes should occur larger. A "colorbar" axes (and I put that inverted commas because I don't think we should limit ourselves to just colorbars here) has a fixed width, i.e. it doesn't expand when the window expands, hence I don't see the need for letters for this type of axes.

How about we use the four operator symbols (+, -, /, *) to denote fixed width axes above, below, left and right respectfully. I would imagine that these axes should eat into the space assigned.

Hence ["AB/", "CD"] gives:

┌───────┐┌─┐┌────┐
│ A     ││ ││ B  │
│       ││ ││    │
│       ││ ││    │
└───────┘└─┘└────┘
┌───────┐┌───────┐
│ C     ││ D     │
│       ││       │
│       ││       │
└───────┘└───────┘

and ["A*B", "CD"] gives either what you outlined above, or the following:

┌────┐┌─┐┌───────┐
│ A  ││ ││ B     │
│    ││ ││       │
│    ││ ││       │
└────┘└─┘└───────┘
┌───────┐┌───────┐
│ C     ││ D     │
│       ││       │
│       ││       │
└───────┘└───────┘

Alternatively if we don't eat into the space, then ["A*B", "CDE"] gives:

  ┌───────┐┌─┐┌───────┐
  │ A     ││ ││ B     │
  │       ││ ││       │
  │       ││ ││       │
  └───────┘└─┘└───────┘
  ┌───────┐   ┌───────┐┌───────┐
  │ C     │   │ D     ││ E     │
  │       │   │       ││       │
  │       │   │       ││       │
  └───────┘   └───────┘└───────┘

rougier commented Apr 29, 2015

Copy link
Copy Markdown
Member Author

But how would you specify horizontal colorbars ?
Maybe we abandon the idea of fixed width/height for a first implementation.

Copy link
Copy Markdown
Member

@rougier to get travis happy you should make sure that MEP28.rst is included in the toc tree in https://github.com/matplotlib/matplotlib/blob/master/doc/devel/MEP/index.rst

We are treating Sphinx warnings as errors when building the docs and this raises a not included warning.

Copy link
Copy Markdown
Contributor

Implenting fixed size axes is not too hard, the problem in matplotlib is more to choose the right size.

Copy link
Copy Markdown
Member

@rougier Horizontal axes would work exactly the same but using the + and - suffixes.

tacaswell removed this from the 2.1 (next point release) milestone Sep 24, 2017
tacaswell added this to the 2.2 (next next feature release) milestone Sep 24, 2017
jklymak added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Dec 12, 2017

jklymak commented Mar 18, 2018

Copy link
Copy Markdown
Member

I think all this functionality is carried out by gridspec. I'm going to close due to inactivity. Feel free to re-open if this is inappropriate...

jklymak closed this Mar 18, 2018

Copy link
Copy Markdown
Member

Do we want to merge not-implemented MEPs to keep a record of them?

jklymak commented Mar 18, 2018

Copy link
Copy Markdown
Member

The MEP process is a bit of mystery to me. But in this case it was never merged, so I assume it was never accepted.

In this case I think a little helper function could be written that wrapped GridSpec and add subplot to do what this MEP proposes. But maybe I’m missing something.

rougier mentioned this pull request May 27, 2020
12 of 13 tasks
story645 removed this from the future releases milestone Oct 6, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: geometry manager LayoutEngine, Constrained layout, Tight layout

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants


Back | FazBrowse Home | New Git URL