Skiv_mag
Skiv_mag

Reputation: 284

Subplot background gradient color

How can I create some gradient color in matplotlib and then set the parameter axisbg of my subplot to this?

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

Upvotes: 6

Views: 10612

Answers (1)

weronika
weronika

Reputation: 2639

This doesn't use the axisbg parameter, but may do what you want.

There's a matplotlib example for gradients: http://matplotlib.sourceforge.net/examples/pylab_examples/gradient_bar.html. I tried it myself, this simplified version gives me a green-white gradient background (for some reason when doing this in the interactive python shell I need to call draw() in order for the image to show up):

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

Pick another colormap for different gradients. Works without 'bicubic' interpolation too, but it's uglier then.

Upvotes: 3

Related Questions