Repository navigation
Simplification of animated histogram example - #18821
Conversation
Newly a BarContainer from hist() function is used.
timhoffm
left a comment
There was a problem hiding this comment.
Thanks! This is really a significant simplification.
| _, _, bar_container = ax.hist( | ||
| data, | ||
| HIST_BINS, | ||
| lw=1, | ||
| ec="yellow", | ||
| fc="green", | ||
| alpha=0.5 | ||
| ) |
There was a problem hiding this comment.
| _, _, bar_container = ax.hist( | |
| data, | |
| HIST_BINS, | |
| lw=1, | |
| ec="yellow", | |
| fc="green", | |
| alpha=0.5 | |
| ) | |
| _, _, bar_container = ax.hist(data, HIST_BINS, lw=1, | |
| ec="yellow", fc="green", alpha=0.5) |
While we have no formal specification on the wrapping style, we're currently not using one-parameter-per-line anywhere in the code or docs. Therefore, I'd like to keep this compact.
There was a problem hiding this comment.
I know, I have noticed the communication regarding the formatting. I personally prefer the long option, mostly because I am really used to read it. But for documentation/example purpose I find the compact form nice, shifting some attention from code itself to texts and figures.
| ani = animation.FuncAnimation( | ||
| fig, | ||
| prepare_animation(bar_container), | ||
| 50, | ||
| repeat=False, | ||
| blit=True | ||
| ) |
There was a problem hiding this comment.
As above
| ani = animation.FuncAnimation( | |
| fig, | |
| prepare_animation(bar_container), | |
| 50, | |
| repeat=False, | |
| blit=True | |
| ) | |
| ani = animation.FuncAnimation(fig, prepare_animation(bar_container), 50, | |
| repeat=False, blit=True) |
|
Thanks @deep-jkl! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again. |
Newly a BarContainer from hist() function is used.
PR Summary
Related to #18570 I diverged from using plt.stairs because resulting plot was different (stairs does not form bars, just an outline of the histogram). However, I simplified the code by utilizing normal histogram function. Moreover, I believe that there was an misconception with dynamically allocated bins that rendered manual histogram with errors (if we set constant number of bins, but range of
np.random.normalis different, then edges and counts are out of sync). This was fixed by pre-calculating edges and making them constant.PR Checklist
pytestpasses).flake8on changed files to check).flake8-docstringsand runflake8 --docstring-convention=all).doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).