Skip to content

Simplification of animated histogram example - #18821

Merged
timhoffm merged 2 commits into
matplotlib:masterfrom
deep-jkl:simplify-animated-histogram-example
Oct 30, 2020
Merged

timhoffm merged 2 commits into
matplotlib:masterfrom
deep-jkl:simplify-animated-histogram-example

Conversation

@deep-jkl

Copy link
Copy Markdown
Contributor

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.normal is different, then edges and counts are out of sync). This was fixed by pre-calculating edges and making them constant.

PR Checklist

  • [N/A] Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [N/A] New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Newly  a BarContainer from hist() function is used.

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is really a significant simplification.

Comment on lines +49 to +56
_, _, bar_container = ax.hist(
data,
HIST_BINS,
lw=1,
ec="yellow",
fc="green",
alpha=0.5
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_, _, 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +59 to +65
ani = animation.FuncAnimation(
fig,
prepare_animation(bar_container),
50,
repeat=False,
blit=True
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

Suggested change
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)

@timhoffm timhoffm added this to the v3.4.0 milestone Oct 29, 2020
@timhoffm
timhoffm merged commit 5ba3911 into matplotlib:master Oct 30, 2020
@timhoffm

Copy link
Copy Markdown
Member

Thanks @deep-jkl! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

@deep-jkl
deep-jkl deleted the simplify-animated-histogram-example branch April 13, 2022 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants