gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:51:11 30 4
gpt4 key购买 nike

我如何制作一个像这里看到的情节

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

我不需要的动态。我确实需要模糊背景曲线的前景曲线。

这些用于 pulsar 天文学。

我已经尝试过

plt.fill() 和

plt.fill_between()

没有成功。有人知道python中的某个地方有一个例子吗?

最佳答案

您可以通过小心行的 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()

enter image description here

关于python-2.7 - 如何在 matplotlib 和 python 2.7 中制作瀑布图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29883344/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com