这是一个生成热图的小程序,基于 Python 和 PIL 开发。
pip install pyheatmap
easy_install pyheatmap
git clone git://github.com/oldj/pyheatmap.git cd pyheatmap python setup.py install
# -*- coding: utf-8 -*- import urllib from pyheatmap.heatmap import HeatMap def main(): # 下载测试数据 url = "https://raw.github.com/oldj/pyheatmap/master/examples/test_data.txt" sdata = urllib.urlopen(url).read().split("\n") data = [] for ln in sdata: a = ln.split(",") if len(a) != 2: continue a = [int(i) for i in a] data.append(a) # 开始绘制 hm = HeatMap(data) hm.clickmap(save_as="hit.png") hm.heatmap(save_as="heat.png") if __name__ == "__main__": main()