一: 柱状图的示例:
import numpy as np import matplotlib.pyplot as plt # 折线统计图 # ax = [23,26,28,31,32,33] #随便创建了一个数据 # ay = [3.0,3.5,4.0,3.0,3.5,4.0] # plt.plot(ax,ay,color=‘r‘,linewidth=1,label=u‘1‘)#color指定线条颜色,labeL标签内容 # plt.legend(loc=2)#标签展示位置,数字代表标签具位置 # plt.xlabel(u‘X/℃‘) # plt.ylabel(u‘Y/‘) # plt.title(u‘2019/06/07‘) # # 设置每个坐标轴的取值范围(x轴取值,y轴取值) # plt.axis([0,36,0,8]) # plt.show() # 柱状统计图 # num_list = [1.5, 0.6, 7.8, 6] # plt.bar(range(len(num_list)), num_list,fc=‘r‘) # plt.show() # 堆叠柱状图 # name_list = [‘Monday‘,‘Tuesday‘,‘Friday‘,‘Sunday‘] # num_list = [1.5,0.6,7.8,6] # num_list1 = [1,2,3,1] # plt.bar(range(len(num_list)), num_list, label=‘boy‘,fc=‘y‘) # plt.bar(range(len(num_list)), num_list1, bottom=num_list, label=‘girl‘,tick_label = name_list,fc =‘r‘) # plt.legend() # plt.show() # 并列柱状图 # name_list = [‘Monday‘,‘Tuesday‘,‘Friday‘,‘Sunday‘] # num_list = [1.5, 0.6, 7.8, 6] # num_list1 = [1, 2, 3, 1] # x = list(range(len(num_list))) # total_width, n = 0.8, 2 # width = total_width / n # # plt.bar(x, num_list, width=width, label=‘boy‘, fc =‘y‘) # for i in range(len(x)): # x[i] = x[i] + width # plt.bar(x, num_list1, width=width, label=‘girl‘, tick_label=name_list, fc=‘r‘) # plt.legend() # plt.show() # 条形柱状图 name_list = [‘Monday‘,‘Tuesday‘,‘Friday‘,‘Sunday‘] num_list = [1.5,0.6,7.8,6] plt.barh(range(len(num_list)), num_list,tick_label = name_list) plt.show() ‘‘‘ 设置背景颜色: 1. fc:设置统一颜色(例:fc=‘r‘统一红色) 2. color:设置不用颜色(例:color=‘rgb‘,三种颜色循环使用) 3. 设置标签: name_list = [‘Monday‘,‘Tuesday‘,‘Friday‘,‘Sunday‘] plt.bar(range(len(num_list)), num_list,fc=‘r‘,tick_label=name_list) ‘‘‘
原文地址:https://www.cnblogs.com/moying-wq/p/10988473.html
时间: 2024-10-30 21:45:22