Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add example to histogram colorbar on galleries#30107

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
livlutz wants to merge31 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromlivlutz:histogram-colorgram

Conversation

livlutz
Copy link

PR summary

This PR contains an example code for generating histogram colorbar on the galleries section with a reference to it on the readme file
closes#30026

PR checklist

@github-actionsgithub-actionsbot added the Documentation: examplesfiles in galleries/examples labelMay 25, 2025
@livlutz
Copy link
Author

@story645 thanks for the suggestion! This PR is ready for review

@rcomer
Copy link
Member

It looks like something went wrong with the layout. Also, please read the comments on the issue for ideas how to improve this.

livlutz reacted with thumbs up emoji

@livlutz
Copy link
Author

livlutz commentedMay 25, 2025
edited
Loading

thanks for the feedback, I tried to make some adjustments but I cannot see if my changes were successful, how does this link you commented before work?

@rcomer
Copy link
Member

rcomer commentedMay 25, 2025
edited
Loading

how does this link you commented before work?

At the bottom of this page are some automated checks. Scroll to the bottom of them and you see "View the built docs". Click on that and you can then navigate to your example from there.

But you can also just run your script locally to see how the plot looks. That will give you faster feedback.

Copy link
Member

@story645story645 left a comment
edited
Loading

Choose a reason for hiding this comment

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

As@rcomer said, please look at the original issue - particularly the suggestion to use binomially distributed data .

@livlutz
Copy link
Author

Thanks a lot for all the suggestions, I tried to see the changes locally like@rcomer said and it should look much better now, please let me know if there's still something missing

@story645
Copy link
Member

story645 commentedMay 26, 2025
edited
Loading

Can you please try the dataset@jklymak suggested in the original issue?

Also can you remove the spines (code should also be in the original example). Also please remove the yaxis_inversion as that's confusing me here - it might be clearer if you add the colorbar like in the original issue. Which also setting the margins to 0 (see original example) will remove the spacing for the bar chart so that it takes up the whole space (also please set height to 100% so they line up) - you are welcome to add that as a comment if it makes it clearer and to ask about the purpose of any code you don't understand.

@livlutz
Copy link
Author

I tried the first example from here :https://matplotlib.org/devdocs/gallery/images_contours_and_fields/image_demo.html and it worked just fine! please tell me if it is alright now

@story645
Copy link
Member

story645 commentedMay 26, 2025
edited
Loading

The new dataset isn't a normal distribution so the histogram should also not be a normal distribution. Please check your bins and extents (for example the dark blue and dark orange should be more prominent).

sphx_glr_colorbar_histogram_001_2_00x.png

Please plot the histogram without preset bins so that you can see what it's supposed to look like and then follow the example in the original issue for visualizing the correct histogram. Please ask questions if you don't understand the code.

Copy link
Member

@story645story645 left a comment

Choose a reason for hiding this comment

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

Also please remove the spines and margins from the histogram.

@livlutz
Copy link
Author

The new dataset isn't a normal distribution so the histogram should also not be a normal distribution. Please check your bins and extents (for example the dark blue and dark orange should be more prominent).

sphx_glr_colorbar_histogram_001_2_00x.png

Please plot the histogram without preset bins so that you can see what it's supposed to look like and then follow the example in the original issue for visualizing the correct histogram. Please ask questions if you don't understand the code.

I took a look at the original issue but it says the new dataset is a bivariate normal distribution, should I still change the histogram? And I'm a bit confused about the extents, do you have any suggestions on what changes should I make?

…, improve inset axes layout, and enhance label spacing
@livlutz
Copy link
Author

I changed the histogram slightly so it depicts a bivariate normal distribuition, please tell me if I still need to fix anything

@livlutz
Copy link
Author

Yes and it looks slightly different from the output I got when I ran the program locally...does it have to do with the output screen scale?

@story645
Copy link
Member

story645 commentedMay 28, 2025
edited
Loading

I'm not sure the context for this question. In general, you want as many bins as you can get without having too many singleton bins.

Just that for the visualization it would maybe be less busy if there are fewer bins but it's not a big deal/blocker.

@jklymak
Copy link
Member

The still has linting errors, and the word "count" is not fitting in the figure, so you can either manually mess with the sizes, or uselayout='constrained'.

@jklymak
Copy link
Member

Just that for the visualization it would maybe be less busy if there are fewer bins but it's not a big deal/blocker.

If it's too busy, I'd just get rid of the spacing between the bars.

@livlutz
Copy link
Author

I managed to fix most of the linting errors, but something is happening with mypy and I am not really sure I understand what is going on

@livlutz
Copy link
Author

@story645 Hello, so I heard a lot of people are having trouble with mypy linting errors due to an update so I was just wondering what will happen to this PR later on since many people (including me) are stuck on that

@rcomer
Copy link
Member

The mypy problems have been fixed on the main branch. It might be enough to close and re-open the PR to pick up those changes.

@rcomerrcomer closed thisJun 6, 2025
@github-project-automationgithub-project-automationbot moved this fromNeeds review toWaiting for author inFirst Time ContributorsJun 6, 2025
@rcomerrcomer reopened thisJun 6, 2025
Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

Overall, the commenting feels a bit too noisy. Please recheck with ourexample guidelines and see if you can improve a bit.

I have the impression that comments are used to create sections with headings (# === Surface Data ===). IMHO that's too much for examples. The code should mostly be able to stand for itself. If comments are used, they should be an explantion, i.e. you'd typically write# surface data but not# === Surface Data ===.

@livlutz
Copy link
Author

Thanks for the help! I managed to get rid of linting errors (finally!) so this is ready for review.

@livlutz
Copy link
Author

I applied the suggested changes and I also checked how it looks like on the built docs and everything looks alright, do we need to change anything else?

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

Gerneally, please lowercase the comments. As said, they are not section titles but remarks.

@livlutz
Copy link
Author

I'm just getting an error in line 30 : line 30, in
norm = mcolors.BoundaryNorm(bins, cmap.N)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/matplotlib/colors.py", line 2042, ininit
super().init(vmin=boundaries[0], vmax=boundaries[-1], clip=clip)
~~~~~~~~~~^^^
TypeError: 'int' object is not subscriptable

I am not really sure what it means and I think we should change the parameters

@livlutz
Copy link
Author

Thank you for the help, I managed to fix it now! Hopefully it works alright now

timhoffm reacted with thumbs up emoji

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

Only minor formatting comments left.

cax = ax.inset_axes([1.18, 0.02, 0.25, 0.95]) # left, bottom, width, height

# plot histogram
counts, bin_edges = np.histogram(Z, bins=bins)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
counts,bin_edges=np.histogram(Z,bins=bins)
counts,_=np.histogram(Z,bins=bin_edges)

Sorry, I just realized, we can make this now slightly safer/more obvious by using the existingbin_edges and not letnp.histogram create them anew, hoping they are identical to the explicit calculation above.

@livlutz
Copy link
Author

Is there anything else left to change?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@story645story645story645 left review comments

@jklymakjklymakjklymak left review comments

@timhoffmtimhoffmtimhoffm left review comments

@rcomerrcomerrcomer left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
Documentation: examplesfiles in galleries/examples
Projects
Status: Waiting for author
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[Doc]: add histogram as colorbar example
5 participants
@livlutz@rcomer@story645@jklymak@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp