I'm making a application to show graph using python pyqt5 and matplotlib. here is a issue with graph I don't know why this happen.
You can see the 2 graph image I uploaded. Second one is what I want to show. But after show pie graph(There are so many types of graph I used in my application but only after pie graph happen this issue), it work like first image.
So, I wrote code after draw pie graph
self.MplWidget.canvas.axes.clear()
like this.
But it doesn't change at all.
If I reboot my application it work well.
How I can show my graph like image2 after show pie graph?
this is my code to show bar graph
self.MplWidget.canvas.axes.bar(ind, graph1, width, label='price1' )
self.MplWidget.canvas.axes.bar(ind, graph2, width, bottom=graph1, yerr=Std, label='price2')
self.MplWidget.canvas.axes.title.set_text('graph1')
self.MplWidget.canvas.axes.set_xticks(ind)
self.MplWidget.canvas.axes.set_xticklabels(temp['date'], rotation=90 )
self.MplWidget.canvas.axes.legend(loc='best')
self.MplWidget.canvas.draw()
this is my code to show pie chart
self.MplWidget.canvas.axes.title.set_text('pie graph')
self.MplWidget.canvas.axes.pie(sizes, labels=labels, autopct='%1.1f%%',shadow=True, startangle=90)
self.MplWidget.canvas.axes.axis('equal')
self.MplWidget.canvas.draw()
self.MplWidget.canvas.axes.clear()
Axes.pie
sets the aspect ratio of the axes to 'equal' which is what seems to mess up the bar plot. You could try settingself.MplWidget.canvas.axes.set_aspect('auto')
when plotting the bar plot to reset the aspect ratio to 'auto'. You probably also want to setself.MplWidget.canvas.axes.set_frame_on(True)
sinceAxes.pie
removes the frame around the plot as well.Another option could be to use separate widgets for each of the plots and combine them in a
QStackedWidget
orQTabWidget
.