Python绘制饼状图

Python绘制饼状图

import matplotlib.pyplot as plt
import numpy as np


if __name__ == "__main__":
    labels = 'A', 'B'
    sizes = [9, 18]
    explode = (0.1, 0)  # only "explode" the 2nd slice (i.e. 'Hogs')

    fig1, ax1 = plt.subplots()
    ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
            shadow=True, startangle=90)
    ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.

    plt.show()

效果如下:

image-20221204230407249

posted @ 2022-12-05 00:00  bH1pJ  阅读(111)  评论(0编辑  收藏  举报