python - How to set the alpha value for each element of a numpy array -


I want to populate an array and then want to show it as an image. I want to set two parameters for each array element: A "color value" and "transparency value" I am using imshow from matplotlib, but I have open for other solutions I have tried to do something like this, Where ca_map is an MxN array.

  ca_map = np.array (ca_map) palette = cm.jet palette.set_under ('w', 1.0) plt. Axis ('off') plt.imshow (ca_map, cmap = palette, norm = colors.Normalize (vmin = 0, clip = false), projection = 'sinc') plt.show ()   

Thanks in advance.

Docs () says that to show you an MxNx4 array values ​​of RGBA, CA_map Believing MxNx3, you can do something like this:

  plt.imshow (np.dstack ([ca_map, alpha], ...)   

Or if ca_map is MxN:

  plt.imshow (np.dstack ([ca_map, ca_map, ca_map, alpha], ...)   < / Div> 

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -