Tutorial :matplotlib - changing rect colours on the fly



Question:

I am playing with matplotlib - I have a bar chart, and I want to highlight the bar which user clicks. I have a callback that goes through a rect collection (the one I got from self.axis.bar(...)) and finds out which one was clicked (looking at the coordinates). At this point I want to call something to change the colour of the current bar. Is it possible? How do I do that?

Edited: I guess the answer I am really looking for is if it's possible to make bars to have different colours.


Solution:1

You can set the color of individual bars using the Artist properties. Here's an example:

import matplotlib.pyplot as plt    fig = plt.figure()  ax1 = fig.add_subplot(111)  bars = ax1.bar(range(1,10), range(1,10), color='blue', edgecolor='black')    bars[6].set_facecolor('red')  plt.show()  

alt text http://i41.tinypic.com/35d7tw0.png


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »