Hi,

I've been experimenting with a simple idea for specifying plot layout in a rather intuitive way.
The idea is simply to "draw" your layout using strings.

Examples:

layout = ["AB"]
-> means two plots side by side with equal width

layout = ["AAAB"]
-> means two plots side by side A being 3 times wider than B

layout = ["AB",
          "CC"]
-> means two plots (A & B) side by side and C below with full width

layout = ["AB",
          "C "]
-> means two plots (A & B) side by side and C below A (same width)

etc... (have a look at sources)

I guess you cannot express every layout but it might work for most common ones.

If you think this might a good addition I can try to make a PR but I'm not sure where to insert it.
My idea would be to have a layout function such that you can write:

A,B,C = plt.layout(["AB", "CC"], border=0.01)
A.plot(...)
B.plot(...)
C.plot(...)


Nicolas


def parse(layout, border=0.02):

    plots = {}
    for y,line in enumerate(layout[::-1]):
        for x,letter in enumerate(line):
            if letter == ' ':
                continue
            if letter in plots.keys():
                (x_start,y_start), (x_stop,y_stop) = plots[letter]
                x_stop = max(x+1,x_stop)
                y_stop = max(y+1,y_stop)
                plots[letter] = [(x_start,y_start),
                                 (x_stop,y_stop)]
            else:
                plots[letter] = [(x,y), (x+1,y+1)]

    width  = float(len(layout[0])*(1+border))
    height = float(len(layout)*(1+border))
    for key, value in plots.items():
        (x_start,y_start), (x_stop,y_stop) = value
        x = x_start / width
        w = (x_stop-x_start) / width
        y = y_start / height
        h = (y_stop-y_start) / height
        plots[key] = x+border, y+border, w-border, h-border
    return [(name, extents) for name,extents in plots.items()]


 # A,B side by side
layout = ["AB"]

# A,B, side by side, A 3 times bigger than B
# layout = ["AAAB"]

# A,B side by side, C below (full width)
layout = ["AB",
          "CC"]

# A,B side by side, C below A
layout = ["AB",
          "C "]

# B within A
layout = ["AAAAA",
          "AAAAA",
          "AAABB",
          "AAABB"]


import matplotlib.pyplot as plt
for name, extents in parse(layout):
    plt.axes(extents)
    plt.xticks([]), plt.yticks([])
    plt.text(0.5,0.5, name, ha='center', va='center', size=32)
plt.show()
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to