marjey 发表于7个月前

• 发表于 7个月前
• 阅读 12
• 收藏 0
• 评论 0
```"""

"""

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import mlab
from matplotlib import rcParams
import pandas as pd

def draw_zhifangtu():
fig1 = plt.figure(2)
rects1 = plt.bar(left=(0.2), height=(0.5), color=('g'), label=(('no1')), width=0.2, align="center", yerr=0.000001)
rects2 = plt.bar(left=(1), height=(1), color=('r'), label=(('no2')), width=0.2, align="center", yerr=0.000001)
plt.legend()
plt.xticks((0.2, 1), ('frst', 'second'))
plt.title('Pe')

def autolabel(rects):
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width() / 2., 1.03 * height, '%s' % float(height))

autolabel(rects1)
autolabel(rects2)
plt.show()

def draw_bingzhuangtu():
import numpy as np
import matplotlib.pyplot as plt

labels = 'A', 'B', 'C', 'D'
fracs = [15, 30.55, 44.44, 10]
explode = [0, 0.1, 0, 0]  # 0.1 凸出这部分，
plt.axes(aspect=1)  # set this , Figure is round, otherwise it is an ellipse
# autopct ，show percet
plt.pie(x=fracs, labels=labels, explode=explode, autopct='%3.1f %%',
shadow=True, labeldistance=1.1, startangle=90, pctdistance=0.6

)
'''
labeldistance，文本的位置离远点有多远，1.1指1.1倍半径的位置
autopct，圆里面的文本格式，%3.1f%%表示小数有三位，整数有一位的浮点数
startangle，起始角度，0，表示从0开始逆时针转，为第一块。一般选择从90度开始比较好看
pctdistance，百分比的text离圆心的距离
patches, l_texts, p_texts，为了得到饼图的返回值，p_texts饼图内部文本的，l_texts饼图外label的文本
'''

plt.show()

if __name__ == '__main__':
draw_zhifangtu()
draw_bingzhuangtu()```

×