Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Apr 19, 2021

PR Summary

We often have the situation where we have a grid of fixed-aspect axes, and they end up with too much space in one direction or the other:

CompressFalse

For simple cases, it is not hard to fix this, as is done with this PR:

CompressTrue

API:

As with previous efforts at doing this the API is a bit klunky, but I think it needs to be optional so we need something.

import matplotlib.pyplot as plt
import numpy as np

nrows = 2
ncols = 3
for compress in [False, True]:
    fig, axs = plt.subplots( nrows, ncols, figsize=(4,4),
                            constrained_layout={'compress':compress}, 
                            sharex=True, sharey=True)
    fig.patch.set_facecolor("0.9")
    #fig.set_constrained_layout_pads(compress=True)

    for i in range(nrows):
        for j in range(ncols):
            ax = axs[i, j]
            ax.set_aspect(1)
            pc = ax.pcolormesh(np.random.randn(30, 30))
    fig.colorbar(pc, ax=axs)
    fig.savefig(f'/Users/jklymak/downloads/Compress{compress}.png', dpi=100)

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@jklymak jklymak marked this pull request as draft April 19, 2021 00:38
@jklymak jklymak added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Apr 19, 2021
@jklymak jklymak force-pushed the enh-compress-axes branch from f6eb58a to 6fa3fa9 Compare April 19, 2021 00:45
@anntzer
Copy link
Contributor

anntzer commented Apr 19, 2021

Possibly the API discussion should be done as part of #19892? e.g. layout="constrained-compressed" (or even just "compressed")

@jklymak
Copy link
Member Author

jklymak commented Jan 22, 2022

Closing for #22289

@jklymak jklymak closed this Jan 22, 2022
@jklymak jklymak deleted the enh-compress-axes branch January 22, 2022 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for other PR topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants