我有一个水平条形图,需要将其另存为HTML文件。我在python中使用mpld3模块执行相同的操作,并且由于“ BarContainer”对象没有属性“ canvas”而收到错误。
import matplotlib.pyplot as plt
plt.rcdefaults()
import numpy as np
# Example data
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))
plt.barh(y_pos, performance, xerr=error, align='center', alpha=0.4)
plt.yticks(y_pos, people)
plt.xlabel('Performance')
plt.title('How fast do you want to go today?')
mpld3.save_html(fig,"fig1.html")
plt.show()
收到的错误是'BarContainer'对象没有属性'canvas'