Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Bug]: Image color limits not correctly updated with set_clim() IFF color bar present AND new norm.vmin > old norm.vmax #29522

Closed
@erikdendekker

Description

@erikdendekker

Bug summary

I experienced some specific odd cases where I noticed that the colors of an image were not correctly set after updating the image data and setting new color limits with set_clim(). After debugging I was able to reproduce with a minimal example,..

Code for reproduction

importnumpyasnpfrommatplotlibimportpyplotasplt# Create test datanp.random.seed(19771105)data_0=np.round(np.random.rand(10,20),1)data_1=data_0+10# Compute data rangerange_0=data_0.min(),data_0.max()range_1=data_1.min(),data_1.max()# Plot data as image; Auto adjusts colorbar scale to value rangeimage=plt.imshow(data_0)cbar=plt.colorbar(image)# NOTE: Problem does not occur if colorbar not created!print(f'expected norm ={range_0}')print(f'actual   norm ={image.norm.vmin,image.norm.vmax}')# Change image data and update image color limitsimage.set_data(data_1)image.set_clim(range_1)print(f'expected norm ={range_1}')print(f'actual   norm ={image.norm.vmin,image.norm.vmax}')# Incorrect!plt.show()

Actual outcome

expected initial norm = (0.0, 1.0)computed initial norm = (0.0, 1.0)expected updated norm = (10.0, 11.0)computed updated norm = (0.9, 11.0)

Image

Expected outcome

expected initial norm = (0.0, 1.0)computed initial norm = (0.0, 1.0)expected updated norm = (10.0, 11.0)computed updated norm = (10.0, 11.0)

Image

Additional information

Only happens if color bar is present; Removing the line that creates it from code lets you see the correct image (minus color bar).
Data dependent; Only occurs if the lowest value of the new image data is higher than the highest value of the old image data (Hence +10 in the code example).

Operating system

Windows 10

Matplotlib Version

3.6.0

Matplotlib Backend

QtAgg

Python version

3.11.9

Jupyter version

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp