我正在尝试将matplotlib饼图嵌入到tkinter GUI中,图例要么适合画布,但与图形重叠,或者被切除。
我尝试设置画布的大小(canvas.get_tk_widget()。config(width = 900,height = 600)),但图例将继续被剪切并且图形将被拉伸。我该怎么做才能解决此问题?
def __init__(self, master):
self.func_list, self.value_list = Graph.get_data()
self.figure = Graph.draw_graph(self.value_list, self.func_list)
self.canvas = Graph.create_canvas(self.figure, master)
self.canvas.draw()
@staticmethod
def create_canvas(figure, master):
canvas = FigureCanvasTkAgg(figure, master)
canvas.get_tk_widget().pack(side=LEFT)
canvas.get_tk_widget().config(width=900, height=600)
return canvas
@staticmethod
def draw_graph(values, legend):
fig = matplotlib.figure.Figure(figsize=(5, 5))
ax = fig.add_subplot(111)
ax.pie(values)
ax.legend(legend, bbox_to_anchor=(1, 1))
circle = matplotlib.patches.Circle((0, 0), 0.7, color='white')
ax.add_artist(circle)
return fig
'''
我希望图形显示在画布的右侧,图例显示在左侧