我正在尝试创建一个描述预算数据的树形图。
预期:树形图中不应有任何间隙;描述每个节点的所有矩形都应该像乐高积木一样适合 SVG 内。
实际:我的树状图的矩形在我的 SVG 中没有很好地排列;见下图:
目前,我的数据集很浅,大部分是我编写的虚拟数据。CSV 文件的结构为:
这些是代码中的相关步骤:
第 1 步:
加载 CSV 文件后,我使用以下命令将其转换为层次结构d3.stratify():
`let dataStratified = d3
.stratify()
.id(function (d) {
return d.Child;
})
.parentId(function (d) {
return d.Parent;
})(results);`
Run Code Online (Sandbox Code Playgroud)
第 2 步:然后我传递到分层布局d3.treemap():
let myTreemap = (data) =>
d3.treemap().size([width, height]).padding(1).round(true)(
d3
.hierarchy(data)
.sum((d) => d.data["Rs,millions"])
.sort((a, b) => b.data["Rs,millions"] - a.data["Rs,millions"])
);
const root = myTreemap(dataStratified);
Run Code Online (Sandbox Code Playgroud)
第 3 步:使用这个Observable 笔记本作为指导,我继续构建树形图的叶子:
const leaf = g
.selectAll("g.leaf") …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试向我的树状图添加下拉菜单
我正在使用的代码:
import pandas as pd
import plotly.express as px
fig = px.treemap(df,
path=['RuleName','RuleNumber','ParaInvolved',"CreationP","MAjP"],
color='Somme',
hover_data=["RuleDecision","RuleMAJ"],
color_continuous_scale='RdBu')
fig.show()
Run Code Online (Sandbox Code Playgroud)
我面临的问题是,在我的“RuleName”列中,我有 151 个不同的值(但总共 1300 行),这就是为什么我尝试添加一个按钮,允许自己选择要绘制树形图的 RuleName 值。现在我正在使用一种野蛮的方法,即通过每个 RuleName 值过滤我的数据帧,这导致我获得 151 个不同的树形图。我在该网站或任何其他网站上找不到任何解决方案。
感谢您的帮助
我正在用Python开发一个'TreeDict'类.这基本上是一个dict,允许您按排序顺序检索其键值对,就像Java中的Treemap集合类一样.
我已经基于关系数据库中的唯一索引的方式实现了一些功能,例如,允许您检索与一系列键相对应的值,大于,小于或等于按排序顺序的特定值的键,字符串或按排序顺序具有特定前缀的元组等.
不幸的是,我想不出任何需要像这样的课程的现实生活问题.我怀疑我们在Python中没有排序的原因是,在实践中它们并不经常被要求得到它,但我想被证明是错误的.
你能想到'TreeDict'的任何具体应用吗?这个数据结构最能解决的任何现实问题?我只是想知道这是否值得.
我创建了一个DateTime类(包装了GregorianCalendar).我还创建了一个类Event.我想创建一个事件集合,我可以从中检索事件的日期.例如:event是Event类型; date1和date2的类型是DateTime,也是date1.equals(date2); 'events'是我的活动收藏.
event.put(date1, event)
Run Code Online (Sandbox Code Playgroud)
将"事件"添加到集合中,以便我可以检索它
event.get(date2)
Run Code Online (Sandbox Code Playgroud)
我想使用TreeMap来实现这个事件集合,因为我可能想要打印按日期排序的所有事件.
那么如何将DateTime设置为TreeMap的键呢?我应该向DateTime添加什么?还有什么可做的?谢谢.
我有一个巨大的键值对映射,大约10 ^ 7,我必须每秒循环15次以更新其内容是否有任何类或结构提供了良好的复杂性并减少了所需的时间循环?
目前,我正在使用TreeMap,但复杂性仅为包含,放置,获取和删除的log n.循环使用元素是非常复杂的
你知道任何结构,或者你有什么想法可以降低n以下的复杂性吗?
我想基于某些属性值对Java TreeMap进行排序.具体来说,我想TreeMap<Integer, Hashset<Integer>>根据大小来排序Hashset<Integer>.为实现这一目标,我做了以下工作:
比较类:
private static class ValueComparer implements Comparator<Integer> {
private Map<Integer, HashSet<Integer>> map = null;
public ValueComparer (Map<Integer, HashSet<Integer>> map){
super();
this.map = map;
}
@Override
public int compare(Integer o1, Integer o2) {
HashSet<Integer> h1 = map.get(o1);
HashSet<Integer> h2 = map.get(o2);
int compare = h2.size().compareTo(h1.size());
if (compare == 0 && o1!=o2){
return -1;
}
else {
return compare;
}
}
}
Run Code Online (Sandbox Code Playgroud)
一个用法示例:
TreeMap<Integer, HashSet<Integer>> originalMap = new TreeMap<Integer, HashSet<Integer>>();
//load keys and values into …Run Code Online (Sandbox Code Playgroud) 我想知道如果在Java中使用TreeMap上的Iterator会干扰密钥的顺序吗?
我正在尝试从TreeMap中的单个键检索多个值.我们的想法是每个密钥都链接到多个值,并且应该是可搜索的.现在我遇到的麻烦是,当我只能从密钥中获取一个值时.
键是一个String,值是一个名为Song的自定义对象.歌曲包含多个元素.目标是从每首歌曲中逐字逐句提取歌词,并将每个单词用作关键词.然后键将链接到包含键的每个乐曲(值).
我一直在搜索StackOverFlow和网络上的提示,我已经看过一些,但没有任何直接解决我的绊脚石.我看到的一个想法是将值更改为某种数组或列表.当我的大脑恢复精神时,明天我可能会尝试.
无论如何,提前感谢任何提示和建议.是的,这是家庭作业.不,我没有标记是因为我被告知家庭作业标签不再常用.
码:
public class SearchByLyricsWords {
private static Song[] songs;
private static TreeMap<String, Song> lyricsTreeMap = new TreeMap<String, Song>();
private static TreeSet<String> wordsToIgnoreTree = new TreeSet<String>();
private static File wordsToIgnoreInput = new File("ignore.txt");
private static String wordsToIgnoreString;
private static String[] wordsToIgnoreArray;
private Song[] searchResults; // holds the results of the search
private ArrayList<Song> searchList = new ArrayList<Song>();
public SearchByLyricsWords(SongCollection sc) throws FileNotFoundException {
// Create a string out of the ignore.txt file
Scanner scanInputFile = new Scanner(wordsToIgnoreInput); …Run Code Online (Sandbox Code Playgroud) 如何在整数数组中找到第二高的数字?
这是一个很好的实现吗?
有一个更好的方法吗?
public class Find2ndHighest {
public static void main(String[] args) {
int b[] = {2,3,1,0,5};
TreeMap<Integer,Integer> tree = new TreeMap<Integer,Integer>();
for(int i = 0; i<b.length;i++){
tree.put(b[i], 0);
}
System.out.println(tree.floorKey(tree.lastKey()-1));
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个循环方法,迭代TreeMap条目以获取其键的值(我使用自定义比较器根据值对映射进行排序,结果打破了get()方法,但这不是我在这里解决的问题).到目前为止,我已经得到了以下内容,但我没有看到为什么符号'K'和'V'没有被解析 - 即使它们是在传入的TreeMap上声明的.
private V forceGet(TreeMap<K, V> sortedMap, K targetKey) {
for (Map.Entry e : sortedMap.entrySet()) {
K key = (K) e.getKey();
V value = (V) e.getValue();
if (key.equals(targetKey)) {
return value;
}
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
我承认自己不是泛型专家,所以如果这应该是显而易见的,请道歉.