Skip to content

Example: remove overlapping text from image_masked.py #7682

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

Merged
merged 2 commits into from
Dec 25, 2016

Conversation

efiring
Copy link
Member

@efiring efiring commented Dec 25, 2016

This also makes several other changes that clarify the example
and improve the code.

This also makes several other changes that clarify the example
and improve the code.
@efiring efiring added this to the 2.0 (style change major release) milestone Dec 25, 2016
@efiring
Copy link
Member Author

efiring commented Dec 25, 2016

While looking for examples using a proportional colorbar, I noticed that the image_masked.py example looks terrible, with colorbar tick labels smashed together and axes titles overflowing their bounds. In this PR I spruce it up with some rearrangement, and edit and add labels to make it a bit easier to see what the example is showing. It's still not great, but it's better--no longer such a gross embarrassment.
image_masked

Copy link
Member

@NelleV NelleV left a comment

Choose a reason for hiding this comment

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

Overall this looks good. I have two nitpicks, that I think would be nice to fix.

x = y = np.arange(-3.0, 3.0, delta)
x0, x1 = -5, 5
y0, y1 = -3, 3
x = np.linspace(x0, x1, 500)
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -38,24 +40,33 @@
# Anything above that range is colored based on palette.set_over, etc.

# set up the axes
fig, (ax1, ax2) = plt.subplots(1, 2)
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(6, 5.4))
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the second argument unecessary?
I also tend to favor being explicit : nrows=2.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. I will fix this.

ax1.set_title('Green=low, Red=high, Blue=masked')
cbar = fig.colorbar(im, extend='both', shrink=0.9, ax=ax1)
cbar.set_label('uniform')
for ticklabel in ax1.xaxis.get_ticklabels():
Copy link
Member

Choose a reason for hiding this comment

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

The x-axis could be shared, which renders these two lines unecessary.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, both axis could be shared.

Copy link
Member Author

Choose a reason for hiding this comment

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

On the contrary, axis sharing is inconsistent with the default aspect-ratio handling of imshow. This is a fundamental limitation (to avoid an over-determined system), not a matter of implementation. Since imshow is typically used in cases where unit aspect ratio is desired, I decided to leave that default and forgo the axis sharing.

@NelleV NelleV changed the title Example: remove overlapping text from image_masked.py [MRG+1] Example: remove overlapping text from image_masked.py Dec 25, 2016
@NelleV
Copy link
Member

NelleV commented Dec 25, 2016

It would also be nice to use the new color scheme instead of the "r", "b", "g".

@efiring
Copy link
Member Author

efiring commented Dec 25, 2016

Regarding colors: In this case, I think that using the simple primary colors, with their simple name abbreviations in the code, is preferable for the purposes of illustration.

@tacaswell tacaswell merged commit 21eb2ed into matplotlib:v2.x Dec 25, 2016
@QuLogic QuLogic changed the title [MRG+1] Example: remove overlapping text from image_masked.py Example: remove overlapping text from image_masked.py Dec 26, 2016
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.

3 participants