0

First of all, if anyone has a link to a good tutorial to creating colomaps with geoviews or holoviews and transporting that to a dashbooard please send a link. I am trying to mimick what they did at the timestamp in the video here . Also having a hard time finding good documentation of geoviews other than the few examples on their website, so a point to the full docs would be great.

Anyways, I have a pretty basic plot I think. It a mesh of x a mesh of y and a mesh of a z value. I want to plot this in geoviews. It contains interpolated motions from GPS stations basically and I want to make a colormap of the z value. I can plot this really easily with matplotlib with a simple

plot = plt.scatter(mesh_x, mesh_y, c = z1, cmap = cm.hsv)

but trying to get this into geoviews makes a really funky dataframe.

running print(np.shape(mesh_x),np.shape(mesh_y), np.shape(z1)) shows the shape of all of these are (41,348). If I try to put them into a single array with a = np.array((mesh_x,mesh_y,z1)) I get an array of shape (3,41,348) as expected. From here I am really just guessing on what to do. When I try to put this into a geoviews points data frame with

points = [a[0], a[1], a[2]] df = gv.Points(points) df.dframe()

and then run df.dframe() it shows two columns, longitude and lattitude with incorrect values, here is a screenshot of what it shows if its helpful enter image description here

I have tried converting to an xarray because it seems that is preferred in all the examples shown on geoviews website but that looks funky as well. When I try xrtest = xr.DataArray((mesh_x,mesh_y,z1)) I get a xarray that looks like this enter image description here

At this point I have no idea what to do. I have tried a few different ways that I though may work but I can't remember all of them. This is where I am at now. I am sure I am doing something completely wrong, I just have no idea how to do it correctly. Thank you

Nwpulver
  • 45
  • 5
  • I'm a bit confused by your question; gv.Points (like plt.scatter) is for plotting points, but it sounds like your data is a mesh, not points at all? GeoViews offer several different classes for plotting meshes, depending on how regular they are; yours sounds maybe like a TriMesh (but also consider Image and QuadMesh). – James A. Bednar May 20 '20 at 00:24
  • I tried image and it says Image type expects gridded data, PandasInterface is columnar.To display columnar data as gridded use the HeatMap element or aggregate the data. It says the same when I convert to numpy array. I was using Points because i used scatter to plot them in mpl. – Nwpulver May 20 '20 at 15:48
  • Image is for visualizing fully regular gridded data, Quadmesh is for visualizing data that's on a grid but with irregular spacing on each axis; both expect gridded data. HeatMap is similar to Image but allows categorical axes, not just numeric. If what you have a is just a list of points at arbitrary locations, then you can use Points (see separate answer) or TriMesh, both of which expect/accept columnar data. – James A. Bednar May 20 '20 at 19:13

1 Answers1

0

Assuming you want a points plot as you are using in Matplotlib, the HoloViews equivalent to plt.scatter is hv.Points. hv.Points accepts a tidy data format that you can get by transposing the data compared to Matplotlib:

import matplotlib.pyplot as plt
from matplotlib import cm
%matplotlib inline
mesh_x = [1,2,3,6]
mesh_y = [6,2,8,0]
z1 = [0.5, 4, 6,2]

plot = plt.scatter(mesh_x, mesh_y, c = z1, cmap = cm.hsv)

plt.scatter

import holoviews as hv
hv.extension('matplotlib')

hv.Points(zip(mesh_x,mesh_y,z1), kdims=["x","y"], vdims=["z"]).opts(color='z', cmap="hsv")

hv.Points

Here kdims=["x","y"], is optional but is explicit about the key dimensions you want. You may also want to consider hvPlot, which handles the same data format as plt.scatter:

import pandas as pd
df = pd.DataFrame(dict(x=mesh_x,y=mesh_y,z=z1))

import hvplot.pandas
df.hvplot.scatter(x="x", y="y", c="z", cmap="hsv")

enter image description here

James A. Bednar
  • 3,195
  • 1
  • 9
  • 13
  • Thanks for your reply James. I was inspired to try holoviews because a video of a presentation you did about pyviz. I will give hvplot a shot as well as Trimesh as you suggested above. – Nwpulver May 20 '20 at 21:32