統計学や
事象を
この
Python には、
この
ライブラリを
インストール
pip
で
!pip install matplotlib-venn
matplotlib-venn の 関数に ついて
以下の
* venn2 * venn2_circles
* venn3 * venn3_circles
venn2 を 使う
venn2 を
%matplotlib inline from matplotlib_venn import venn2 from matplotlib import pyplot venn2(subsets=(3, 2, 1)) pyplot.show()
venn2_circles を 使う
venn2_circles は
シンプルな
%matplotlib inline from matplotlib_venn import venn2_circles from matplotlib import pyplot venn2_circles((1, 2, 3)) pyplot.show()
venn3 を 使う
venn3 は
若干subsets
が
%matplotlib inline from matplotlib_venn import venn3 venn3(subsets = (2, 3, 4, 5, 1, 1, 1), set_labels = ('Set1', 'Set2', 'Set3')) pyplot.show()
%matplotlib inline from matplotlib_venn import venn3 venn3(subsets = (1,1,1,2, 3, 4, 5), set_labels = ('Set1', 'Set2', 'Set3')) pyplot.show()
venn3_circles を 使う
venn3_circles も
%matplotlib inline from matplotlib_venn import venn3_circles venn3_circles(subsets = (1,1,1,2, 3, 4, 5)) pyplot.show()
venn2 で 事象を 表す
venn2 を
補事象
以下は、
背景を
%matplotlib inline from matplotlib_venn import venn2 from matplotlib import pyplot v = venn2(subsets=(3, 3, 1)) # ベン図の色を変更する v.get_patch_by_id('10').set_color('white') v.get_patch_by_id('10').set_edgecolor('black') v.get_patch_by_id('11').set_color('white') v.get_patch_by_id('11').set_edgecolor('black') v.get_patch_by_id('01').set_color('white') v.get_patch_by_id('01').set_edgecolor('black') # 背景色を変更する pyplot.gca().set_axis_on() pyplot.gca().set_facecolor('skyblue') pyplot.show()
排反事象
排反事象を
%matplotlib inline from matplotlib_venn import venn2 from matplotlib import pyplot # 重なる部分の領域の割合を0にする v = venn2(subsets=(3, 3, 0)) # ベン図の色を変更する v.get_patch_by_id('10').set_color('skyblue') v.get_patch_by_id('10').set_edgecolor('black') v.get_patch_by_id('01').set_color('skyblue') v.get_patch_by_id('01').set_edgecolor('black') # 背景色を変更する pyplot.gca().set_axis_on() pyplot.gca().set_facecolor('white') pyplot.show()
和事象
和事象を
Aと
%matplotlib inline from matplotlib_venn import venn2 from matplotlib import pyplot # 重なる部分の領域の割合を0にする v = venn2(subsets=(3, 3, 1)) # ベン図の色を変更する v.get_patch_by_id('10').set_color('skyblue') v.get_patch_by_id('10').set_edgecolor('black') v.get_patch_by_id('11').set_color('skyblue') v.get_patch_by_id('11').set_edgecolor('black') v.get_patch_by_id('01').set_color('skyblue') v.get_patch_by_id('01').set_edgecolor('black') # 背景色を変更する pyplot.gca().set_axis_on() pyplot.gca().set_facecolor('white') pyplot.show()
積事象
積事象を
Aと
%matplotlib inline from matplotlib_venn import venn2 from matplotlib import pyplot # 重なる部分の領域の割合を0にする v = venn2(subsets=(3, 3, 1)) # ベン図の色を変更する v.get_patch_by_id('10').set_color('white') v.get_patch_by_id('10').set_edgecolor('black') v.get_patch_by_id('11').set_color('skyblue') v.get_patch_by_id('11').set_edgecolor('black') v.get_patch_by_id('01').set_color('white') v.get_patch_by_id('01').set_edgecolor('black') # 背景色を変更する pyplot.gca().set_axis_on() pyplot.gca().set_facecolor('white') pyplot.show()
差事象(差集合)
A が
%matplotlib inline from matplotlib_venn import venn2 from matplotlib import pyplot # 重なる部分の領域の割合を0にする v = venn2(subsets=(3, 3, 1)) # ベン図の色を変更する v.get_patch_by_id('10').set_color('skyblue') v.get_patch_by_id('10').set_edgecolor('black') v.get_patch_by_id('11').set_color('white') v.get_patch_by_id('11').set_edgecolor('black') v.get_patch_by_id('01').set_color('white') v.get_patch_by_id('01').set_edgecolor('black') # 背景色を変更する pyplot.gca().set_axis_on() pyplot.gca().set_facecolor('white') pyplot.show()
参考
以下、
* 差集合 - Wikipedia * Python Matplotlib Venn diagram - Stack Overflow
* Matplotlib Venn diagram with legend - Stack Overflow * python - Accurate color blending in Matplotlib-Venn - Stack Overflow
* #174 Change background colour of Venn diagram – The Python Graph Gallery
* #172 Custom Venn diagram – The Python Graph Gallery
* Python: Venn Diagram
* 排反事象と
* slide03.pdf
以上です。
コメント