question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Matshow/imshow changes layout in matplotlib >= 3.3

See original GitHub issue

Description

I set up a subplots layout the way I need it for my figure and the subplots look good. But as soon as I start filling the axes with image-data using matshow or imshow, the layout is completely changed. It appears, the axes change their aspect ratio to one, resulting in large margins in the final plot.

Steps to reproduce

import proplot as plot
import numpy as np

f, axes = plot.subplots(nrows=2, ncols=5, aspect=4/3, wspace='3mm', hspace='3mm')
axes[0].matshow(np.random.randn(3,4))

Expected behavior: I expect to see a nicely aligned grid of axes with the given aspect ratio, the first axes should be completely filled with the random data, roughly like this (except for the missing data): Screenshot_20201115_001856

Actual behavior: The matshow command changes the layout: Screenshot_20201115_002011

Equivalent steps in matplotlib

Not sure whether this applies here, but with the matplotlib subplots, the layout is not changed after the first matshow.

import matplotlib.pyplot as plt
import numpy as np

f, axes = plt.subplots(2, 5, figsize=(4*5, 3*2))
axes[0, 0].matshow(np.random.randn(3,4))
f.subplots_adjust(hspace=0.1, wspace=0.1, left=0.02, right=0.98, top=0.98, bottom=0.02)

Screenshot_20201115_002427

Proplot version

0.6.4

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
matthias-kcommented, Jul 4, 2021

@lukelbd Thanks for fixing this! For the sake of completeness, git bisect is a git feature for efficiently finding the commit that introduced a certain bug. It can save a lot of time 😃. See https://git-scm.com/docs/git-bisect for a nice introduction

0reactions
lukelbdcommented, Jul 4, 2021

Eating my words – it was e7f76fa (I have no idea what git bisect is but evidently I should learn). In matplotlib 3.3+ they translate aspect='equal' to aspect=1 (these are synonyms since here “1” is in data units) but I confused matplotlib’s convention of data-units “aspect” with proplot’s convention of physical-units “aspect”. So this otherwise innocuous change caused the whole algorithm to fail.

Now fixed by: 124ea3f

Read more comments on GitHub >

github_iconTop Results From Across the Web

Figure size/aspect for projections is not working anymore with ...
I think it is coming from the last version of Matplotlib 3.3. Here is the problem with a random ... Matshow/imshow changes layout...
Read more >
Tight Layout guide — Matplotlib 3.6.2 documentation
In matplotlib, the location of axes (including subplots) are specified in normalized figure coordinates. It can happen that your axis labels or titles...
Read more >
Constrained Layout Guide — Matplotlib 3.6.2 documentation
How to use constrained-layout to fit plots within your figure cleanly. ... Note in the below how the space at the edges doesn't...
Read more >
Customizing Figure Layouts Using GridSpec and ... - Matplotlib
Specifies the geometry of the grid that a subplot will be placed. The number of rows and number of columns of the grid...
Read more >
API Changes — Matplotlib 3.3.1 documentation
The behavior of both has been changed to ignore the width of the title and xlabel and the height of the ylabel in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found