Holoviews: Plot frame(s) dimensions and aspect ratio - python

I am currently desperately trying out to align three images with different sizes in a gridlike layout.
Essentially, I would like to insert three raster images of different shapes. I would like to be able to define their boundary and aspect ratio of each raster independently that they are not stretched in one dimension. However, I fail to find a fix doing that.
My code snipplet:
import holoviews as hv
import numpy as np
hv.extension('bokeh')
%%opts Raster [show_frame=False shared_axes=False]
hv.Layout(hv.Raster(np.eye(100,100),group='t1') +
hv.Raster(np.eye(100,20),group='t2') +
hv.Raster(np.eye(20,100),group='t3')).cols(2)
Which produces the following:
Sample Image
Is there any way to define each raster image bounding box individually in a layout?
Thanks in advance!

I found the solution after searching through the API.
width and height can be adjusted individually by opts:
hv.Raster(np.eye(100,100),group='t1').opts(plot=dict(width=500, height=500))

Related

How to draw a Heatmap in a image using the coordinates in Python OpenCV?

I've a huge list of Coordinates(x,y) of people walking in the streets and I like to design a heatmap using those Coordinates(x,y), i.e., it should look something like this. I want much hotter spot for multiple coordinates in a single spot, hotter means red colored spot. I've tried this but ended up getting a heatmap like this not the one I expected nor the site mentioned in the beginning(the wikipedia heatmap). This is the code I tried,
import cv2
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
x,y = [230,150,200],[200,100,150]
plt.imshow(img)
ax = sns.kdeplot(x,y, cmap = "Blues", shade= True, shade_lowest=False)
ax.set_frame_on(False)
plt.axis('off')
plt.savefig('heatmap_pic.png')
This code also made the result image size smaller the actual image was much bigger. I'm new to OpenCV and Matplotlib someone please help me with this, to plot a Heatmap(like this) in a image using a bunch of Coordinates.
You need to take image, create the heatmap, and superimpose it.
Check this or this.

plot image with interpolation in Python Bokeh like matplotlib?

Is there any way to plot 2D array as an image using Bokeh with interpolation like in Matplotlib? I am able to plot using an example: https://docs.bokeh.org/en/latest/docs/gallery/image.html
However, the image is to coarse. I like the way interpolation work in Matplotlib: https://matplotlib.org/gallery/images_contours_and_fields/interpolation_methods.html
I tried to perform interpolation beforehand but the matrix size now is to big.
I had the same issue and I've found the answer in pyviz's Gitter.
The solution combines Holoviews and Datashader:
import holoviews as hv
from holoviews import opts
from holoviews.operation.datashader import regrid
img = hv.Image(data)
regrid(img, upsample=True, interpolation='bilinear')
If you are working with a large dataset then you could try Bokeh in combination with Datashader/HoloViews like in this example. When zooming in, Datashader can dynamically create new high quality images from your data that could be displayed in your Bokeh plot.
Not an answer but an observation - I've noticed that plotting an image via an image_url source it appears interpolated when zoomed in whilst if you read in the same image and display it from a columndatasource via 'image' it then appears blocky when zoomed. I'd love to know how to make it appear interpolated too when zoomed, eg like the raw png image appears. Holoview/datashader would be a great solution but in my case I need it to work offline/as a standalone html file.

How to save an image plotted with matplolib 1.5

I want to save an image plotted with matplotlib. For that, I use the function savefig which has different parameters.
The problem is that when I saved the image, this function add additional white pixel.
In short, I would like to save the image I draw with the original size. In other words, if the data I draw has a dimension of 1000x560, I save the image with those dimensions without additional white parts.
Thus in this way a pixel of the saved image coincides with the pixel that the figure of matplotlib can see.
I'm using python 2.7
Can anyone help please?
Thanks
from matplotlib import pyplot as plt
plt.savefig('foo.png', bbox_inches='tight')

How to color specific area on mayavi 2d array plotting

I'm using mayavi python library for plotting my 2d elevation array (Extracted from Raster DEM) and its generating 3d visualization using my elevation data perfectly. but i want to show some specific areas on different color.
I'm calculating risky slope areas and i want to show those areas on map using different color.
dataset = gdal.Open("elevation.tif", GA_ReadOnly)
band = dataset.GetRasterBand(1)
demArray = band.ReadAsArray()
mlab.figure(size=(640, 800) , bgcolor=(1, 1, 1))
surf = mlab.surf(demArray, warp_scale=0.1 )
mlab.show()
generated dem using mayavi
Could anyone can tell my how to mark specific area using different color in mayavi or any other alternative solution to my problem.
Here I have a link for you. I think you will learn more from it.
(http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#mayavi.mlab.contour3d)
Good luck!
Finally i found a solution. Mayavi library support to add textures to its objects. So by creating blank image and mark specific areas on map, I could create perfectly overlapping texture to mark specific areas on my DEM.

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