- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
假设我有一个 10x10 矩阵,它由 0 和 1 组成,表示为列表的列表。我如何使用 matplotlib
将这样的矩阵表示为红色和黑色方 block 的网格? (红色代表 1,黑色代表 0)。
我进行了广泛的搜索,但我能找到的最接近的是 Plot a black-and-white binary map in matplotlib
,但颜色是小于 1 的 float 。一旦我在数据中得到 1,情节就会出错。谁能帮忙?或者指出可以帮助我克服这个问题的特定 matplotlib 文档?
最佳答案
您需要所谓的 ListedColorMap
:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
# random data
x = np.random.random_integers(0, 1, (10, 10))
fig, ax = plt.subplots()
# define the colors
cmap = mpl.colors.ListedColormap(['r', 'k'])
# create a normalize object the describes the limits of
# each color
bounds = [0., 0.5, 1.]
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
# plot it
ax.imshow(x, interpolation='none', cmap=cmap, norm=norm)
关于python - matplotlib:二进制热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28517400/
我想要类似于以下伪代码的东西: while input is not None and timer = 5: print "took too long" else: print inp
如何将 MainEngine Observable 转换为 Cold?来自这个例子: public IObservable MainEngine { get
自从手表被发明以来,表盘的方圆之争就始终没有停下来过,在漫长的岁月中,无论是方形还是圆形表盘,人们都为其寻找到足够多的设计元素,让其肆意成长,这种生机与活力后来也延续到了智能手表上,在2014年,这
我正在学习 CUDA,试图解决一些标准问题。例如,我正在使用以下代码求解二维扩散方程。但我的结果与标准结果不同,我无法弄清楚。 //kernel definition __global__ void
我的 Web 应用程序使用 native dll 来实现其部分功能(其位置在 PATH 中提供)。一切正常,直到我对 WAR 进行更改并且 JBoss 热部署此 WAR。此时dll已经找不到了,需要手
我看到这个问题here 。这是关于实现每个发出的项目的延迟。这是根据accepted answer如何实现的: Observable.zip(Observable.range(1, 5) .g
我最近一直在进行冷迁移...这意味着我无法在进行迁移时从应用程序级别读取/写入数据库(维护页面)。 这样就不会因为更改结构而发生错误,而且如果负载很大,我也不希望 mysql 在迁移过程中崩溃。 我的
我是一名优秀的程序员,十分优秀!