详解Python+Matplotlib绘制面积图&热力图
作者:侯小啾 时间:2021-10-10 10:16:29
1.绘制面积图
面积图常用于描述某指标随时间的变化程度。其面积也通常可以有一定的含义。
绘制面积图使用的是plt.stackplot()方法。
以小学时期学的 常见的追击相遇问题中的速度时间图像为例,下边绘制出一幅简单的v-t图像。
全局字体设为默认的黑体,时间为从第0秒到第10秒,描述的是甲乙两个物体的速度。显然,面积则表示位移。
标题部分字体使用楷体(将系统中的TTF字体文件"STKAITI.TTF"复制到了当前目录下)。
import matplotlib.pyplot as plt
from matplotlib import font_manager
fig = plt.figure(1, facecolor='#ffffcc', figsize=(6, 6))
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.rcParams['axes.facecolor'] = '#cc00ff'
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
v1 = [1, 1, 1, 2, 3, 4, 5, 5, 5, 5, 5]
v2 = [0.5, 0.5, 0.5, 1, 1.5, 2, 2.5, 3, 3, 2, 1]
plt.stackplot(x, v1, color=['#ff0000'])
plt.stackplot(x, v2, color=['#33ff66'])
plt.xlim(0, 10)
plt.title('v-t图像', fontsize=25, color='#0033cc', fontproperties=font_manager.FontProperties(fname="STKAITI.TTF"))
plt.xlabel('t/s')
plt.ylabel('v/(m/s)')
plt.legend(['甲', '乙'], bbox_to_anchor=(0.2, 0.95))
plt.show()
图像效果呈现如下:
2.绘制热力图
在数据分析中,热力图也是一种常用的方法,热力图通过色差、亮度来展示数据与数据之间的差异。
绘制热力图使用的是plt.imshow()方法,这个方法也即matplotlib中图像处理常用的方法。
下边做一个热力图的案例示例:
import matplotlib.pyplot as plt
from matplotlib import font_manager
import numpy as np
np.random.seed(30)
data = np.random.randint(70, 100, (30, 8))
plt.imshow(data)
plt.xticks(range(0, 8), ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])
plt.yticks(range(0, 30), np.array(range(1, 31), dtype='U3'))
# 显示颜色条
plt.colorbar()
plt.title('30个产品的ABCDEFGH指标热力图', fontsize=25, color='#0033cc', fontproperties=font_manager.FontProperties(fname="STKAITI.TTF"))
plt.show()
图像效果呈现如下:
来源:https://blog.csdn.net/weixin_48964486/article/details/124112740
标签:Python,Matplotlib,面积图,热力图
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python文件编译为pyc后运行的实现步骤
2021-03-08 22:36:46
![](https://img.aspxhome.com/file/2023/6/70866_0s.png)
使用MySQL数据库的23个注意事项
2010-03-18 15:46:00
escape解决AJAX中文乱码的简单方法
2008-10-23 14:32:00
Python同步遍历多个列表的示例
2023-08-08 00:20:10
![](https://img.aspxhome.com/file/2023/4/95744_0s.jpg)
python实现根据窗口标题调用窗口的方法
2022-06-12 04:24:40
探讨关于404错误页面设置的问题
2011-12-01 10:59:38
数据库基础:MySQL 添加用户的两种方法
2009-05-07 14:26:00
深入MySQL数据库的索引
2009-02-26 15:27:00
详解如何利用Python制作24点小游戏
2022-02-04 17:22:42
![](https://img.aspxhome.com/file/2023/2/66882_0s.jpg)
Python实现非正太分布的异常值检测方式
2021-11-22 12:27:57
![](https://img.aspxhome.com/file/2023/4/76054_0s.jpg)
解读python如何实现决策树算法
2021-08-26 19:52:01
Server 对象 错误 ASP 0177 800401f3 的解决方案 Server 对象 错误 ASP 0177 800401f3
2009-07-28 17:57:00
python中Apriori算法实现讲解
2023-10-27 17:41:20
![](https://img.aspxhome.com/file/2023/2/87712_0s.png)
Linux上MySql远程备份方案
2010-11-25 17:23:00
Python高级特性——详解多维数组切片(Slice)
2023-01-20 17:04:13
python判断正负数方式
2023-07-06 11:16:12
ASP 使用Filter函数来检索数组
2011-04-30 16:49:00
python爬虫中的url下载器用法详解
2022-06-28 01:09:21
新云4.0 模板通用标签说明
2008-11-20 13:12:00
一个简单的北京2008奥运倒计时代码
2008-03-16 14:15:00