- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个由 ColumnDataSource
驱动的 hbar
图,其中 y 轴上有分类标签,两个数字 x 轴上有分类标签。为了在 y 轴上每个标签有两组条形,我构造了两个范围 (Things1=df.Thing.index + 1 - 0.2
和 Things2=df.Thing.index + 1 + 0.2
) 并将两个 hbar
实例分别分配给这些范围之一。
当且仅当 ColumnDataSource
中的范围 Things1
和 Things2
是使用预定义偏移量 1 构造的时,这才给我正确的布局;否则,所有标签和条形图都恰好偏移一个条目。
我现在构建绘图的方式如下所示:
df = pandas.DataFrame([('Store', 'Juice', 3, 19.0),
('Warehouse', 'Paint', 7, 21.0),
('Store', 'Fruit', 2, 6.0),
('Warehouse', 'Grass', 4, 15.0),
('Store', 'Leaves', 9, 32.0)],
columns=('Storage', 'Thing', 'Quantity', 'Valueation'))
source = bokeh.models.ColumnDataSource(dict(Quantity=df.Quantity,
Things1=df.Thing.index + 1 - 0.2, # Why +1 ?
Things2=df.Thing.index + 1 + 0.2, # Why +1 ?
Valueation=df.Valueation,
Storage=df.Storage))
plot = bokeh.plotting.figure(plot_width=800, plot_height=300,
y_range=list(df.Thing.unique()),
x_range=(0, df.Quantity.max() * 1.1))
plot.hbar(y='Things1', right='Quantity', height=0.3, alpha=0.7, source=source)
plot.hbar(y='Things2', right='Valueation', height=0.3, alpha=1, source=source,
x_range_name="ValueationRange")
plot.yaxis.axis_label = 'Thing'
plot.xaxis.axis_label = 'Quantity'
plot.extra_x_ranges = {"ValueationRange":
bokeh.models.Range1d(start=0, end=df.Valueation.max() * 1.1)}
plot.add_layout(bokeh.models.LinearAxis(x_range_name="ValueationRange",
axis_label='Valueation'), 'above')
bokeh.plotting.show(plot)
Things1/2=df.Thing.index + 1 -/+ 0.2
给出正确的绘图:
使用 Things1/2=df.Thing.index -/+ 0.2
我得到
我的猜测是,这是由于不同的范围是基于 0 或 1 的。这是一个简单的陷阱还是我做错了?
最佳答案
编辑事实证明,这种使用原始值(而不是真实的分类数据)和因子范围的方法没有记录和未经测试。分类数据的处理将在 0.12.7 中发生变化,这将允许正确使用分类数据所需的功能 - 请参阅下面的 bigreddots(主要 Bokeh 开发人员)评论。
仅从观察来看,分类范围的默认行为似乎是将整数 y 值从 1 开始映射到类别。
如果在初始化绘图对象后添加 y_range,则会暴露原始刻度:
正如您所提到的,这只是由于范围所致。第一个绘制的数据系列从 0 开始,但第一个标签从 1 开始。您可以使用 funtickformatter 设置偏移量或将显式 y 刻度映射到值,这可以精确控制值和标签之间的映射。
如果你看一个例子,例如 http://docs.bokeh.org/en/latest/docs/gallery/categorical.html ,您可以看到数据映射到类别,但这是因为 y 值本身作为因子输入。在您的示例中,您只是更改 y 轴,但为了偏移值,您不能使用原始类别本身。
顺便说一句:编辑 offset 属性在 0.12.7 中可能不存在,因此最好不要依赖它/假设它存在。
查看文档,它说默认偏移量为 0。所以我认为您需要 -1 的偏移量来解释这一点。请参阅http://docs.bokeh.org/en/latest/docs/reference/models/ranges.html#bokeh.models.ranges.FactorRange.offset
import pandas
import bokeh
import bokeh.models, bokeh.plotting
df = pandas.DataFrame([('Store', 'Juice', 3, 19.0),
('Warehouse', 'Paint', 7, 21.0),
('Store', 'Fruit', 2, 6.0),
('Warehouse', 'Grass', 4, 15.0),
('Store', 'Leaves', 9, 32.0)],
columns=('Storage', 'Thing', 'Quantity', 'Valueation'))
source = bokeh.models.ColumnDataSource(dict(Quantity=df.Quantity,
Things1=df.Thing.index - 0.2, # Why +1 ?
Things2=df.Thing.index + 0.2, # Why +1 ?
Valueation=df.Valueation,
Storage=df.Storage))
plot = bokeh.plotting.figure(plot_width=800, plot_height=300,
y_range=list(df.Thing.unique()),
x_range=(0, df.Quantity.max() * 1.1))
plot.y_range.offset = -1
plot.hbar(y='Things1', right='Quantity', height=0.3, alpha=0.7, source=source)
plot.hbar(y='Things2', right='Valueation', height=0.3, alpha=1, source=source,
x_range_name="ValueationRange")
plot.yaxis.axis_label = 'Thing'
plot.xaxis.axis_label = 'Quantity'
plot.extra_x_ranges = {"ValueationRange":
bokeh.models.Range1d(start=0, end=df.Valueation.max() * 1.1)}
plot.add_layout(bokeh.models.LinearAxis(x_range_name="ValueationRange",
axis_label='Valueation'), 'above')
bokeh.plotting.show(plot)
关于python - 与 Bokeh hbar 和 ColumnDataSource 的标签相差一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45280354/
我用 bokeh.plotting.Figure.line 画了下面的图。我如何添加垂直引用线来强调 Feb/14 的一个点? 这是另一个情节。这是 bokeh.charts.Bar。我想添加水平指南
我使用 python 在 Bokeh 中创建了一个散点图。我想创建一个小部件,允许用户更改散点图中点的颜色。有没有简单的方法可以做到这一点?我找到了一个基于 JQuery 的颜色选择器小部件 ( ht
我有一个 bokeh 应用程序,我可以在其中读取各种文件(6 到 12 个)并生成 DataTable 来比较几个不同的变量。 所以我有一个生成 DataTable 的循环,将它们添加到列表中,然后最
典型的 Bokeh 散点图可能如下所示: 其中 x 和 y 限制均为 [0,1]。如何删除轴上 0 之前并延伸到 1 之外的额外空间?这样最终图的左角为坐标 (0,0),左上角和右下角分别为 (0,1
我正在尝试创建一个 Bokeh 图,它允许我通过单击复选框来切换图中线条的可见性。 我开始尝试对复选框组使用 js 回调,但不幸的是,实际上并没有为复选框组实现 js 回调。 任何人都可以提出另一种方
例如,我有 button = Button(label="0", type="success") 选择此按钮后,我想将标签更改为“1”,反之亦然。有没有简单的方法来实现这一目标? 编辑: RadioB
我团队中的一些人,包括我自己,发现在 Bokeh 散点图中使用 circle 非常令人迷惑。方法,对于图中数据的初始自动缩放拟合,我们可以为我们的数据拨入合理的大小,例如使用 plot.circle(
所以我想做的是一个带有线条和圆圈的简单图形 http://docs.bokeh.org/en/latest/docs/quickstart.html#getting-started 但带有在鼠标悬停在
考虑一个垂直堆积条形图,其中每一列都由多个条形(段)组成。是否可以在每个段上添加工具提示?目前,相同的工具提示附加到组成该列的所有段。 from bokeh.core.properties impor
In[21]: from bokeh.charts import Bar, output_file, show In[22]: dict = {'sec': {u'A': 10, u'B': 20}}
在 Bokeh 中实现树形图需要什么?类似于这个 DS 示例的东西会很好—— http://bl.ocks.org/robschmuecker/7880033 我只是想可视化一个数据结构,所以只需要平
我了解如何指定在 Bokeh 中显示的特定刻度,但我的问题是是否有一种方法可以分配特定的标签来显示与位置。例如 plot.xaxis[0].ticker=FixedTicker(ticks=[0,1]
有什么方法可以为图例添加标题,例如左侧为当前图例,右侧为带有标题的图例。这个特殊的图例被放置在情节之外,所以我不知道是否可以用文本字形来伪造它。 最佳答案 从最新版本的 Bokeh (1.2) 开始,
问题:我的 python 应用程序启动了一个 Bokeh 服务器,如本文所述: http://matthewrocklin.com/blog/work/2017/06/28/simple-bokeh-
我正在使用 Bokeh 图制作折线图,我想标记实际的点(用线穿过它们),而不是仅仅标记线本身。我怎样才能做到这一点?我浏览了文档和用户指南,但似乎找不到答案。谢谢! 最佳答案 假设您正在使用 boke
我将一个 Bokeh Figure 实例作为输入传递给另一个函数,我需要在那里修改它的源代码。 不知道该怎么做! 这就是我创建图形实例的方式: source = ColumnDataSource({'
据我所知,我可以通过设置 responsive=True 来使 Bokeh 图响应 div 的宽度。然而,我感兴趣的是让 Bokeh 图只在一定程度上做出响应。有没有一种方法可以让我设置 Bokeh
我有一个 Bokeh 服务器应用程序。我想在命令行上传递自定义选项: bokeh serve /path/to/script.py --my-option foo 这可能吗? Bokeh 会以某种方式
我有一个图,它使用来自一些原始数据的值(在 0-20 的 x/y 范围内),以及一些导致一些相当大的 x/y 值(例如 -1000 到 1000+)的最小化数据。因此,我所做的绘图需要我手动单击缩放以
在Web应用程序中,我想让用户使用bokeh的漂亮的框/套索选择工具来选择绘制图像中的感兴趣区域。我想接收选定的像素,以便在python中进行进一步的操作。 对于散点图,这类似于gallery,很容易
我是一名优秀的程序员,十分优秀!