我有一个包含 10,000 多个 Matplotlib Polygon 对象的列表。每个多边形属于 20 个组中的 1 个。我想通过将每个唯一组映射到唯一颜色来区分多边形属于哪个组。
以下是我发现的一些与我的问题类似的帖子:
这些解决方案只是将随机颜色应用于列表中的每个形状。那不是我要找的。对我来说,属于特定组的每个形状都应该具有相同的颜色。有任何想法吗?
示例代码:
from matplotlib.collections import PatchCollection
from matplotlib.patches import Polygon
from matplotlib import pyplot as plt
patches = []
colors = []
num_polys = 10000
for i in range(num_polys):
patches.append(Polygon(poly_vertices[i], closed=True))
colors.append(poly_colors[i]) # This line is pointless, but I'm letting you know that
# I have a particular color for each polygon
fig, ax = plt.subplots()
p = PatchCollection(patches, alpha=0.25)
ax.add_collection(p) …
Run Code Online (Sandbox Code Playgroud) 我有一个ListView,每行包含两个TextViews和一个EditText。我已经搜索了并且无法找到如何将用户输入到EditText中的文本。我最近的尝试实现了一个TextWatcher。
public void addIngredientToMeal(String ingredientName) {
ingredient_list = (ListView) findViewById(R.id.ingredients_in_meal_listView);
int numberOfIngredients = ingredient_list.getChildCount();
ListAdapter adapter = new ListAdapter();
adapter.name_array = new String[numberOfIngredients+1];
for (int i = 0; i < numberOfIngredients; i++)
adapter.name_array[i] = (String) ingredient_list.getItemAtPosition(i);
adapter.name_array[numberOfIngredients] = ingredientName;
ingredient_list.setItemsCanFocus(true);
ingredient_list.setAdapter(adapter);
}
private class ListAdapter extends BaseAdapter{
public String[] name_array, qty_array;
@Override
public int getCount() {
// TODO Auto-generated method stub
if(name_array != null && name_array.length != 0){
return name_array.length;
}
return 0;
}
@Override
public Object getItem(int position) { …
Run Code Online (Sandbox Code Playgroud) 我的问题与此非常相似.解决方案是,有一个<div>
搞乱的事情.我的没有<divs>
.
我有这个CoffeeScript代码:
data = [0, 1, 2, 3, 4]
d3.select("body")
.data(data)
.enter()
.each((d, i) =>
console.log(i, d)
)
Run Code Online (Sandbox Code Playgroud)
使用所需的控制台输出:
0 0
1 1
2 2
3 3
4 4
Run Code Online (Sandbox Code Playgroud)
在实际的控制台输出为:
1 1
2 2
3 3
4 4
Run Code Online (Sandbox Code Playgroud)
我可以使用以下代码获得所需的输出:
data = [0, 1, 2, 3, 4]
d3.select("body")
.data(data)
.each((d, i) =>
console.log(i, d)
).enter()
.each((d, i) =>
console.log(i, d)
)
Run Code Online (Sandbox Code Playgroud)
但是有两个.each()调用只是感觉不对.
android ×1
colormap ×1
colors ×1
d3.js ×1
each ×1
foreach ×1
javascript ×1
matplotlib ×1
polygon ×1
python ×1