Closed
Description
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