- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 this post 中的示例树状图在我的工作中,但还想跟踪哪行/列来自哪条数据。
我已将数据名称记录编辑为 names
,如下所示,并希望打印距离矩阵可视化底部和右侧的名称。我尝试在对dendrogram
的调用中添加labels=names
,但这没有帮助。
有人知道如何为此添加标签吗?
import scipy
import pylab
import scipy.cluster.hierarchy as sch
# Generate random features and distance matrix.
x = scipy.rand(40)
D = scipy.zeros([40,40])
for i in range(40):
for j in range(40):
D[i,j] = abs(x[i] - x[j])
### new code
names = [ ]
for i in range(40):
names.append( 'str%i'%( i ) )
print names[-1]
### end new code
# Compute and plot first dendrogram.
fig = pylab.figure(figsize=(8,8))
ax1 = fig.add_axes([0.09,0.1,0.2,0.6])
Y = sch.linkage(D, method='centroid')
Z1 = sch.dendrogram(Y, orientation='right')
ax1.set_xticks([])
ax1.set_yticks([])
# Compute and plot second dendrogram.
ax2 = fig.add_axes([0.3,0.71,0.6,0.2])
Y = sch.linkage(D, method='single')
Z2 = sch.dendrogram(Y)
ax2.set_xticks([])
ax2.set_yticks([])
# Plot distance matrix.
axmatrix = fig.add_axes([0.3,0.1,0.6,0.6])
idx1 = Z1['leaves']
idx2 = Z2['leaves']
D = D[idx1,:]
D = D[:,idx2]
im = axmatrix.matshow(D, aspect='auto', origin='lower', cmap=pylab.cm.YlGnBu)
axmatrix.set_xticks([])
axmatrix.set_yticks([])
# Plot colorbar.
#axcolor = fig.add_axes([0.91,0.1,0.02,0.6])
#pylab.colorbar(im, cax=axcolor)
fig.show()
fig.savefig('dendrogram.png')
最佳答案
python 包 heatmapcluster
(可用 on PyPI )我写的接受(实际上,需要)标签。
这是使用 heatmapcluster
的脚本的简化版本:
import numpy as np
import matplotlib.pyplot as plt
from heatmapcluster import heatmapcluster
# Generate random features and distance matrix.
x = np.random.rand(40)
D = np.abs(np.subtract.outer(x, x))
names = ['str%i' % i for i in range(len(x))]
h = heatmapcluster(D, names, names,
num_row_clusters=3, num_col_clusters=3,
label_fontsize=8,
xlabel_rotation=-75,
cmap=plt.cm.coolwarm,
show_colorbar=True,
top_dendrogram=True)
plt.show()
(请注意,对于像 D
这样的对称数组,对两个轴进行聚类实际上没有意义。通过对称性,它们将生成相同的树状图。)
关于python - 带有名称的 Scipy 树形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37999852/
我在 d3 (v5) 中制作了一个可折叠的树形图,可以在此处找到其简化版本:https://jsfiddle.net/philipnye/cwj9nkhr/ . 每个节点都有一个标签,但标签只显示在有
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 2 年前。 Improve this qu
我正在尝试为 ZingCharts 动态创建此数据数组,但被难住了。 基本上,我需要制作这个结构: var series = [{ text: "Democratic", style: {
我正在尝试为我的树状图(内存)使用 firstKey() 方法。我的代码如下所示: import java.util.*; //Code in the middle. System.out.print
我正在尝试复制以下 D3 可缩放树形图,以便更好地了解 D3 的工作原理: https://secure.polisci.ohio-state.edu/faq/d3/zoomabletreemap.h
我正在使用 this post 中的示例树状图在我的工作中,但还想跟踪哪行/列来自哪条数据。 我已将数据名称记录编辑为 names ,如下所示,并希望打印距离矩阵可视化底部和右侧的名称。我尝试在对de
我使用 d3.js 组合了以下树状图。就选民投票率而言,它是前 20 名的州。 Link 我不确定如何将“值”添加到悬停中。理想情况下,它应该显示每个状态的唯一值。我可以为一个人(例如加利福尼亚州)做
我正在尝试在数据更新时动态更新我的 d3 树形图。我有两个函数,一个是我最初调用的用于构建树形图的函数,另一个是用于重绘树形图的函数。当我重新绘制树状图时,我在树状图顶部看到一个细黑条,并且我正在绘制
我正在尝试放置 2 个 d3.js 树形图,如此处所示 http://bl.ocks.org/1249394在一页上。两棵树都将加载来自 Javascript 对象的不同数据。第一个将出现在: 第二
我使用从 TreeMap 派生的类和我自己的比较器作为 LinkedHashMap 中的键。使用这个构造,我发现了一些我无法解释自己的奇怪行为。也许你们中的一个人可以提供帮助。我尝试用原语重现我的问题
如何在使用 d3.js 单击时从 treemap 获取矩形的值?HTML正文如下, "ABC" "My rectangle tag here"
我有一个树形图,我试图在这里进行调整,但问题是,当我单击折叠的节点时,它会自动伸展树(Splay Tree)中的所有根节点,而不是仅展开直接子节点。这是一把 fiddle 。我该如何解决这个问题? h
尝试转换 Mike Bostock 的 zoomable treemap到 React 组件中。已经完成了一部分,但不确定当数据取决于渲染的 DOM(即宽度)时在组件之间传递数据的最佳方式。 遇到了本
我正在尝试使用 Javascript 对象创建一个小树形图。我正在使用 D3 并尝试说明元素(键、id)的嵌套结构而不是它们的值。 我的JSFiddle var d1 = { "time_
我想使用 Highcharts 创建一个有 4 个级别的树形图。构建 3 个级别的树形图效果很好。这是 fiddle :https://jsfiddle.net/khsemucx/2/和截图: var
My treemap body { font: 10px sans-serif; position: relative; } .node { box-sizing: borde
当我收到新数据时更新并重新渲染的 js 树形图。我建立了一个包含 50 个元素的数据集,效果很好。但是,我尝试在更大的数据集(包含 10,000 个元素)上运行相同的代码。而且它似乎无法渲染图形,有人
这是 JavaScript 代码: d3.json("city.json", function (error, root) { var nodes = cluster.nodes(ro
我是一名优秀的程序员,十分优秀!