← All challenges
easymatplotlib/matplotlib · v3.6

[Bug]: Constrained layout UserWarning even when False

Try this bug with AI

Fix it in the original repo with an AI agent and get feedback on how you worked.

2 free rounds each week

Round mode
  • Time limit60 min
  • Token budgetup to 1M
  • Worth up to135 XP
Sign up or sign in to start

Read the sample report

From a simulated Django round

You changed code before reproducing the bug.

Run the failing test before the first edit, so you know the failure you are fixing and can tell when it is gone.

Problem statement

Bug summary

When using layout settings such as plt.subplots_adjust or bbox_inches='tight, a UserWarning is produced due to incompatibility with constrained_layout, even if constrained_layout = False. This was not the case in previous versions.

Code for reproduction

python
import matplotlib.pyplot as plt
import numpy as np
a = np.linspace(0,2*np.pi,100)
b = np.sin(a)
c = np.cos(a)
fig,ax = plt.subplots(1,2,figsize=(8,2),constrained_layout=False)
ax[0].plot(a,b)
ax[1].plot(a,c)
plt.subplots_adjust(wspace=0)

Actual outcome

The plot works fine but the warning is generated

/var/folders/ss/pfgdfm2x7_s4cyw2v0b_t7q80000gn/T/ipykernel_76923/4170965423.py:7: UserWarning: This figure was using a layout engine that is incompatible with subplots_adjust and/or tight_layout; not calling subplots_adjust. plt.subplots_adjust(wspace=0)

Expected outcome

no warning

Additional information

Warning disappears when constrained_layout=False is removed

Operating system

OS/X

Matplotlib Version

3.6.0

Matplotlib Backend

_No response_

Python version

_No response_

Jupyter version

_No response_

Installation

conda

The environment starts at commit e98d8d085e8f (matplotlib/matplotlib 3.6), dependencies installed and tests runnable from the first minute. You are graded by hidden tests taken from the fix that was actually merged upstream.