- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在此example ,他们在单个 go.Scatter
跟踪器中绘制所有内容,然后他们可以使用 selection_fn
获取所选点的信息。
我想对包含 3 个集群的数据集做类似的事情。为了使集群更容易被看到,我对一个类使用一个示踪剂。因此,我尝试修改示例代码以适应我的数据集,如下所示。
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.tools import set_credentials_file
import plotly.offline as py
import pandas as pd
import numpy as np
from ipywidgets import interactive, HBox, VBox
from sklearn.datasets import make_blobs
X, y = make_blobs(30,random_state=101)
py.init_notebook_mode()
f = go.FigureWidget([go.Scatter(y = X[y==0][:,1], x = X[y==0][:,0], mode = 'markers'),
go.Scatter(y = X[y==1][:,1], x = X[y==1][:,0], mode = 'markers'),
go.Scatter(y = X[y==2][:,1], x = X[y==2][:,0], mode = 'markers')])
scatter = f.data[0]
N = len(X)
# Create a table FigureWidget that updates on selection from points in the scatter plot of f
t = go.FigureWidget([go.Table(
header=dict(values=['x','y','class'],
fill = dict(color='#C2D4FF'),
align = ['left'] * 5),
cells=dict(values=[X[:,0], X[:,1], y],
fill = dict(color='#F5F8FF'),
align = ['left'] * 5))])
def selection_fn(trace,points,selector):
print(points.point_inds)
t.data[0].cells.values = [X[points.point_inds,0], X[points.point_inds,1], y[points.point_inds]]
scatter.on_selection(selection_fn)
# Put everything together
VBox((HBox(),f,t))
当从 trace 0
中选择两个数据点时,它确实返回了 2 个信息给我,但这是错误的。
从tracer 1和tracer 2中选择数据点时,它甚至不返回信息
经过简短调试后,我注意到每个示踪剂的索引与完整数据集不匹配。此代码只能从跟踪器 0 返回索引,但是,当它将索引传递给完整数据集时,它会为您提供点的错误匹配信息。从tracer 1和tracer 2中选点时,连索引都不能返回,因此无法提取任何信息。
虽然我明白了这个问题,但我不知道如何修改代码,因为我还是 plotly 的新手。
最佳答案
经过几天的尝试,我想出了一个 hack 来实现它。 (也许有人还能提供更好的方法?)
技巧是为表中的每一列创建 3 个列表,并将所选点的数据追加到列表中,最后更新表。
这是完整的代码。
X, y = make_blobs(30,random_state=101)
py.init_notebook_mode()
f = go.FigureWidget([go.Scatter(y = X[y==0][:,1], x = X[y==0][:,0], text=y[y==0], mode = 'markers', name='class 0'),
go.Scatter(y = X[y==1][:,1], x = X[y==1][:,0], text=y[y==1], mode = 'markers', name='class 1'),
go.Scatter(y = X[y==2][:,1], x = X[y==2][:,0], text=y[y==2], mode = 'markers', name='class 2')])
# Create a table FigureWidget that updates on selection from points in the scatter plot of f
t = go.FigureWidget([go.Table(
header=dict(values=['x','y', 'class'],
fill = dict(color='#C2D4FF'),
align = ['left'] * 5),
cells=dict(values=[X[:,0], X[:,1], y],
fill = dict(color='#F5F8FF'),
align = ['left'] * 5))])
# def data_append(trace,points,selector):
# X1 = []
# X2 = []
# c = []
X1 = []
X2 = []
data_cluster = []
num_called = 0
def selection_fn(trace,points,selector):
global num_called
global X1, X2, data_cluster
if num_called == 3: # number of scatters
num_called = 0
X1 = []
X2 = []
data_cluster = []
X1.extend(trace['x'][points.point_inds])
X2.extend(trace['y'][points.point_inds])
data_cluster.extend(trace['text'][points.point_inds])
t.data[0].cells.values = [X1, X2,data_cluster]
num_called +=1
for scatter in f.data:
scatter.on_selection(selection_fn)
# Put everything together
VBox((HBox(),f,t))
如您所见,表格准确地返回了三个选定数据点的信息。
关于python-3.x - Plotly 无法为多个跟踪器返回选定数据点的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53827778/
我需要跟踪包含数千个 JAR 和 .CLASS 文件的已编译 Java 应用程序,您知道有什么合适的工具可以附加到 JVM 来跟踪函数调用(无需源代码)吗? 最佳答案 是的。 Jprofiler无需源
我想使用深度学习和计算机视觉技术来检测和统计葡萄园中葡萄藤的数量。我正在使用 YOLOv4 对象检测器并在 darknet 上进行训练框架。我已经能够将 SORT 跟踪器集成到我的应用程序中并且运行良
我有一个分为两部分的问题 (1) 如何在用户不移动时暂停事件跟踪,(2) 这可以节省电池生命周期吗? 更多信息。我正在构建一个事件跟踪器,但用于通常涉及大量暂停的事件 - 例如。步行30分钟,在一个位
我需要能够在一个页面上使用多个 Google Analytics(分析)。我怎样才能用异步代码做到这一点? 让跟踪器的工作方式有点像这样(不确定确切的代码): var tracker2 = _gat.
我正在尝试为我的 Android 应用设置 Google Analytics v2。 现在,我正在尝试通过为我的 Activity 和 fragment 设置跟踪器来跟踪不同的屏幕。我有两个所有东西都
您知道有哪些易于使用、简洁的 Python 或 Perl API 可以与 BitTorrent Tracker 进行交互吗?例如,我获取一个 torrent 文件,枚举文件中的所有跟踪器,并向跟踪器询
我一直在尝试为 SEO 编写自己的关键字位置排名扫描器。我找到了一个 PHP 类,它看起来很有用,但我不知道如何让它工作。 我对在 PHP 中使用类/函数还很陌生。 这是我找到的代码: http://
我正在使用 KCF 跟踪算法,我的问题是当目标退出窗口时,跟踪器不会重置并错误地在窗口边缘显示它的矩形。在理想状态下,跟踪器应该在失去目标时删除矩形。 这些是我的代码: int main(int ar
我正在开发一项服务,用于跟踪互联网上的节点。该服务将按日期时间对节点列表进行排序,并且数据库不需要在崩溃中幸存下来(http://wiki.postgresql.org/wiki/What%27s_n
我有一个如下所示的类,当我通过命令行运行它时,我想查看进度状态。类似的东西, 10% completed... 30% completed... 100% completed...Job done!
我已经按照入门指南进行了一些扩展,以了解之前的 Angular 2 版本。我已经更新了我的修订版并相应地更改了所有内容。当我运行 Web 服务器时,我现在收到 traceur 错误 404... 这是
我正在开发一个使用 GPS/GPRS/GSM 的车辆跟踪系统。我目前使用的追踪设备是 GV100,这是一款来自 Quectel ([www.quectel.com][1]) 的 GPS/GPRS/GS
我将 angular2 从 RC2 迁移到 RC4,现在收到以下错误: localhost/:36 Error: Error: XHR error (404 Not Found) loading ht
我目前正在尝试在 nodeJS 中实现一个最小的 torrent 客户端。 我正在阅读此规范:https://wiki.theory.org/index.php/BitTorrentSpecifica
我正在使用 OpenCV 跟踪器在视频中执行人脸跟踪,每隔几帧使用人脸检测器。如果人脸检测器检测到人脸,我想用“检测到的”边界框更新跟踪器。我看到在 C++ 实现中有一个输入 Rect 的选项,但由于
我刚刚安装了 Mantis 错误跟踪器以与 Eclipse IDE 一起使用,并且已经开始发现它的优点。真的很棒。 由于 Eclipse 通过 PHP soap API 与 Mantis 通信,我想知
使用 Google Analytics 的 Javascript 跟踪器,如果有人访问 IP #1 的网站,1 小时后(同一天)使用另一个 IP #2(但在同一浏览器中)访问网站,是否算作 1 或2
很抱歉打扰您,但我已经为此苦苦挣扎了近两周,并进行了很多研究,但没有找到任何解决方案: 我正在尝试运行这个 git 项目 open gps tracker ,在本地它运行完美,但是当我将它部署到开放
我有一个 asp net 项目,我必须在登录后向 Mantis 跟踪器添加一些问题。最好的方法是什么? JS 还是 C#?我找到了几个库(例如 Mantis-JS),但我发现没有文档,我不明白我应该做
我发送了一个抓取数据包,播种器、下载器和盗取器总是返回 0。 这是我的初始连接和抓取代码。 public void scrape() { for (final String infoh
我是一名优秀的程序员,十分优秀!