英文:
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'
英文:
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'
答案1
得分: 0
我运行了相同的代码,我能够看到输出。但是你的代码中有一个小的拼写错误。你在Y和Z的变量中使用了小写x而不是大写X。
我还安装了matplotlib 3.7.1和brokenaxes 0.5.0。请检查这些版本。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论