On Tue, Jun 21, 2011 at 1:50 PM, Frank <frank.t.winter@...> 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.
Hope that helps,