scripts: plotmpl.py: Added --w/hpad/w/hspace for low-level pad control
These just expose the low-level w/hpad and w/hspace controls available in matplotlib's constrained_layout. --- I think something funky might be going on with matplotlib's constrained_layout. I've noticed a relatively annoying amount of padding as the number of plots in the grid grow quite large. Though as is usual with plotmpl.py, this may just be my own fault with the amount of hacks being applied. --w/hpad and --w/hspace provide a temporary workaround by overriding the low-level padding controls in matplotlib's constrained_layout (--w/hpad should probably be preferred, --w/hspace seems to be a legacy option). Though, while a temporary solution, these are probably a good idea to keep around for easy tweaking of plot padding.
This commit is contained in:
+4
-2
@@ -2135,14 +2135,16 @@ if __name__ == "__main__":
|
|||||||
nargs='?',
|
nargs='?',
|
||||||
type=lambda x: int(x, 0),
|
type=lambda x: int(x, 0),
|
||||||
const=0,
|
const=0,
|
||||||
help="Width in columns. <=0 uses the terminal width. Defaults "
|
help="Width in columns. <=0 uses the terminal width. In subplots "
|
||||||
|
"this instead expresses a ratio of the current grid. Defaults "
|
||||||
"to min(terminal, 80).")
|
"to min(terminal, 80).")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-H', '--height',
|
'-H', '--height',
|
||||||
nargs='?',
|
nargs='?',
|
||||||
type=lambda x: int(x, 0),
|
type=lambda x: int(x, 0),
|
||||||
const=..., # handles shell prompt spacing, which is a bit subtle
|
const=..., # handles shell prompt spacing, which is a bit subtle
|
||||||
help="Height in rows. <=0 uses the terminal height. Defaults "
|
help="Height in rows. <=0 uses the terminal height. In subplots "
|
||||||
|
"this instead expresses a ratio of the current grid. Defaults "
|
||||||
"to 17.")
|
"to 17.")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-X', '--xlim',
|
'-X', '--xlim',
|
||||||
|
|||||||
+33
-2
@@ -850,6 +850,10 @@ def main(csv_paths, output, *,
|
|||||||
points_and_lines=False,
|
points_and_lines=False,
|
||||||
width=WIDTH,
|
width=WIDTH,
|
||||||
height=HEIGHT,
|
height=HEIGHT,
|
||||||
|
wpad=None,
|
||||||
|
hpad=None,
|
||||||
|
wspace=None,
|
||||||
|
hspace=None,
|
||||||
xlim=(None,None),
|
xlim=(None,None),
|
||||||
ylim=(None,None),
|
ylim=(None,None),
|
||||||
xlim_stddev=(None,None),
|
xlim_stddev=(None,None),
|
||||||
@@ -1064,6 +1068,11 @@ def main(csv_paths, output, *,
|
|||||||
layout='constrained',
|
layout='constrained',
|
||||||
# we need a linewidth to keep xkcd mode happy
|
# we need a linewidth to keep xkcd mode happy
|
||||||
linewidth=8 if xkcd else 0)
|
linewidth=8 if xkcd else 0)
|
||||||
|
fig.get_layout_engine().set(
|
||||||
|
w_pad=wpad/72 if wpad is not None else None,
|
||||||
|
h_pad=hpad/72 if hpad is not None else None,
|
||||||
|
wspace=wspace if wspace is not None else 0,
|
||||||
|
hspace=hspace if hspace is not None else 0)
|
||||||
|
|
||||||
gs = fig.add_gridspec(
|
gs = fig.add_gridspec(
|
||||||
grid.height
|
grid.height
|
||||||
@@ -1560,11 +1569,33 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-W', '--width',
|
'-W', '--width',
|
||||||
type=lambda x: int(x, 0),
|
type=lambda x: int(x, 0),
|
||||||
help="Width in pixels. Defaults to %r." % WIDTH)
|
help="Width in pixels. In subplots this instead expresses a "
|
||||||
|
"ratio of the current grid. Defaults to %r." % WIDTH)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-H', '--height',
|
'-H', '--height',
|
||||||
type=lambda x: int(x, 0),
|
type=lambda x: int(x, 0),
|
||||||
help="Height in pixels. Defaults to %r." % HEIGHT)
|
help="Height in pixels. In subplots this instead expresses a "
|
||||||
|
"ratio of the current grid. Defaults to %r." % HEIGHT)
|
||||||
|
parser.add_argument(
|
||||||
|
'--wpad',
|
||||||
|
type=float,
|
||||||
|
help="Width padding in pt. Defaults to %r." % (
|
||||||
|
72*plt.rcParams["figure.constrained_layout.w_pad"])),
|
||||||
|
parser.add_argument(
|
||||||
|
'--hpad',
|
||||||
|
type=float,
|
||||||
|
help="Height padding in pt. Defaults to %r." % (
|
||||||
|
72*plt.rcParams["figure.constrained_layout.h_pad"])),
|
||||||
|
parser.add_argument(
|
||||||
|
'--wspace',
|
||||||
|
type=float,
|
||||||
|
help="Width spacing between plots as a ratio of the grid. "
|
||||||
|
"Defaults to %r." % 0)
|
||||||
|
parser.add_argument(
|
||||||
|
'--hspace',
|
||||||
|
type=float,
|
||||||
|
help="Height spacing between plots as a ratio of the grid. "
|
||||||
|
"Defaults to %r." % 0)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-X', '--xlim',
|
'-X', '--xlim',
|
||||||
type=lambda x: tuple(
|
type=lambda x: tuple(
|
||||||
|
|||||||
Reference in New Issue
Block a user