如何使用Python绘制时间序列热图? [英] How to plot Time Series Heatmap with Python?

查看:82
本文介绍了如何使用Python绘制时间序列热图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个图表,其中x轴为时间轴,y轴为其值,颜色将指示其频率.频率越高,颜色越深.

推荐答案

我认为您正在寻找二维直方图:

I think you are looking for a 2d histogram:

import matplotlib.pyplot as plt

plt.hist2d(x, y)

默认图不如您的示例那么漂亮,但是您可以使用它并更改颜色图,垃圾箱,...

The default plot is not as pretty as your example, but you can play with it and change the colormap, bins, ...

这将产生一个更接近您的示例的图:

This produces a plot much closer to your example:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap

# example data
x = np.linspace(0, 10, 10000)
y = 0.5*x+np.random.randn(10000)

# make a custom colormap with transparency
ncolors = 256
color_array = plt.get_cmap('YlOrRd')(range(ncolors))
color_array[:, -1] = np.linspace(0, 1, ncolors)
cmap = LinearSegmentedColormap.from_list(name='YlOrRd_alpha', colors=color_array)

plt.hist2d(x, y, bins=[15, 30], cmap=cmap, edgecolor='white')
plt.show()

结果是:

我希望这会有所帮助.

这篇关于如何使用Python绘制时间序列热图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆