求助,在學習matplotlib,遇到了個navigationtoolbar的問題。
1\下面是我的代碼:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
from matplotlib.backend_bases import NavigationToolbar2
from matplotlib.backends.backend_agg import FigureCanvasAgg
data = {'Barton LLC': 109438.50,
'Frami, Hills and Schmidt': 103569.59,
'Fritsch, Russel and Anderson': 112214.71,
'Jerde-Hilpert': 112591.43,
'Keeling LLC': 100934.30,
'Koepp Ltd': 103660.54,
'Kulas Inc': 137351.96,
'Trantow-Barrows': 123381.38,
'White-Trantow': 135841.99,
'Will LLC': 104437.60}
group_data = list(data.values())
group_names = list(data.keys())
group_mean = np.mean(group_data)
class MyToolbar(NavigationToolbar2):
toolitems = [t for t in NavigationToolbar2.toolitems if
t[0] in ("Pan", )]
def __init__(self, figure_canvas, parent= None):
super(MyToolbar,self).__init__(figure_canvas)
def select_tool(self):
print ("You clicked the selection tool")
fig, ax = plt.subplots()
canvas=FigureCanvasAgg(fig)
toolbar=MyToolbar(canvas)
ax.barh(group_names, group_data)
print(toolbar.toolitems)
toolbar.update()
plt.show()
執行的時候提示在NavigationToolbar2的__init__中執行_init_toolbar未執行失敗
有兩個問題:
1、定義toolbar類的時候必須重新寫_init_toolbar嗎?我查看了原始碼,這個函式是空的,只有一個raise錯誤
2、直接用matplotlib自帶的視窗顯示,需要選擇什么后端?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/132409.html
上一篇:在pyqt5中如何提取選擇的radiobutton的資訊
下一篇:python新手求教
