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

Colorbar does not render with PowerNorm and min extend when using imshow #11486

Copy link
Copy link
Closed
@evas-ssec

Description

@evas-ssec
Issue body actions

Bug report

When using the PowerNorm to normalize data with imshow, if you turn on the min end of the extend for the colorbar the colorbar will not render.

Code for reproduction

import numpy as np

import matplotlib
matplotlib.use('Agg')
#matplotlib.use('Qt4Agg')

import matplotlib.pyplot as plt
import matplotlib.colors as colors

fig, ax = plt.subplots(2, 1)

test_data1 = np.zeros((100,100), ) # data at the bottom bound of the range
disp_obj1 = ax[0].imshow (test_data1, norm=colors.PowerNorm(gamma=0.5, vmin=0.0, vmax=1.0,),)
# ************ to reproduce the bug, use the line with 'both' or 'min' extends *************
#fig.colorbar(disp_obj1, ax=ax[0], )
fig.colorbar(disp_obj1, ax=ax[0], extend='max')
#fig.colorbar(disp_obj1, ax=ax[0], extend='min')
#fig.colorbar(disp_obj1, ax=ax[0], extend='both')

test_data2 = np.ones((100,100), ) * 0.25 # all positive data that's inside the range
disp_obj2 = ax[1].imshow (test_data2, norm=colors.PowerNorm(gamma=0.5, vmin=0.0, vmax=1.0,),)
# ************ to reproduce the bug, use the line with 'both' or 'min' extends *************
#fig.colorbar(disp_obj2, ax=ax[1], )
#fig.colorbar(disp_obj2, ax=ax[1], extend='max')
fig.colorbar(disp_obj2, ax=ax[1], extend='min')
#fig.colorbar(disp_obj2, ax=ax[1], extend='both')

fig.savefig("./test.png", )
plt.close(fig)

Actual outcome

image

I see the following warning (or similar in different environments) when I trigger the bug:

celestia:temp_tests evas$ python -m test
/Users/evas/anaconda/envs/aitf_ql_3/lib/python3.6/site-packages/matplotlib/colors.py:1199: RuntimeWarning: invalid value encountered in power
  np.power(resdat, gamma, resdat)
/Users/evas/anaconda/envs/aitf_ql_3/lib/python3.6/site-packages/matplotlib/colorbar.py:891: RuntimeWarning: invalid value encountered in true_divide
  z = np.take(y, i0) + (xn - np.take(b, i0)) * dy / db

Expected outcome

I would expect the colorbar to render correctly with the triangle on the bottom.

Matplotlib version

I'm using MacOS 10.11.5 and my environments were set up using conda.

I have tested this with Qt4Agg in python 3.6 and with Agg in both python 3.6 and python 2.7 (the bug appears with both).
I have matplotlib 1.5.1 in my python 2.7 environment and matplotlib 2.1.2 in my python 3.6 environment (the bug appears with both).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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