Skip to content

Fix: Log Colorbar minorticks_off reverted if ticks set #13351

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

Conversation

LevN0
Copy link
Contributor

@LevN0 LevN0 commented Feb 3, 2019

PR Summary

Closes #13339.

Fixes issue where colorbar lognorm minorticks are turned back on anytime ticks are updated.

Before

Any time ColorbarBase.update_ticks is called, it forces minorticks on for LogNorm. Calling methods like set_ticks therefore reverts the action of minorticks_off.

fig, ax = plt.subplots()

data = np.clip(randn(250, 250)*1000, 0, 1000)

cax = ax.imshow(data, norm=mpl.colors.LogNorm(vmin=1, vmax=1000))
cbar = fig.colorbar(cax, format='%d')

cbar.minorticks_off()
cbar.set_ticks([5, 10, 100])

plt.show()

Produces,

mpl3_lognorm_update_ticks_before

(Note minorticks come back on, after being explicitly turned off.)

After

Minorticks stay off after being manually turned off.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@LevN0
Copy link
Contributor Author

LevN0 commented Feb 3, 2019

Should I add a unit test?

If so, would I adjust one I wrote a few days ago to test minorticks can be turned off for LogNorm to also add this condition (e.g. just add set_ticks after minorticks_off, prior to testing they are really off), or leave those tests alone and write a separate one (that would still do the above)?

@NelleV
Copy link
Member

NelleV commented Feb 3, 2019

@LevN0 Yes, a unit test is in order.

Either adding a new one, or adding checks to an existing one is fine.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Looks right to me, subject to a test in test_colorbar.py (preferably one w/o a new image)

@LevN0 LevN0 force-pushed the fix-log-colorbar-minorticks-revert-set-ticks branch from 14fad1c to 6ba23b8 Compare February 3, 2019 17:28
@LevN0
Copy link
Contributor Author

LevN0 commented Feb 3, 2019

Added a test.

@@ -579,6 +579,10 @@ def _reset_locator_formatter_scale(self):
# mid point is easier.
self.ax.set_xscale('log')
self.ax.set_yscale('log')

if type(self.norm) == colors.LogNorm:
Copy link
Member

Choose a reason for hiding this comment

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

OK, actually we don't need the check here, do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a very good point.

@LevN0 LevN0 force-pushed the fix-log-colorbar-minorticks-revert-set-ticks branch from 16d3377 to 347f65b Compare February 4, 2019 01:58
Fixes issue where colorbar lognorm minorticks are turned back on anytime
ticks are updated
@LevN0 LevN0 force-pushed the fix-log-colorbar-minorticks-revert-set-ticks branch from e8a5d91 to ffaaabd Compare February 4, 2019 02:09
@NelleV
Copy link
Member

NelleV commented Feb 4, 2019

This looks good! Thanks!

@NelleV NelleV merged commit 3ad9be2 into matplotlib:master Feb 4, 2019
@QuLogic QuLogic added this to the v3.1.0 milestone Feb 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants