import numpy as np import matplotlib.pyplot as mp mp.figure(facecolor='lightgray') mp.title('fill', fontsize=18) x = np.linspace(0, 10, 1000) sinx = np.sin(x) cosx = np.cos(x / 2) / 2 mp.grid(linestyle=':', color='r')#'-' solid line style 实线样式 '--' dashed line style 虚线样式 '-.' dash-dot line style 虚点线样式 ':' dotted line style 冒号样式 mp.plot(x, sinx, label=r'$y=sin(x)$') mp.plot(x, cosx, color='orangered', label=r'$y=\frac{1}{2}cos(\frac{x}{2})$') mp.legend() mp.fill_between(x, sinx, cosx, sinx > cosx, color='dodgerblue', alpha=0.3) mp.fill_between(x, sinx, cosx, sinx < cosx, color='orangered', alpha=0.3) mp.legend() mp.show() xiaoming = np.array([57, 55, 58, 49, 52, 43, 59]) xiaohong = np.array([95, 90, 97, 83, 87, 80, 99]) mp.figure('Bar', facecolor='lightgray') mp.title('Bar Chart', fontsize=18) mp.grid(linestyle=':') x = np.arange(xiaoming.size) mp.bar(x - 0.2, xiaoming, 0.4, color='limegreen', label='xiaoming', align='center') mp.bar(x + 0.2, xiaohong, 0.4, color='orangered', label='xiaohong', align='center') mp.xticks(x, ['yuwen', 'shuxue', 'yingyu', 'wuli', 'huaxue', 'zhengzhi', 'lishi']) mp.show() values = [57, 55, 58, 49, 52, 43, 59] spaces = [0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.05] labels = ['yuwen', 'shuxue', 'yingyu', 'wuli', 'huaxue', 'zhengzhi', 'lishi'] colors = ['dodgerblue', 'orangered', 'limegreen', 'violet', 'gold', 'blue', 'red'] mp.figure('Pie Chart') mp.pie(values, spaces, labels, colors, '%.1f%%', shadow=True) mp.legend() mp.show()
matplotlib 画图函数(二)
最新推荐文章于 2024-07-12 16:16:27 发布