Python饼图使用matplotlib,重新排列标签

时间:2016-11-15 12:48:21

标签: python matplotlib charts

假设我有以下饼图:

Sub FindFirstEmptyCell()

    Dim l As Integer
    Dim Firstcell As Integer
    Dim MyArray(4) As String
    Dim currentRowValue As String

    MyArray(0) = "g"
    MyArray(1) = "g"
    MyArray(2) = "s"
    MyArray(3) = ""
    MyArray(4) = "f"

    ' loop through all elements in MyArray
    For l = LBound(MyArray) To UBound(MyArray)
        If IsEmpty(MyArray(l)) Or MyArray(l) = "" Then
            Firstcell = l
            MsgBox "First empty element in MyArray is " & Firstcell
            Exit For
        End If
    Next

End Sub

我们立即看到标签的重叠。是否可以从分数到标签创建一条线,并且在它们之间获得更多距离?

像这样,例如: selfmade labels

1 个答案:

答案 0 :(得分:0)

我无法想出一种有效实现这一目标的方法。你最安全的选择是单独放置标签(想象在一个饼图中有更多的碎片)。试试这个替代方案:

import matplotlib.pyplot as plt
sizes = [0.988799675982225, 0.009625725741571165, 0.0015745982762038959]
labels = ["Aaaaaa", "Bbbbbbbbbb", "CcCcccCc"]
patches, texts = plt.pie(sizes)
plt.legend(patches, labels, loc="best")
plt.axis('equal')
plt.tight_layout()
plt.show()