scripts: plot[mpl].py: Made subplot width/height defaults more intuitive
So far, I think the use of ratios for subplot widths/heights has worked
well, with the exception of the default behavior for repeated neighbors
being a bit garbage.
Before, the default was a simple 0.5x of the current row/column:
./scripts/csv.py test.csv -xx \
--subplot="-ya" \
--subplot-right="-yb -W0.5" \
--subplot-right="-yc -W0.5" \
--subplot-right="-yd -W0.5" \
--subplot-right="-ye -W0.5"
And while this is certainly simple, it's behavior is not the most
intuitive. When -ye takes 0.5x, it takes 0.5x of the _whole_ grid,
squishing -ya + -yb + -yc + -yd into the other 0.5x as needed. As a
result, -ya ends up with 0.0625x of the final grid.
You could argue this is confusing behavior, but I worry trying to make
it "smarter" will just make it more confusing when multiple dirs/
nestings are mixed.
---
But we can at least change the _default_ behavior to be less confusing.
Now, instead of defaulting to 0.5x, we keep a sum of the number of
subplots seen in the current direction (row vs column), and default the
next subplot's width/height to 1/n.
As a result, repeated subplots end up like the following:
./scripts/csv.py test.csv -xx \
--subplot="-ya" \
--subplot-right="-yb -W0.5" \
--subplot-right="-yc -W0.3333333" \
--subplot-right="-yd -W0.25" \
--subplot-right="-ye -W0.2"
Which may look crazy, but cancels out the nested ratio so the final grid
is a set of evenly distributed columns.
---
Maybe this is still too clever and will need to be reverted in the
future, but in the meantime it provides a nice default for the common
use case of repeated subplots.
This commit is contained in:
+8
-2
@@ -1229,14 +1229,20 @@ class Grid:
|
||||
**args):
|
||||
grid = cls(Subplot(**args))
|
||||
|
||||
wcount = 1
|
||||
hcount = 1
|
||||
for dir, subargs in subplots:
|
||||
subgrid = cls.fromargs(
|
||||
width=subargs.pop('width',
|
||||
0.5 if dir in ['right', 'left'] else width),
|
||||
width/(wcount+1) if dir in ['right', 'left']
|
||||
else width),
|
||||
height=subargs.pop('height',
|
||||
0.5 if dir in ['above', 'below'] else height),
|
||||
height/(hcount+1) if dir in ['above', 'below']
|
||||
else height),
|
||||
**subargs)
|
||||
grid.merge(subgrid, dir)
|
||||
wcount += 1 if dir in ['right', 'left'] else 0
|
||||
hcount += 1 if dir in ['above', 'below'] else 0
|
||||
|
||||
grid.scale(width, height)
|
||||
return grid
|
||||
|
||||
+8
-2
@@ -820,14 +820,20 @@ class Grid:
|
||||
**args):
|
||||
grid = cls(Subplot(**args))
|
||||
|
||||
wcount = 1
|
||||
hcount = 1
|
||||
for dir, subargs in subplots:
|
||||
subgrid = cls.fromargs(
|
||||
width=subargs.pop('width',
|
||||
0.5 if dir in ['right', 'left'] else width),
|
||||
width/(wcount+1) if dir in ['right', 'left']
|
||||
else width),
|
||||
height=subargs.pop('height',
|
||||
0.5 if dir in ['above', 'below'] else height),
|
||||
height/(hcount+1) if dir in ['above', 'below']
|
||||
else height),
|
||||
**subargs)
|
||||
grid.merge(subgrid, dir)
|
||||
wcount += 1 if dir in ['right', 'left'] else 0
|
||||
hcount += 1 if dir in ['above', 'below'] else 0
|
||||
|
||||
grid.scale(width, height)
|
||||
return grid
|
||||
|
||||
Reference in New Issue
Block a user