Skip to content

Pie chart labels out of Figure, even with tight_layout #4251

Closed as not planned
@lafrech

Description

@lafrech

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 per this 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 -*-

import sys

from PyQt4 import QtGui

from matplotlib.figure import Figure

from matplotlib.backends.backend_qt4agg import (
    FigureCanvasQTAgg as FigureCanvas)

class MplCanvas(FigureCanvas):
    """Class to represent the FigureCanvas widget"""
    def __init__(self):

        # Setup Matplotlib Figure and Axis
        self.fig = Figure(facecolor="white")
        self.axes = self.fig.add_subplot(111)

        # Initialization of the canvas
        super(MplCanvas, self).__init__(self.fig)

        # Define the widget as expandable
        FigureCanvas.setSizePolicy(self,
                                   QtGui.QSizePolicy.Expanding,
                                   QtGui.QSizePolicy.Expanding)

        # Notify the system of updated policy
        FigureCanvas.updateGeometry(self)

        # Call tight_layout on resize
        #self.mpl_connect('resize_event', self.fig.tight_layout)

class MplWidget(QtGui.QWidget):
    """Widget defined in Qt Designer"""
    def __init__(self, parent = None):

        super(MplWidget, self).__init__(parent)

        # Set canvas and navigation toolbar
        self.canvas = MplCanvas()

        # Layout as vertical box
        self.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    New featurekeepItems to be ignored by the “Stale” Github Actiontopic: geometry managerLayoutEngine, Constrained layout, Tight layouttopic: text

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions