python 饼图 直方图 曲线图 代码模板
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['axes.unicode_minus'] = False
import random
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
def bing_tu(label_list,size,title_name,figsize_x): # 饼图
# label_list = ["第一部分", "第二部分", "第三部分"] # 各部分标签
# size = [55, 35, 10] # 各部分大小
def make_autopct(values):
def my_autopct(pct):
total = sum(values)
val = int(round(pct * total / 100.0))
# 同时显示数值和占比的饼图
return '{p:.2f}% ({v:d})'.format(p=pct, v=val)
return my_autopct
color=[]
colors = ["red", "green", "blue", "yellow"] # 各部分颜色
while len(color)<len(label_list):
color.append(colors[random.randint(0,3)])
# explode
|