Change in axes(position = […]) behaviour in matplotlib

  matplotlib, python

Just recently, the behavior of matplotlib changed for me and I’m not sure why. I don’t remember making any changes to my install, and many of my plotting routines have stopped working the way they used to. I’m stumped. Has anyone else come across this or have a proposed solution?

import matplotlib.pyplot as plt

fig = plt.figure()

pos1 = [0.1, 0.1, 0.3, 0.8]
pos2 = [0.5, 0.1, 0.4, 0.6]

ax1 = plt.axes(position = pos1)
ax1.plot([0,1], [0, 1], color = 'r', linewidth = 3)

ax2 = plt.axes(position = pos2)
ax2.plot([1, 0], [0, 1], color = 'b', linestyle = '--')

The output looks like this (apologies for those who use dark mode, saving the figure with transparent=True helps to show what is happening):

test1

If I add these lines, then the behavior is the way I’d expect and the way it was until a few days ago:

ax1.set_position(pos1)
ax2.set_position(pos2)

test2

When I run the same code in Google Colab, the last two lines are not necessary. I’m using matplotlib v. 3.4.2.

Source: Python Questions

LEAVE A COMMENT