5

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

f = plt.figure()
ax = f.add_subplot(111, axisbg='green')
4

1 回答 1

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()  

为不同的渐变选择另一个颜色图。也可以在没有'bicubic'插值的情况下工作,但它更丑陋。

于 2012-05-30T17:59:03.820 回答