tags:

views:

90

answers:

1

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.

+4  A: 

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

tom10
Worked like a charm, thank you tom10.
Nick