1

从数据着色器中绘制数据时如何绘制颜色条。我正在使用带有位置和航向 (0-360*) 的车辆数据

最小的数据着色器代码:

import seaborn as sns, datashader as ds
from matplotlib.cm import ListedColormap

cmap = ListedColormap(sns.color_palette("hls", 8).as_hex())
agg = canvas.points(df, "longitude", "latitude", ds.mean("heading"))
img = tf.shade(agg, cmap=cmap, how="eq_hist")
img

这会生成具有清晰道路和方向的彩色图像,除非没有图例就无法分辨哪种颜色映射到哪个方向。

目前,我正在使用 Plotly 使情节具有交互性,因为由于某种原因,holoviews/bokeh 方法非常糟糕。这是我结合它们的教程:https ://plot.ly/python/v3/change-callbacks-datashader/ 。

4

2 回答 2

1

Datashader isn't made to render things like axes and colorbars, relying on embedding into an external library for such things. How you do it depends on the external library. For the plotly example you linked, it would be most direct to change the gen_ds_image function to return agg_scatter instead of img, and then use Plotly's array plotting functionality to do the colormapping and create a colorbar that would then automatically match. I don't use Plotly enough to give you any guidance on that, but it should be straightforward for a Plotly user, as the result of gen_ds_image will then just be a 2D array of directions per pixels, which presumably can easily be plotted as colors.

I'm not sure what problems you had with the Bokeh+HoloViews approach, but it should take much less code than that Plotly example; you'd just need to be sure to use rasterize() and not datashade() (to let Bokeh do the colormapping and matching colorbar). See https://anaconda.org/jbednar/datashade_vs_rasterize/notebook for background info.

于 2019-12-03T23:43:45.637 回答
0

我在原始帖子中使用了数据着色器,并添加了一个 colorbar_trace ,如此处所做的:一个链接 它起作用了。

我所做的唯一更改是它显示 colorscale=red_blue,我更新为触发,并将散点图的背景色设置为“黑色”以匹配地图。

所以在 datashader 链接的 update_layout 部分添加以下内容:

plot_bgcolor="黑色",
paper_bgcolor="黑色"

并在 stackoverflow 链接的标记部分添加以下内容:
colorscale=fire

于 2022-01-28T23:04:02.910 回答