matplotlib 的交互式独立输出
我喜欢 matplotlib 创建的图以及将它们保存为 SVG 的选项很棒,但是...
我希望能够将图形保存为 SVG 并附带 javascript 代码,这会增加一定程度的交互性。例如。对于散点图中的每个数据样本,我想在工具提示中显示一些信息。有办法实现这一点吗?或者你会如何完成这样的事情?
I like the plots matplotlib creates and the option to save them as SVG is great but...
I would like to be able to save the figure as SVG accompanied by javascript code that would add some level of interactivity. Eg. for each data sample in a scatter plot I would like to display some information in a tooltip. Is there a way to achieve this? Or how would you accomplish such a thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Cytoscape 这是相当简单的。
您需要做的是创建两个文件
File1
只需要 3 列
(sourceNode、destinationNode、edgeLabel)
然后您可以从表(文本/MS Excel)中选择文件→导入→网络。
选择源节点、目标节点和交互类型。
请记住更改 VizMapper
File2
节点 中的显示选项边属性文件的格式很简单:节点属性文件的第一行以属性名称开头(注意不能包含空格)。接下来的每一行包含节点的名称,后跟等号和该属性的值。数字和文本字符串是最常见的属性类型。给定属性的所有值必须具有相同的类型。例如:
边属性文件具有大致相同的结构,只不过边的名称是源节点名称,后面是括号中的交互类型,最后是目标节点名称。方向性很重要,因此切换源和目标将引用不同的(或者可能不存在的)边缘。以下是边缘属性文件示例:
由于 Cytoscape 将边缘属性视为有方向的,因此第二个和第三个边缘属性值引用两个不同的边缘(源和目标相反,尽管涉及的节点相同)。
每个属性都存储在单独的文件中。节点和边属性文件使用相同的格式。节点属性文件名通常使用后缀“.noa”,而边属性文件名则使用后缀“.eda”。 Cytoscape 在浏览属性文件时会识别这些后缀。
节点和边属性可以在命令行使用 –n 和 –e 选项或通过文件 → 导入菜单加载。
当使用表达式矩阵加载表达式数据时,除非另有明确指定,否则它会自动加载为节点属性数据。
节点和边属性附加到节点和边,因此独立于网络。给定节点或边的属性将应用于所有加载的网络文件中该节点或边的所有副本,无论首先导入属性文件还是网络文件。
注意:为了在 Cytoscape 2.4 中导入网络属性,请转到文件→导入→表中的属性(文本/MS Excel)...或将它们编码到 XGMML 网络文件中。
第一行之后的每一行都标识一个网络的名称。对象(节点属性文件中的节点或边属性文件中的边)以及属性值的字符串表示形式。分隔符始终是等号;等号前后的空白(空格和/或制表符)将被忽略。
如果属性要映射到任何内容,则对象名称必须是属性浏览器最左列中所示的节点 ID 或边 ID。这些名称必须准确复制,包括大小写,否则它们将不匹配。
阅读此了解更多详细信息
This is fairly straightforward using Cytoscape.
What you need to do is create two files
File1
This just needs to be 3 columns
(sourceNode, destinationNode, edgeLabel)
And then you can go File→Import→Network from Table (Text/MS Excel)..
Select the source node, destination node, and interaction type.
Remember to change the display options in the VizMapper
File2
Node and edge attribute files are simply formatted: a node attribute file begins with the name of the attribute on the first line (note that it cannot contain spaces). Each following line contains the name of the node, followed by an equals sign and the value of that attribute. Numbers and text strings are the most common attribute types. All values for a given attribute must have the same type. For example:
An edge attribute file has much the same structure, except that the name of the edge is the source node name, followed by the interaction type in parentheses, followed by the target node name. Directionality counts, so switching the source and target will refer to a different (or perhaps non-existent) edge. The following is an example edge attributes file:
Since Cytoscape treats edge attributes as directional, the second and third edge attribute values refer to two different edges (source and target are reversed, though the nodes involved are the same).
Each attribute is stored in a separate file. Node and edge attribute files use the same format. Node attribute file names often use the suffix ".noa", while edge attribute file names use the suffix ".eda". Cytoscape recognizes these suffixes when browsing for attribute files.
Node and edge attributes may be loaded at the command line using the –n and –e options or via the File → Import menu.
When expression data is loaded using an expression matrix, it is automatically loaded as node attribute data unless explicitly specified otherwise.
Node and edge attributes are attached to nodes and edges, and so are independent of networks. Attributes for a given node or edge will be applied to all copies of that node or edge in all loaded network files, regardless of whether the attribute file or network file is imported first.
Note: In order to import network attributes in Cytoscape 2.4, please go to File → Import → Attribute from Table (text/MS Excel)... or encode them in an XGMML network file
Every line past the first line identifies the name of an object (a node in a node attribute file or an edge in a edge attribute file) along with the String representation of the attribute value. The delimiter is always an equals sign; whitespace (spaces and/or tabs) before and after the equals sign is ignored.
Object names must be the Node ID or Edge ID as seen in the left-most column of the attribute browser if the attribute is to map to anything. These names must be reproduced exactly, including case, or they will not match.
Read this for more detail
如果您同意使用 html 文件代替 svg;散景可能是您正在寻找的?
请参阅此处 http://docs.bokeh.org/en/latest/docs/ gallery.html
我不相信大多数应用程序都需要服务器,正如文档中所说:“Bokeh 可以使用 file_html() 函数生成独立的 HTML 文档。此函数可以从其自己的通用函数发出 HTML模板,或您提供的模板。这些文件包含内联绘图的数据,并且完全可传输,同时仍然为您的绘图提供交互式工具(平移、缩放等)。
If you would agree to having an html file in stead of an svg; Bokeh is probably what you are looking for?
See here http://docs.bokeh.org/en/latest/docs/gallery.html
I don't believe you need a server for most applications, as they say in the docs: "Bokeh can generate standalone HTML documents using the file_html() function. This function can emit HTML from its own generic template, or a template you provide. These files contain the data for the plot inline and are completely transportable, while still providing interactive tools (pan, zoom, etc.) for your plot. "