3.1.8 热力图
import numpy as np import matplotlib import matplotlib.pyplot as plt # 标签 vegetables = ["cucumber", "tomato", "lettuce", "asparagus", "potato", "wheat", "barley"] farmers = list('ABCDEFG') # 创建数据,随机数 harvest = np.random.randn(7, 7) * 5 # 农民丰收数据 plt.rcParams['font.size'] = 18 plt.rcParams['font.weight'] = 'heavy' plt.figure(figsize = (9, 9)) # imshow() 显示图片,因为数值不同,所以图片颜色不同 im = plt.imshow(harvest) plt.xticks(np.arange(len(farmers)), farmers, rotation = 45, ha = 'right') plt.yticks(np.arange(len(vegetables)), vegetables) # 绘制文本 for i in range(len(vegetables)): for j in range(len(farmers)): text = plt.text(j, i, round(harvest[i, j], 1), ha = "center", va = "center", color = 'r') plt.title("Harvest of local farmers (in tons/year)", pad = 20)
3.1.9 面积图
import matplotlib.pyplot as plt plt.figure(figsize = (9, 6)) days = [1, 2, 3, 4, 5] sleeping = [7, 8, 6, 11, 7] eating = [2, 3, 4, 3, 2] working = [7, 8, 7, 2, 2] playing = [8, 5, 7, 8, 13] plt.stackplot(days, sleeping, eating, working, playing) plt.xlabel('x') plt.ylabel('y') plt.title('Stack Plot', fontsize = 18) plt.legend(['Sleeping', 'Eating', 'Working', 'Playing'], fontsize = 18)
3.1.10 蜘蛛图
import numpy as np import matplotlib.pyplot as plt # 画图数据 plt.rcParams['font.family'] = 'KaiTi' labels = np.array(["个人能力", "IQ", "服务意识", "团队精神", "解决问题能力", "持续学习"]) y = [83, 61, 95, 67, 76, 88] x = np.linspace(0, 2 * np.pi, len(labels), endpoint = False) # 首位相接,我们要把 "持续学习" 和 "个人能力相连起来" y = np.concatenate((y, [y[0]])) # 首尾相接 x = np.concatenate((x, [x[0]])) # 首尾相接 # 用Matplotlib画蜘蛛图 fig = plt.figure(figsize = (6, 6)) ax = fig.add_subplot(111, polar = True) # 连线 # o:表示形状,圆形 # -:表示实线 # o-:属性连用 ax.plot(x, y, 'o-', linewidth = 2) ax.fill(x, y, alpha = 0.25) # 填充颜色 # 设置角度 ax.set_thetagrids(x[:-1] * 180 / np.pi,# 角度值 # 由于首位相接时候相当于给x增加了一个元素,现在需要切片去掉这个元素 labels, fontsize = 18) _ = ax.set_rgrids([20, 40, 60, 80], fontsize = 18)