Python 中的拱形关系信息图
这是一个非常具体的信息图表挑战,尽管基本问题是如何使用 matplotlib、cario 或其他 python 库在单词之间构建拱形结构。
给定以下数据结构。
我,你,7 | 我,苹果,9 | 苹果,你,1 | bike、me、5 个
名称将水平显示,关系最密切的名称比其他名称大,然后名称之间会出现加权拱形。 10 权重拱门的厚度是 5 权重拱门的两倍。
灵感来源于:相似的多样性。 http://similardiversity.net/
让挑战开始吧!
This is a very specific inforgraphic challange altough the fundemental question is how do you build archs between words using matplotlib, cario or an other python libary.
Given a the following data structure.
me, you, 7 |
me, apple, 9 |
apple, you, 1 |
bike, me, 5
Names would be displayed horizontally the names with the most relationships larger than the others and then there would be weighted archs between the names. A 10 weighted arch would be twice as thick as a 5 weighted arch.
Inspiration comes from: similar diverstiy. http://similardiversity.net/
Let the challange commence!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
matplotlib 在这里不是正确的库,因为它不是通用图形库。您在这里需要的是类似 Cairo 的东西,或者更简单,您可以使用图形功能来完成任何 GUI 工具包,例如 PyQt。另一种可行的方法是 PyGame,它也具有良好的绘图功能。
如果您需要示例,请参阅此 Cairo 示例 页面,第一个示例 - arc。您只需编写文本单词,然后使用弧线代码在它们之间形成任意宽度和颜色的弧线。
matplotlib
isn't the right library here, since it's not a general purpose graphics library. What you need here is either something like Cairo, or much simpler, you can do with the graphics capabilities of any GUI toolkit, such as PyQt. Another feasible approach is PyGame, which has good drawing capabilities as well.If you want an example, see this Cairo samples page, the first sample - arc. You just write the text words and then use the arc code for an arc of any width and color between them.
有几个库,至少其中一个依赖于 Matplotlib,可以满足您的需求。我建议使用 Networkx (www.networkx.lanl.gov) 来构建图形结构,然后您可以使用它来调用相关的 Matplotlib 方法来进行绘图。 Networkx 和 Matplotlib 可以很好地协同工作。
正如您所看到的,您可以通过应用一个因子来改变任何“边缘”方法的“权重”参数来缩放边缘,就像我对节点缩放所做的那样。
我还推荐 pygraphviz (显然使用 graphviz 作为其后端)。它与 Networkworkx 非常相似(同一首席开发人员)。
There are several libraries, at least one of which relies on Matplotlib, that will do what you want. I recommend Networkx (www.networkx.lanl.gov) to build your graph structure, and which you can then use to call the relevant Matplotlib methods to plot. Networkx and Matplotlib work very well together.
As you can see, you could scale the edges by applying a factor to vary the 'weight' parameter to any of the 'edge' methods, just the same way as i did it for node scaling.
I would also recommend pygraphviz (obviously using graphviz as its backend). It is very similar to Netwworkx (same lead developer).
我真的不明白困难或挑战在哪里。您所需要的只是一个可以绘制文本和半圆的图形库,这几乎可以用于所有事情。不需要贝塞尔曲线。例如,您可以简单地创建一个 SVG 文件(然后您甚至不需要任何库,并且可以很好地将其嵌入到网页中并使用一些 JavaScript 使其具有交互性)。
实际绘图很简单:圆心位于两个单词之间的中间,半径是它们之间距离的一半。然后,您可以调整笔划以反映其他数量。
I don't really see where the difficulty or challenge is. All you need is a graphics library that can draw text and half circles, which is possible in pretty much everything. There is no need for Bezier curves. For example you could simply create an SVG file (then you don't even need any library and can nicely embed this in a webpage and use some JavaScript to make it interactive).
The actual plotting is simple: the center of a circle is in the middle between the two words, the radius is half the distance between them. You can then adjust the stroke to reflect other quantities.