From 751b89a26358e40dfa1dd4f5c98b9f30d399c2bd Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 15 Feb 2026 14:48:38 -0600 Subject: [PATCH] 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. --- scripts/plot.py | 10 ++++++++-- scripts/plotmpl.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/plot.py b/scripts/plot.py index 79c5f92c..158d94e0 100755 --- a/scripts/plot.py +++ b/scripts/plot.py @@ -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 diff --git a/scripts/plotmpl.py b/scripts/plotmpl.py index 1ab7d7fb..43f318cb 100755 --- a/scripts/plotmpl.py +++ b/scripts/plotmpl.py @@ -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