Displaying Paths with Geoviews

2019-07-27 05:17发布

I'm trying to use geoviews to display a path. I can get it to display ONLY the points properly:

import numpy as np
import geoviews as gv
import cartopy.crs as ccrs
import pandas as pd

hv.extension('bokeh')

coord_system = ccrs.UTM(17)

userLine = [[ 501386.89237725, 3026047.23276743],
 [ 502233.40219658, 3030363.86891928],
 [ 497065.22714886, 3031309.6654351 ],
 [ 499260.08171301, 3027147.9437062 ],
 [ 494678.08475863, 3026891.08691589],
 [ 494971.32963864, 3025188.1383645 ],
 [ 496475.86909916, 3025394.03293946],
 [ 496061.07730504, 3026116.58492655],
 [ 497530.90995815, 3026357.00292598]]

line_pd = pd.DataFrame(userLine, columns=['Longitude', 'Latitude'])
pressure = pd.DataFrame(np.arange(0,401,np.ceil(401/len(userLine))), columns=['Pressure'])
windspeed = pd.DataFrame(np.arange(0,201,np.ceil(201/len(userLine))), columns=['Max_Wind_Speed'])
alldata = pd.concat([line_pd,pressure,windspeed], axis=1)

gvdata = gv.Dataset(alldata, kdims=['Pressure','Max_Wind_Speed','Longitude','Latitude'])
hover = HoverTool(tooltips=[("Longitude", "@Longitude"), ("Latitude", "@Latitude"), ("Pressure","@Pressure"),("Max Wind Speed","@Max_Wind_Speed")])

%%opts Points (size=10 cmap='inferno') [tools=[hover] color_index=4]
gvdata.to(gv.Points, kdims=['Longitude', 'Latitude'], vdims=['Pressure','Max_Wind_Speed'], crs=coord_system)

But what I really want is a path. However, when I try:

gvdata.to(gv.Path, kdims=['Longitude', 'Latitude'], crs=coord_system)

I get the error message DataError: None of the available storage backends were able to support the supplied data format.

I have tried reformatting the input data, but no success. I'm not sure what else I could be doing wrong.

1条回答
神经病院院长
2楼-- · 2019-07-27 05:59

The .to method has the purpose of letting you easily group high-dimensional data. In this particular example you have only two dimensions (latitude and longitude) so there is no need to use .to. In your particular example this should be sufficient to construct the plot:

gv.Path([userLine], crs=coord_system)

Path types in HoloViews can be constructed using a list of arrays, dataframes or dictionary of columns, so this would also work:

line_pd = pd.DataFrame(userLine, columns=['Longitude', 'Latitude'])
gv.Path([line_pd], crs=coord_system)

Edit: In your expanded example the format that works for me is as follows:

%%opts Path (cmap='inferno') [tools=[hover] color_index='Max_Wind_Speed']
gv.Path([alldata], vdims=['Pressure','Max_Wind_Speed'], crs=coord_system)
查看更多
登录 后发表回答