Holoviews每个类别的颜色 [英] Holoviews color per category

查看:174
本文介绍了Holoviews每个类别的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在使用bokeh进行绘图.我只是发现了全息视图,并想绘制一个基本的箱形图.

I have been lately working with bokeh for plotting. I just found out about holoviews and wanted to plot a basic box plot.

在箱形图中,我尝试为要分组数据的类别之一上色.这是我正在使用的代码:

In my box plot I am trying to color per one of the categories I am grouping the data in. Here is the code I am using:

hv.extension('bokeh') %opts BoxWhisker (box_color='blue') boxwhisker = hv.BoxWhisker(pool_ride_distance_time_year_less_hour, ['total_time', 'customer'], 'amount') plot_opts = dict(show_legend=False, width=800, height=400)

hv.extension('bokeh') %opts BoxWhisker (box_color='blue') boxwhisker = hv.BoxWhisker(pool_ride_distance_time_year_less_hour, ['total_time', 'customer'], 'amount') plot_opts = dict(show_legend=False, width=800, height=400)

我正在尝试根据客户变量(是/否虚拟变量)对颜色进行不同的着色.当我尝试在box_color中包含列表时,它不起作用.在数据集中还包括一个带有颜色的额外变量并不能解决问题.关于如何使其工作的任何想法?谢谢!

I am trying to color it differently according to the customer variable (which is a yes/no dummy variable.) When I try to include a list in box_color it does not work. Also including an extra variable with color in the data set does not do the trick. Any ideas on how to make it work? Thanks!

推荐答案

HoloViews中的大多数元素具有color_index绘图选项,该选项允许按特定变量进行着色.在这里使用您的示例,我们通过'customer'变量着色,并使用Set1颜色图为box_color定义HoloViews Cycle.

Most Elements in HoloViews have a color_index plot option which allows coloring by a particular variable. Using your example here we color by the 'customer' variable and define a HoloViews Cycle for the box_color using the Set1 colormap.

data = (np.random.randint(0, 3, 100), np.random.randint(0, 5, 100), np.random.rand(100))
boxwhisker = hv.BoxWhisker(data, ['total_time', 'customer'], 'amount')
plot_opts = dict(show_legend=False, width=800, height=400, color_index='customer')
style_opts = dict(box_color=hv.Cycle('Set1'))
boxwhisker.opts(plot=plot_opts, style=style_opts)

如果要定义一组自定义颜色,还可以定义一个明确的循环,如下所示:Cycle(values=['#ffffff', ...]).

If you want to define a custom set of colors you can also define an explicit Cycle like this: Cycle(values=['#ffffff', ...]).

这篇关于Holoviews每个类别的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆