Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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')
like image 825
Skiv_mag Avatar asked Oct 23 '22 21:10

Skiv_mag


1 Answers

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.

like image 105
weronika Avatar answered Nov 04 '22 02:11

weronika