子图背景渐变色

Ski*_*mag 5 python colors matplotlib

如何在 matplotlib 中创建一些渐变颜色,然后将axisbg我的子图的参数设置为此?

f = plt.figure()
ax = f.add_subplot(111, axisbg='green')
Run Code Online (Sandbox Code Playgroud)

wer*_*ika 3

这不使用axisbg参数,但可能会执行您想要的操作。

有一个 matplotlib 渐变示例:http://matplotlib.sourceforge.net/examples/pylab_examples/gradient_bar.html。我自己尝试过,这个简化版本给了我一个绿白渐变背景(由于某种原因,在交互式 python shell 中执行此操作时,我需要调用draw()才能显示图像):

import matplotlib.pyplot as mplt  
fig = mplt.figure()  
ax = fig.add_subplot(111)  
mplt.plot([1,2,3],[1,2,1])  
plotlim = mplt.xlim() + mplt.ylim()  
ax.imshow([[0,0],[1,1]], cmap=mplt.cm.Greens, interpolation='bicubic', extent=plotlim)  
mplt.draw()  
Run Code Online (Sandbox Code Playgroud)

为不同的渐变选择另一个颜色图。无需'bicubic'插值也可以工作,但这样会更丑陋。

  • 每次我尝试用自己的数据复制这一点时,y 轴都会完全崩溃到几乎不存在。我尝试手动更改plotlim值来纠正这个问题。我想知道在这种情况下,我的数据是针对两个浮点数据集的日期时间索引是否会有所不同。还有谁有相同的问题吗?感谢进一步的信息。 (2认同)