如何在matplotlib和python 2.7中制作瀑布图?

Dav*_*off 2 python-2.7

如何制作如此处所见的情节

http://38.media.tumblr.com/tumblr_m7bk6wu3VW1qfjvexo1_500.gif

我不需要的动态.我确实需要遮挡背景曲线的前景曲线.

这些用于脉冲星天文学.

我试过了

plt.fill()和

plt.fill_between()

没有成功.有人知道python的某个地方有什么例子吗?

xnx*_*xnx 7

你可以通过小心线条的z顺序和fill_under来创建类似于所需效果的东西:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure(facecolor='k')
ax = fig.add_subplot(111, axisbg='k')

def fG(x, x0, sigma, A):
    """ A simple (un-normalized) Gaussian shape with amplitude A. """
    return A * np.exp(-((x-x0)/sigma)**2)

# Draw ny lines with ng Gaussians each, on an x-axis with nx points
nx, ny, ng = 1000, 20, 4
x = np.linspace(0,1,1000)

y = np.zeros((ny, nx))
for iy in range(ny):
    for ig in range(ng):
        # Select the amplitude and position of the Gaussians randomly
        x0 = np.random.random()
        A = np.random.random()*10
        sigma = 0.05
        y[iy,:] += fG(x, x0, sigma, A)
    # Offset each line by this amount: we want the first lines plotted
    # at the top of the chart and to work our way down
    offset = (ny-iy)*5
    # Plot the line and fill under it: increase the z-order each time
    # so that lower lines and their fills are plotted over higher ones
    ax.plot(x,y[iy]+offset, 'w', lw=2, zorder=(iy+1)*2)
    ax.fill_between(x, y[iy]+offset, offset, facecolor='k', lw=0, zorder=(iy+1)*2-1)
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • @DavidSaroff然后为什么不接受答案? (2认同)