-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@story645 thanks for the suggestion! This PR is ready for review |
It looks like something went wrong with the layout. Also, please read the comments on the issue for ideas how to improve this. |
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? |
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. |
There was a problem hiding this comment.
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 .
galleries/examples/color/README.txt
Outdated
@@ -5,3 +5,5 @@ Color | ||
|
||
For a description of the colormaps available in Matplotlib, | ||
see the :ref:`colormaps tutorial <tutorials-colors>`. | ||
|
||
- colorbar_histogram.py: Example of a colorbar with a histogram inset. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- colorbar_histogram.py: Example of a colorbar with a histogram inset. |
You don't need to add anything to the readme
@@ -0,0 +1,46 @@ | ||
""" | ||
========================= | ||
Colorbar with Histogram |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colorbar with Histogram | |
Histogram as Colorbar |
This example is about using a histogram in place of a regular colorbar
# Create an axes on the right side of ax. The width of cax will be 20% of ax and the padding between cax and ax will be fixed at 0.05 inch. | ||
divider = make_axes_locatable(ax) | ||
cax = divider.append_axes("right", size="20%", pad=0.05) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said in the original issue, I want this example to use axes_inset for the colorbar b/c I think that is more reflective of the usual use case for these types of plots.
|
||
# Plot histogram | ||
midpoints = bins[:-1] + np.diff(bins) / 2 | ||
cax.barh(midpoints, counts, height=np.diff(bins), color=cmap(norm(midpoints))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you making the width of the bars (which is the height) equal to the difference of the bins?
I use it in midpoints to center the bars between ticks that are labeled with the bin edges.
…ayout, and adjust label positions
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 |
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. |
…) + remove yaxis inversion
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 |
The new dataset is bimodal so the histogram should be bimodal. Please check your bins and extents (for example the dark blue and dark orange should be more prominent). 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. |
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