1

I am plotting simulator results in matplotlib and would like to be able to have the x-axis changing color depending on a variable.

The variable is an indicator if, for each time step in the simulatorn, convergence is reached or not and how far away from convergence it is.

For the time steps where convergence is reached Id like to have the x-axis green and for non-convergence starting from light red for not so bad to red for bad. Now Im simply plotting a line along the x-axis which changes color as described but it would be nice to have the x-axis do it instead,

Is that possible?

Sulthan Allaudeen
  • 11,330
  • 12
  • 48
  • 63
dallas74
  • 31
  • 5
  • Plotting a line along it as you're currently doing is the easiest (and "right") way. The x-axis spine (the term for the line) is a line with two points, so there's no good way to make its color vary with distance. It's easiest to just hide the x-axis (`ax.spines['bottom'].set_visible(False)`) and then draw your line. – Joe Kington Mar 15 '14 at 20:34
  • Thanks a lot Joe. I cannot get rid of the frame of my plot which if it coincides with the x-axis disturbs somewhat my line I want to plot. If the x-axis isnt at y = 0 and would like to plot my line along it, how can I get the y - value for the x-axis? – dallas74 Mar 21 '14 at 06:18

1 Answers1

0

Have a look at this question. Consider to bulid a color dict and pick the color you preferred from it according to the indicator var.

Community
  • 1
  • 1
LumiG
  • 452
  • 1
  • 6
  • 13