## matplotlib-users

 [Matplotlib-users] is a changing background color possible? From: Frank - 2011-06-21 17:50:50 Attachments: Message as HTML ```matplotlib python: How do you change the background color of a line plot according to a given column? Say I have the following data file 1. 0 4. 0 2. 0 1. 1 2. 1 3. 1 3. 2 1. 2 2. 2 The first column represents the y-values, and the 2nd column should control the background color. Say, it plots the (black) line on a white-gray alternating background (zebra-like) as proceeding further in x-direction, where the transition in color occurs anytime the integer in the 2nd column increments. Or other possible solution: Use 2nd column as function argument to determine background color. How would one do this with matlibplot? Frank ```
 Re: [Matplotlib-users] is a changing background color possible? From: Justin McCann - 2011-06-21 18:48:22 ```On Tue, Jun 21, 2011 at 1:50 PM, Frank wrote: > matplotlib python: How do you change the background color of a line plot > according to a given column? Say I have the following data file >... > 2. 1 > 3. 1 > 3. 2 > > The first column represents the y-values, and the 2nd column should control > the background color. Say, it plots the (black) line on a white-gray > alternating background (zebra-like) as proceeding further in x-direction, > where the transition in color occurs anytime the integer in the 2nd column > increments. Or other possible solution: Use 2nd column as function argument > to determine background color. > > How would one do this with matlibplot? You can use axvspan (see below). You'll need to track where the 2nd column changes, and then use axvspan to make a colored fill between (x-1, x). Make sure you pass in a low (< 0) zorder number to the axvspan function so it stays in the background. pyplot function: http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axvspan Axes method: http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.axvspan Hope that helps, Justin ```