Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed as not planned
Labels
Milestone
Description
Hi.
I'm drawing a pie chart and the labels are cut off of the Figure. I thought this would be solved by tight_layout (as perthis issue for instance) but this does not seem to be the case, at least for a pie chart.
Below is a code snippet to reproduce. In fact, tight_layout makes it even worse since it ignores the labels and crops tighter to the pie.
Is there a way around this ?
Am I doing things wrong ?
# -*- coding: utf-8 -*-importsysfromPyQt4importQtGuifrommatplotlib.figureimportFigurefrommatplotlib.backends.backend_qt4aggimport (FigureCanvasQTAggasFigureCanvas)classMplCanvas(FigureCanvas):"""Class to represent the FigureCanvas widget"""def__init__(self):# Setup Matplotlib Figure and Axisself.fig=Figure(facecolor="white")self.axes=self.fig.add_subplot(111)# Initialization of the canvassuper(MplCanvas,self).__init__(self.fig)# Define the widget as expandableFigureCanvas.setSizePolicy(self,QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)# Notify the system of updated policyFigureCanvas.updateGeometry(self)# Call tight_layout on resize#self.mpl_connect('resize_event', self.fig.tight_layout)classMplWidget(QtGui.QWidget):"""Widget defined in Qt Designer"""def__init__(self,parent=None):super(MplWidget,self).__init__(parent)# Set canvas and navigation toolbarself.canvas=MplCanvas()# Layout as vertical boxself.vbl=QtGui.QVBoxLayout()self.vbl.addWidget(self.canvas)self.setLayout(self.vbl)if__name__=="__main__":app=QtGui.QApplication(sys.argv)W=MplWidget()W.canvas.axes.cla()values= [0.2,0.5,0.3]labels= ['label','looooooog label','very loooooooooooooooooooooooog label' ]W.canvas.axes.pie(values,labels=labels)W.canvas.axes.axis('equal')W.canvas.fig.tight_layout()W.canvas.draw()W.show()sys.exit(app.exec_())
I'm using python 2.7 and Matplotlib 1.4.3~rc1 from Debian experimental.