如何为热像图颜色着色3D直方图matplotlib图

时间:2018-05-06 08:27:14

标签: python python-2.7 matplotlib colors

我希望将直方图的颜色更改为高度,如下例所示: enter image description here

直方图的代码是

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
nbins = 1000
mean_list = [366, 657, 594, 1200]
scale_list = [15,50,19,7]
height_list = [1200, 300, 900, 600]
n = 0

for z in [30, 15, 10, 0]: 
    ys = np.random.normal(loc=mean_list[n], scale=scale_list[n], size=height_list[n]) # loc is mean

    hist, bins = np.histogram(ys, bins=int(nbins/10))
    xs = (bins[:-1] + bins[1:])/2

    ax.bar(xs, hist, zs=z, zdir='y', alpha=0.8)
    n += 1

plt.show()

enter image description here

0 个答案:

没有答案