New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
legends do not refresh #6166
Comments
Are you using blitting? |
i have a blit=True in the FuncAnimation call, so probably: yes. just checked: not setting it or setting to False does not work at all, the windows stays gray. |
Can you make a minimal example? Starting from one of the example might be a good starting point if your actual use case is very involved. There is enough subtlety in the animation code that my trying to guess what you are doing would not go well 😉 |
ok, i cut it down to this: |
i just found that the init_func() is called after each resize... it seems that the call to the legend() function at the moment where the bars are already there refreshes the legend. calling it when a bar is created doesn't help either, in that case several legends are created which seem to cover each other. |
i now added a legend.remove() and a plt.legend() in case a new bar was created. and now it gets scary: i get a "AttributeError: 'NoneType' object has no attribute 'remove'" exception. i found out that the animate function is called /before/ the init_func! this seems to be a bug as well... but it's the cause the first legend entry show up properly because a call to animate will create a bar in my code. |
ok, i found it. it seems the legend must be returned in the list of artists from the animation function to be updated. |
I am glad you found a work around 😄 One comment from looking at your code is that you should use the OO interface in this sort of situation. Where you have self.figure = plt.figure() do self.figure, self.ax = plt.subplots() and then the rest of the calls to I also suggest creating all of the artists you will need in |
yes, i was wondering why matplotlib was so non-py and non-oo. i found the first method in most of the samples while i found the second on some stackoverflow-snippets. i was wondering that the second works (saw it only in a multi-plot) and what the benefit is because it's so seldom in the samples. and: it's not working. i replaced most plt. for self.ax. and get errors, AxesSubplot does not have xticks, xlabel, ... :( |
Here is my explanation about pyplot vs. axes methods: tl;dr; Matplotlib has its roots in interactive plotting via a REPL a la MatLab. On Fri, Mar 18, 2016 at 4:23 AM, M. Dietrich notifications@github.com
|
some of those do get renamed to |
i created an animation that shows a live result-code distribution parsed from logfiles. my frames function reads a logfile (
tail -f
like), parses each line for the resultcode and returns just the resultcode. the animate function increments a counter for that code from which stacked bars are drawn.the result-codes are unknown at startup so the animate function "invents" new bars on the fly with new labels. the legend is created in the init_func (and complains that there are no labels in my plots - it does not know they show up later).
the legend shows only one label - the first one that was added. this does not change when the program runs for a while until i resize the window. in that moment the correct number of labels will be shown. is this a bug or do i have to issue some 'refresh()' method to wake up the legend?
The text was updated successfully, but these errors were encountered: