Venn3:如何重新定位圆和标签? [英] Venn3: How to reposition circles and labels?

查看:133
本文介绍了Venn3:如何重新定位圆和标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了三通维恩图.我有三个似乎无法解决的问题.

I have made a three way venn diagram. I have three issues with it that I can't seem to solve.

  1. 移动圆形标签(即"Set1","Set2","Set3")的代码是什么,因为现在一个距离圆形太远了.

  1. What is the code to move the circle labels (i.e."Set1","Set2","Set3") because right now one is too far away from the circle.

使圆形等于三个大小/更改圆形大小的代码是什么?

What is the code to make the circles be three equal sizes/change the circle size?

在绘图周围移动圆的代码是什么.现在,set2在set3内(但颜色不同),我希望该图看起来更像是显示维恩图的标准"方式(即3个独立的圆,中间有一些重叠).

What is the code to move the circles around the plot. Right now, set2 is within set3 (but coloured differently), I would like the diagram to look more like the "standard" way of showing a venn diagram (i.e. 3 separate circles with some overlap in the middle).

另一方面,我发现很难找到诸如"set_x","set_alpha"之类的命令;如果有人知道一本可以回答以上问题的手册,我将不胜感激,我似乎找不到我所需要的所有信息.

On another note, I found it difficult to find what the commands such as "set_x", "set_alpha" should be; if anyone knew of a manual that would answer by above questions I would appreciate it, I couldn't seem to find one place with all the information I needed.

import sys
import numpy
import scipy
from matplotlib_venn import venn3,venn3_circles
from matplotlib import pyplot as plt

#Build three lists to make 3 way venn diagram with                                                                                                                             
list_line = lambda x: set([line.strip() for line in open(sys.argv[x])])
set1,set2,set3 = list_line(1),list_line(2),list_line(3)

#Make venn diagram                                                                                                                                                             
vd = venn3([set1,set2,set3],set_labels=("Set1","Set2","Set3"))

#Colours: get the HTML codes from the net                                                                                                                                      
vd.get_patch_by_id("100").set_color("#FF8000")
vd.get_patch_by_id("001").set_color("#5858FA")
vd.get_patch_by_id("011").set_color("#01DF3A")

#Move the numbers in the circles                                                                                                                                               
vd.get_label_by_id("100").set_x(-0.55)
vd.get_label_by_id("011").set_x(0.1)

#Strength of color, 2.0 is very strong.                                                                                                                                        
vd.get_patch_by_id("100").set_alpha(0.8)
vd.get_patch_by_id("001").set_alpha(0.6)
vd.get_patch_by_id("011").set_alpha(0.8)

plt.title("Venn Diagram",fontsize=14)
plt.savefig("output",format="pdf")

推荐答案

移动圆形标签(即"Set1","Set2","Set3")的代码是什么,因为现在一个距离圆形太远了.

What is the code to move the circle labels (i.e."Set1","Set2","Set3") because right now one is too far away from the circle.

类似的东西:

lbl = vd.get_label_by_id("A")
x, y = lbl.get_position()
lbl.set_position((x+0.1, y-0.2))  # Or whatever

"A""B""C"是预定义的标识符,表示这三个集合.

The "A", "B", and "C" are predefined identifiers, denoting the three sets.

使圆形等于三个大小/更改圆形大小的代码是什么?

What is the code to make the circles be three equal sizes/change the circle size?

如果您不希望圆/区域的大小与数据相对应(不一定是个好主意),则可以使用函数venn3_unweighted获得未加权(经典")维恩图:

If you do not want the circle/region sizes to correspond to your data (not necessarily a good idea), you can get an unweighted ("classical") Venn diagram using the function venn3_unweighted:

from matplotlib_venn import venn3_unweighted 
venn3_unweighted(...same parameters you used in venn3...)

您可以通过向venn3_unweighted提供一个subset_areas参数来进一步作弊和调整结果-这是一个七元素向量,用于指定每个区域的所需相对大小.在这种情况下,将以区域区域为subset_areas的方式绘制图表,而数字将根据实际的subsets显示.尝试例如:

You can further cheat and tune the result by providing a subset_areas parameter to venn3_unweighted - this is a seven-element vector specifying the desired relative size of each region. In this case the diagram will be drawn as if the region areas were subset_areas, yet the numbers will be shown from the actual subsets. Try, for example:

venn3_unweighted(...., subset_areas=(10,1,1,1,1,1,1))

在绘图周围移动圆的代码是什么.

What is the code to move the circles around the plot.

移动圆"的需求有些不寻常-通常,您要么希望定位圆,以使其交点大小与您的数据相对应,要么使用默认"定位.函数venn3venn3_unweighted可以满足这两个要求.可以随意移动圈子,但是需要一些较低级别的编码,我对此建议.

The need to "move the circles around" is somewhat unusual - normally you would either want the circles to be positioned so that their intersection sizes correspond to your data, or use the "default" positioning. The functions venn3 and venn3_unweighted cater to those two requirements. Moving circles around arbitrarily is possible, but would require some lower-level coding and I'd advice against that.

我发现很难找到诸如"set_x","set_alpha"之类的命令

I found it difficult to find what the commands such as "set_x", "set_alpha" should be

调用v.get_label_by_id时获得的对象是Matplotlib Text对象.您可以在此处中了解其方法和属性. v.get_patch_by_id返回的对象是PathPatch,请在此处查看并此处以供参考.

The object you get when you call v.get_label_by_id is a Matplotlib Text object. You can read about its methods and properties here. The object returned by v.get_patch_by_id is a PathPatch, look here and here for reference.

这篇关于Venn3:如何重新定位圆和标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆