Pyplot:曲线下的垂直渐变填充? [英] Pyplot: vertical gradient fill under curve?
本文介绍了Pyplot:曲线下的垂直渐变填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有一种方法可以用垂直渐变填充pyplot曲线下的内容,例如此快速模型:
I'm wondering if there's a way to fill under a pyplot curve with a vertical gradient, like in this quick mockup:
我在StackOverflow上发现了这个黑手,如果我能弄清楚如何使颜色贴图垂直,我就不在乎多边形:
I found this hack on StackOverflow, and I don't mind the polygons if I could figure out how to make the color map vertical: How to fill rainbow color under a curve in Python matplotlib
推荐答案
也许有更好的方法,但这是可行的:
There may be a better way, but here goes:
from matplotlib import pyplot as plt
x = range(10)
y = range(10)
z = [[z] * 10 for z in range(10)]
num_bars = 100 # more bars = smoother gradient
plt.contourf(x, y, z, num_bars)
background_color = 'w'
plt.fill_between(x, y, y2=max(y), color=background_color)
plt.show()
显示:
这篇关于Pyplot:曲线下的垂直渐变填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文