basemap set_bad() for Nan values - python

I have tried to use numpy masked array and basemap module to plot raster data with no-data values. I defined a color map as cmap and then used cmap.set_bad(color='grey') to set no-data value to color gray. I then use contourf(...,cmap=cmap) to plot the raster, however, the no-data is still shown as white color.
I have been searching a lot of examples of "set_bad", it looks like it works fine for imshow() function. I wonder does anyone have any experience using contourf and set_bad to show the raster images with nodata values?
Thanks a lot for your help.

Related

Retrieve actual data from raster with colorbar Python

I know that matplotlib can map data on RGB values. A classic exemple could be values of elevation mapped with the "terrain" cmap from matplotlib.
Captured from GRASS tutorial
I have an RGB tiff file corresponding to magnetic anomalies. This is useless because there is actually no data but only RGB values. But... If only I could "reverse", "un-normalize" the RGB values from the colobar to retrieve the data... That would be amazing! Is there a function I do not know in matplotlib (or anything else) to do that?
Like:
def fictionnal_fonction(img=TiffFile, min=min_on_colorbar, max=max_on_colorbar, colormap=viridis):
return greyscale_array_actual_data
Thank you very much!!!

masking an imshow, or imshow with RGBA

A dataframe, which should be considered a matrix, contains values 0, 1, 2.
With imshow, I get a nice image. I can use a cmap with 3 discrete colors.
I want to highlight few rows, so visually I want to have those rows with alpha=1 and the other with alpha=0.1 .
Should I create the image myself, creating a matrix with RGBA entries?
Is there a more straight-forward way?
With Kind Regards,
Oren
I found a nice way to do that with Layer Images.
https://matplotlib.org/gallery/images_contours_and_fields/layer_images.html#sphx-glr-gallery-images-contours-and-fields-layer-images-py
Apparently I can imshow the matrix with the intended highlighted colors. And on top of that, add a imshow with values that are either the same, where I want to highlight, or white otherwise. I then make sure to have alpha=0.5 for example, for the second imshow.

Using Mayavi and Mlab to plot "bubbles"

Currently, I am attempting to plot some "bubble" like shapes in a 3D space using Mayavi/Mlab. These bubbles are represented by a numpy array of shape (840,1100,30) where the parameters represent (x,y,z) and the value at any x,y,z is either 1 or 0. The array can be thought of as a collection of Voxels that are either on or off. I try to plot this data with the following commands:
mlab.contour3d(finalVolume)
mlab.show()
But the plot is coming out in 2 dimensions instead of in 3 dimensions. I have looked at the documentation but am having trouble understanding. If anyone could provide some help or a push in the right direction, then I would be very appreciative!
Thanks!
Sounds like you need to use volume rendering to accomplish this. This can be accomplished using:
mlab.pipeline.volume(mlab.pipeline.scalar_field(s), vmin=0, vmax=0.8)
You will need to adjust the opacity transfer function using vmin and vmax to make an appropriate image. Examples on volume rendering can be found at: http://docs.enthought.com/mayavi/mayavi/mlab.html

matplotlib surface plot limited by the boundaries

Is there any kind of chance to "cut" the surface plot (x,y,z) made by use of the matplotlib by some well defined boundaries, so that I can draw any kind of shape in 3D. Now I can do that but x,y are 2D arrays (meshgrid) and the shape is always rectangular.
Example:
Here, the plate has a base-shape of rectangular (2d-array are used). The z coordinates are derived by some function f=f(x,y).
What I would like achieve is shown in the picture below (made by hand ;)). One idea is to turn-off a single cell. But how to make the cells transparent?
What you'd like is to mask some regions in the surface. Unfortunately, matplotlib does not support masked arrays yet for plot_surface, but you could circumvent it by using np.nan for those masked regions.
It is also detailed in plotting-a-masked-surface-plot-using-python-numpy-and-matplotlib.

Display colormap/heatmap values in Python on hover

I am new to Python and figured out that I can plot color maps the following way:
import matplotlib.pyplot as plt
#some image generating code
plot = plt.imshow(image)
plot.set_cmap(cmap)
plot.set_interpolation(interpolation_method)
plt.show()
Where image is an 2-dimensional numpy array in my case.
As result I get a beautiful colormap (could not post an image of it since I am new to this platform).
Link to my color map: http://s7.directupload.net/images/131017/t9aczkmq.png)
My Question
Is there a way to display the current value of a position/pixel in the upper colormap on mouse hovering? I need to display the actual value (within the array that has been plotted) not the color value.
Additional Question
Is there also a way to add a slicer to the output in order to change the cuts of the color map dynamically (similar to a FITS viewer).
Probably I just need the right modules, but I could not find any fitting my needs yet.
Thanks in advance!

Categories

Resources