Skip to content

Imshow does not copy data array but determines colormap values upon call #6419

Closed
@kgabor

Description

@kgabor

The following code produces a horizontal gradient plot instead of a horizontal line:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm

Z=np.zeros((100,100))
Z[50]=100
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
ax.imshow(Z,cmap=matplotlib.cm.Greys)
Z[...]= np.arange(100.)[np.newaxis,:]

plt.show() 

Please note that if we comment Z[50]=100 the issue is not apparent as an all white figure is created as expected, but e.g. in Qt4Agg backend, mouseover values shows the altered Z values.

This means that imshow does not copy the data array but sets the color scale at the ax.imshow() call.

If data is intentionally not copied, I'd suggest adding a big warning about this behavior in the documentation and then the colorscale determination should be deferred until the figure is actually drawn. Otherwise the data should be copied.

  • pip installed Matplotlib: 1.5.0, numpy: 1.10.1
  • Ubuntu 14.04 python: 3.4.3

Metadata

Metadata

Assignees

Labels

Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions