Matplotlib - color change on the fly

I play with matplotlib - I have a histogram and I want to highlight the panel that the user clicks. I have a callback that goes through a direct collection (the one I received from self.axis.bar (...)) and finds out which one was pressed (looking at the coordinates). At this point I want to call something to change the color of the current bar. Is it possible? How to do it?

Edited: I think the answer I'm really looking for is the ability to make bars in different colors.

+4
source share
1 answer

You can set the color of individual stripes using the Artist properties . Here is 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

+6
source

Source: https://habr.com/ru/post/1306059/


All Articles