森林和漏斗图库

机器算法验证 数据可视化 漏斗图 爪哇
2022-04-01 02:29:53

谁能推荐我一个开源图形库来创建森林和漏斗图?

我的目标是在 Java 桌面应用程序上使用它。

3个回答

好吧,我使用graphviz,它具有 Java 绑定(Grappa)。

尽管点语言(graphviz 的语法)很简单,但我更喜欢通过优秀且生产稳定的 python 绑定pygraphviznetworkx将 graphviz 用作库。

这是使用这些工具的简单“漏斗图”的代码;它不是最精细的图,但它是完整的——它初始化图对象,创建所有必要的组件,设置它们的样式,渲染图,并将其写入文件。

import networkx as NX
import pygraphviz as PV

G = PV.AGraph(strict=False, directed=True)     # initialize graph object

# create graph components:
node_list = ["Step1", "Step2", "Step3", "Step4"]
edge_list = [("Step1, Step2"), ("Step2", "Step3"), ("Step3", "Step4")]
G.add_nodes_from(node_list)
G.add_edge("Step1", "Step2")
G.add_edge("Step2", "Step3")
G.add_edge("Step3", "Step4")

# style them:
nak = "fontname fontsize fontcolor shape style fill color size".split()
nav = "Arial 11 white invtrapezium filled cornflowerblue cornflowerblue 1.4".split()
nas = dict(zip(nak, nav))
for k, v in nas.iteritems() :
    G.node_attr[k] = v

eak = "fontname fontsize fontcolor dir arrowhead arrowsize arrowtail".split()
eav = "Arial 10 red4 forward normal 0.8 inv".split()
eas = dict(zip(eak, eav))
for k, v in eas.iteritems() :
    G.edge_attr[k] = v

n1 = G.get_node("Step1")
n1.attr['fontsize'] = '11'
n1.attr['fontcolor'] = 'red4'
n1.attr['label'] = '1411'
n1.attr['shape'] = 'rectangle'
n1.attr['width'] = '1.4'
n1.attr['height'] = '0.05'
n1.attr['color'] = 'firebrick4'
n4 = G.get_node("Step4")
n4.attr['shape'] = 'rectangle'

# it's simple to scale graph features to indicate 'flow' conditions, e.g., scale 
# each container size based on how many items each holds in a given time snapshot:
# (instead of setting node attribute ('width') to a static quantity, you would
# just bind 'n1.attr['width']' to a variable such as 'total_from_container_1'

n1 = G.get_node("Step2")
n1.attr['width'] = '2.4'

# likewise, you can do the same with edgewidth (i.e., make the arrow thicker
# to indicate higher 'flow rate')

e1 = G.get_edge("Step1", "Step2")
e1.attr['label'] = '  1411'
e1.attr['penwidth'] = 2.6

# and you can easily add labels to the nodes and edges to indicate e.g., quantities: 
e1 = G.get_edge("Step2", "Step3")
e1.attr['label'] = '  392'

G.write("conv_fnl.dot")      # save the dot file
G.draw("conv_fnl.png")       # save the rendered diagram

替代文字 http://a.imageshack.us/img148/390/convfunnel.png

R 中的rmeta 包可以生成森林图和漏斗图。

http://cran.r-project.org/web/packages/rmeta/index.html

除了 rmeta 包之外,R 中还有 meta 包,它可以生成出版质量图。