I want to plot the ocean currents data using plotly, I have the following information:
longitude (array | shape -> (360,)): The array with longitude points
latitude (array | shape -> (140,)): The array with latitude points
U (2d-array | shape -> (140, 360)) : The array with x-component of current velocities
V (2d-array | shape -> (140, 360)) : The array with y-component of current velocities
I tried it with matplot and it works well:
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
mymap=plt.streamplot(lon, lat, U, V, density=6, transform=ccrs.PlateCarree(), color=U, cmap='autumn')
ax.plot(xx, yy)
plt.show()
But plotly throws the following error:
fig = ff.create_streamline(lon, lat, U.T, V.T)
File "C:\Users\91983\anaconda3\envs\face\lib\site-packages\plotly\figure_factory\_streamline.py", line 112, in create_streamline
utils.validate_equal_length(x, y)
File "C:\Users\91983\anaconda3\envs\face\lib\site-packages\plotly\figure_factory\utils.py", line 99, in validate_equal_length raise exceptions.PlotlyError(
_plotly_utils.exceptions.PlotlyError: Oops! Your data lists or ndarrays should be the same length.
I tried
x, y = np.meshgrid(lon, lat)
x, y = np.vstack([x.ravel(), y.ravel()])
But I am unable to appropriately modify U and V
Example data:
lon = [-9.5, -8.5, -7.5, -6.5, -5.5]
lat = [-10.5, -11.5, -12.5]
U = [[ 0.01359653 -0.06777997 -0.01459221], [ 0.10778577 -0.0182181 -0.04552014], [-0.12153802 -0.10809003 -0.08621038], [-0.03212119 0.03420004 0.0011446 ], [0.01677546 0.02874723 0.121696 ]]
V = [[-0.0171657 -0.06966873 -0.05578572 -0.03955243 -0.05238442], [-0.01327003 -0.02819919 -0.07014654 -0.06515452 -0.00050288], [-0.01017548 -0.01393307 -0.03817951 -0.03380885 0.03111682]]