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

Appearance settings

FIX: inverted colorbar ticks #13563

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 1 commit into from
Mar 2, 2019

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Mar 2, 2019

PR Summary

Closes #13530

Before, if we inverted the colorbar the tick trimming logic was incorrect and we trimmed all the ticks! This fixes that.

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as mcolors

fig, axs = plt.subplots(2, 1)
axs = axs.flat
ax = axs[0]
pc = ax.pcolormesh(10**np.arange(1,5).reshape(2, 2), norm=mcolors.LogNorm())
cbar = fig.colorbar(pc, ax=ax, extend='both')
ticks = cbar.get_ticks()
cbar.ax.invert_yaxis()

ax = axs[1]
pc = ax.pcolormesh(np.arange(1,5).reshape(2, 2))
cbar = fig.colorbar(pc, ax=ax, extend='both')
ticks = cbar.get_ticks()
cbar.ax.invert_yaxis()
cbar.minorticks_on()
plt.show()

Before:

screen shot 2019-03-01 at 17 05 32

Note this also gives an error and the figure can't be saved:

  File "/Users/jklymak/matplotlib/lib/matplotlib/axis.py", line 1312, in get_minorticklocs
    minor_locs = self.minor.locator()
  File "/Users/jklymak/matplotlib/lib/matplotlib/colorbar.py", line 272, in __call__
    return ticks[(ticks >= vmin - rtol) & (ticks <= vmax + rtol)]
TypeError: only integer scalar arrays can be converted to a scalar index

After:

figure_1

and no error....

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

@jklymak jklymak added Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: color/colorbar labels Mar 2, 2019
@jklymak jklymak added this to the v3.1.0 milestone Mar 2, 2019
@jklymak jklymak requested a review from efiring March 2, 2019 01:06
Copy link
Member

@efiring efiring left a comment

Choose a reason for hiding this comment

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

Looks like this can go in after fixing the flake8 fuss; suggested slight simplification of the test is optional.

lib/matplotlib/tests/test_colorbar.py Outdated Show resolved Hide resolved
lib/matplotlib/tests/test_colorbar.py Outdated Show resolved Hide resolved
@jklymak jklymak force-pushed the fix-inverted-colorbar branch from 77d6280 to 318326e Compare March 2, 2019 02:25
@dstansby dstansby merged commit 66efef9 into matplotlib:master Mar 2, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Mar 2, 2019
timhoffm added a commit that referenced this pull request Mar 2, 2019
…563-on-v3.1.x

Backport PR #13563 on branch v3.1.x (FIX: inverted colorbar ticks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: color/colorbar
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.