0

I am trying to adjust the position of the axes in my matplotlib figure. Here are the two cells I'm running consequently in the jupyter notebook:

%matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(4, 4))
ax = fig.add_axes([0.65, 0.1, 0.3, 0.8])
ax.patch.set_facecolor('red')
fig.patch.set_facecolor('blue')

The result however doesn't look as I expect it to:

I.e. both the figure aspect ratio and the position of the axes on it have been changed.

If, however, I change the backend from inline to notebook in the very first line (the %matplotlib magic) and run the same code (in a clean kernel), I do get the result as expected:

I am guessing there is some automatic adjustment function enabled in the inline backend, but I failed to find it. For example, I checked that matplotlib.rcParams['figure.autolayout'] parameter is set to False.

Is there any way to disable this feature for the inline backend?

I'm using matplotlib version 3.1.3. Also here's the jupyter --version output:

$ jupyter --version
jupyter core     : 4.6.1
jupyter-notebook : 6.0.3
qtconsole        : 4.6.0
ipython          : 7.12.0
ipykernel        : 5.1.4
jupyter client   : 5.3.4
jupyter lab      : 1.2.6
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 5.0.4
traitlets        : 4.3.3
SiLiKhon
  • 583
  • 4
  • 15

0 Answers0