Search code examples
pythonmatplotlibaxis

brokenaxes AttributeError: 'SubplotSpec' object has no attribute 'is_last_row'


I am trying to use the python brokenaxes to break both x and y axis. I run the code suggested here https://www.codespeedy.com/create-a-plot-with-broken-axis-in-python-using-matplotlib/

import matplotlib.pyplot as plt 
from brokenaxes import brokenaxes 
import numpy as np 
fig = plt.figure(figsize=(6,4)) 
baxes = brokenaxes(xlims=((-2,3),(5,8)), ylims=((0,8),(9.5,21)), hspace=.1) 
X = np.array([3,-1,0,4,5,-2,7]) 
Y = x**2
Z = x**3
baxes.plot(X,Y,label="squared") 
baxes.plot(X,Z,label="cubed") 
baxes.legend(loc="best")
plt.plot()
plt.show()

However I get error:

AttributeError: 'SubplotSpec' object has no attribute 'is_last_row'

Solution

  • I ran the same code, and I'm able to see the output. But there's a small typo in your code. You have put lowercase x instead of the variable uppercase X for Y and Z.

    enter image description here

    Also I installed matplotlib 3.7.1 and brokenaxes 0.5.0. Please check these versions as well