On Tue, Jun 21, 2011 at 1:50 PM, Frank <frank.t.win...@googlemail.com> 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 ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users