最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Matlab實(shí)現(xiàn)繪制高階版本韋恩圖(upset圖)

 更新時(shí)間:2023年01月28日 11:40:41   作者:slandarer  
韋恩圖隨著階數(shù)升高會(huì)越來越復(fù)雜,當(dāng)階數(shù)達(dá)到7或者以上時(shí)幾乎沒辦法繪制,但是使用upset圖卻可以比較輕易的繪制。本文就來用Matlab實(shí)現(xiàn)繪制upset圖,需要的可以參考一下

韋恩圖隨著階數(shù)升高會(huì)越來越復(fù)雜,當(dāng)階數(shù)達(dá)到7或者以上時(shí)幾乎沒辦法繪制:

但是使用upset圖卻可以比較輕易的繪制:

兩種類型圖的對應(yīng)關(guān)系:

這期便教大家如何繪制這樣的upset圖:

教程部分

數(shù)據(jù)準(zhǔn)備

數(shù)據(jù)需要的是0,1矩陣,例如隨機(jī)生成數(shù)據(jù):

setName={'RB1','PIK3R1','EGFR','TP53','PTEN'};
Data=rand([200,5])>.85;

每一行代表一個(gè)對象,第一行是1,0,0,1,0說明它既屬于第一類也屬于第四類。

配色

配色可以是rgb數(shù)值,也可以是多行顏色,也可以用matlab自帶的colormap數(shù)據(jù):

% 設(shè)置兩個(gè)柱狀圖及關(guān)系連線的顏色
bar1Color=[61,58,61]./255;
bar2Color=[61,58,61]./255;
lineColor=[61,58,61]./255;

在隨后的部分會(huì)更詳細(xì)的講解顏色設(shè)置。

主要運(yùn)算

接下來幾行就是數(shù)據(jù)統(tǒng)計(jì)的詳細(xì)代碼,小技巧有點(diǎn)多,這部分技巧在韋恩圖繪制那篇和數(shù)據(jù)統(tǒng)計(jì)那篇也寫到過,可以去瞅瞅,這里不詳細(xì)展開:

% 進(jìn)行組合統(tǒng)計(jì)(一頓花里胡哨的操作)
pBool=abs(dec2bin((1:(2^size(Data,2)-1))'))-48;
[pPos,~]=find(((pBool*(1-Data'))|((1-pBool)*Data'))==0);
sPPos=sort(pPos);dPPos=find([diff(sPPos);1]);
pType=sPPos(dPPos);pCount=diff([0;dPPos]);
[pCount,pInd]=sort(pCount,'descend');
pType=pType(pInd);
sCount=sum(Data,1);
[sCount,sInd]=sort(sCount,'descend');
sType=1:size(Data,2);
sType=sType(sInd);

創(chuàng)建布局并修飾

若集合名稱為中文亂碼,請將字體改為宋體,若后面繪圖部分顯示不全請調(diào)整各個(gè)axes的XLim及YLim屬性。

% 構(gòu)造figure及axes
fig=figure('Units','normalized','Position',[.3,.2,.5,.63],'Color',[1,1,1]);
axI=axes('Parent',fig);hold on;
set(axI,'Position',[.33,.35,.655,.61],'LineWidth',1.2,'Box','off','TickDir','out',...
    'FontName','Times New Roman','FontSize',12,'XTick',[],'XLim',[0,length(pType)+1])
axI.YLabel.String='Intersection Size';
axI.YLabel.FontSize=16;
%
axS=axes('Parent',fig);hold on;
set(axS,'Position',[.01,.08,.245,.26],'LineWidth',1.2,'Box','off','TickDir','out',...
    'FontName','Times New Roman','FontSize',12,'YColor','none','YLim',[.5,size(Data,2)+.5],...
    'YAxisLocation','right','XDir','reverse','YTick',[])
axS.XLabel.String='Set Size';
axS.XLabel.FontSize=16;
%
axL=axes('Parent',fig);hold on;
set(axL,'Position',[.33,.08,.655,.26],'YColor','none','YLim',[.5,size(Data,2)+.5],'XColor','none','XLim',axI.XLim)

圖像繪制

% 相交關(guān)系統(tǒng)計(jì)圖 -----------------------------------------------------------
barHdlI=bar(axI,pCount);
barHdlI.EdgeColor='none';
if size(bar1Color,1)==1
    bar1Color=[bar1Color;bar1Color];
end
tx=linspace(0,1,size(bar1Color,1))';
ty1=bar1Color(:,1);ty2=bar1Color(:,2);ty3=bar1Color(:,3);
tX=linspace(0,1,length(pType))';
bar1Color=[interp1(tx,ty1,tX,'pchip'),interp1(tx,ty2,tX,'pchip'),interp1(tx,ty3,tX,'pchip')];
barHdlI.FaceColor='flat';
for i=1:length(pType)
    barHdlI.CData(i,:)=bar1Color(i,:);
end
text(axI,1:length(pType),pCount,string(pCount),'HorizontalAlignment','center',...
    'VerticalAlignment','bottom','FontName','Times New Roman','FontSize',12,'Color',[61,58,61]./255)
% 集合統(tǒng)計(jì)圖 ---------------------------------------------------------------
barHdlS=barh(axS,sCount,'BarWidth',.6);
barHdlS.EdgeColor='none';
barHdlS.BaseLine.Color='none';
for i=1:size(Data,2)
    annotation('textbox',[(axS.Position(1)+axS.Position(3)+axI.Position(1))/2-.02,...
        axS.Position(2)+axS.Position(4)./size(Data,2).*(i-.5)-.02,.04,.04],...
        'String',setName{sInd(i)},'HorizontalAlignment','center','VerticalAlignment','middle',...
        'FitBoxToText','on','LineStyle','none','FontName','Times New Roman','FontSize',13)
end
if size(bar2Color,1)==1
    bar2Color=[bar2Color;bar2Color];
end
tx=linspace(0,1,size(bar2Color,1))';
ty1=bar2Color(:,1);ty2=bar2Color(:,2);ty3=bar2Color(:,3);
tX=linspace(0,1,size(Data,2))';
bar2Color=[interp1(tx,ty1,tX,'pchip'),interp1(tx,ty2,tX,'pchip'),interp1(tx,ty3,tX,'pchip')];
barHdlS.FaceColor='flat';
sstr{size(Data,2)}='';
for i=1:size(Data,2)
    barHdlS.CData(i,:)=bar2Color(i,:);
    sstr{i}=[num2str(sCount(i)),' '];
end
text(axS,sCount,1:size(Data,2),sstr,'HorizontalAlignment','right',...
    'VerticalAlignment','middle','FontName','Times New Roman','FontSize',12,'Color',[61,58,61]./255)
% 繪制關(guān)系連線 ---------------------------------------------------------------
patchColor=[248,246,249;255,254,255]./255;
for i=1:size(Data,2)
    fill(axL,axI.XLim([1,2,2,1]),[-.5,-.5,.5,.5]+i,patchColor(mod(i+1,2)+1,:),'EdgeColor','none')
end
[tX,tY]=meshgrid(1:length(pType),1:size(Data,2));
plot(axL,tX(:),tY(:),'o','Color',[233,233,233]./255,...
    'MarkerFaceColor',[233,233,233]./255,'MarkerSize',10);
for i=1:length(pType)
    tY=find(pBool(pType(i),:));
    oY=zeros(size(tY));
    for j=1:length(tY)
        oY(j)=find(sType==tY(j));
    end
    tX=i.*ones(size(tY));
    plot(axL,tX(:),oY(:),'-o','Color',lineColor(1,:),'MarkerEdgeColor','none',...
        'MarkerFaceColor',lineColor(1,:),'MarkerSize',10,'LineWidth',2);
end

若是前面配色部分使用的是:

bar1Color=[61,58,61]./255;
bar2Color=[61,58,61]./255;
lineColor=[61,58,61]./255;

修改其中一個(gè)柱狀圖顏色,另一個(gè)用多行顏色矩陣:

bar1Color=[66,182,195]./255;
bar2Color=[253,255,228;
          164,218,183;
          68,181,197;
          44,126,185;
          35,51,154]./255;
lineColor=[61,58,61]./255;

一個(gè)用多行顏色矩陣,一個(gè)使用自帶colormap數(shù)據(jù):

bar1Color=[0,0,245;245,0,0]./255;
bar2Color=cool;
lineColor=[61,58,61]./255;

完整代碼

% upSetMDemo
% @author : slandarer
% Zhaoxu Liu / slandarer (2023). upset plot 
% (https://www.mathworks.com/matlabcentral/fileexchange/123695-upset-plot), 
% MATLAB Central File Exchange. 檢索來源 2023/1/22.

rng(2)
clc;clear;
setName={'RB1','PIK3R1','EGFR','TP53','PTEN'};
Data=rand([200,5])>.85;
% setName={'A','B','C','D','E','F','G'};
% Data=rand([200,7])>.9;

% 設(shè)置兩個(gè)柱狀圖及關(guān)系連線的顏色
bar1Color=[61,58,61]./255;
bar2Color=[61,58,61]./255;
lineColor=[61,58,61]./255;

% bar1Color=[66,182,195]./255;
% bar2Color=[253,255,228;
%           164,218,183;
%           68,181,197;
%           44,126,185;
%           35,51,154]./255;
% lineColor=[61,58,61]./255;

bar1Color=[0,0,245;245,0,0]./255;
bar2Color=cool;
lineColor=[61,58,61]./255;

%% =========================================================================
% 進(jìn)行組合統(tǒng)計(jì)(一頓花里胡哨的操作)
pBool=abs(dec2bin((1:(2^size(Data,2)-1))'))-48;
[pPos,~]=find(((pBool*(1-Data'))|((1-pBool)*Data'))==0);
sPPos=sort(pPos);dPPos=find([diff(sPPos);1]);
pType=sPPos(dPPos);pCount=diff([0;dPPos]);
[pCount,pInd]=sort(pCount,'descend');
pType=pType(pInd);
sCount=sum(Data,1);
[sCount,sInd]=sort(sCount,'descend');
sType=1:size(Data,2);
sType=sType(sInd);
%% ========================================================================
% 構(gòu)造figure及axes
fig=figure('Units','normalized','Position',[.3,.2,.5,.63],'Color',[1,1,1]);
axI=axes('Parent',fig);hold on;
set(axI,'Position',[.33,.35,.655,.61],'LineWidth',1.2,'Box','off','TickDir','out',...
    'FontName','Times New Roman','FontSize',12,'XTick',[],'XLim',[0,length(pType)+1])
axI.YLabel.String='Intersection Size';
axI.YLabel.FontSize=16;
%
axS=axes('Parent',fig);hold on;
set(axS,'Position',[.01,.08,.245,.26],'LineWidth',1.2,'Box','off','TickDir','out',...
    'FontName','Times New Roman','FontSize',12,'YColor','none','YLim',[.5,size(Data,2)+.5],...
    'YAxisLocation','right','XDir','reverse','YTick',[])
axS.XLabel.String='Set Size';
axS.XLabel.FontSize=16;
%
axL=axes('Parent',fig);hold on;
set(axL,'Position',[.33,.08,.655,.26],'YColor','none','YLim',[.5,size(Data,2)+.5],'XColor','none','XLim',axI.XLim)
%% ========================================================================
% 相交關(guān)系統(tǒng)計(jì)圖 -----------------------------------------------------------
barHdlI=bar(axI,pCount);
barHdlI.EdgeColor='none';
if size(bar1Color,1)==1
    bar1Color=[bar1Color;bar1Color];
end
tx=linspace(0,1,size(bar1Color,1))';
ty1=bar1Color(:,1);ty2=bar1Color(:,2);ty3=bar1Color(:,3);
tX=linspace(0,1,length(pType))';
bar1Color=[interp1(tx,ty1,tX,'pchip'),interp1(tx,ty2,tX,'pchip'),interp1(tx,ty3,tX,'pchip')];
barHdlI.FaceColor='flat';
for i=1:length(pType)
    barHdlI.CData(i,:)=bar1Color(i,:);
end
text(axI,1:length(pType),pCount,string(pCount),'HorizontalAlignment','center',...
    'VerticalAlignment','bottom','FontName','Times New Roman','FontSize',12,'Color',[61,58,61]./255)
% 集合統(tǒng)計(jì)圖 ---------------------------------------------------------------
barHdlS=barh(axS,sCount,'BarWidth',.6);
barHdlS.EdgeColor='none';
barHdlS.BaseLine.Color='none';
for i=1:size(Data,2)
    annotation('textbox',[(axS.Position(1)+axS.Position(3)+axI.Position(1))/2-.02,...
        axS.Position(2)+axS.Position(4)./size(Data,2).*(i-.5)-.02,.04,.04],...
        'String',setName{sInd(i)},'HorizontalAlignment','center','VerticalAlignment','middle',...
        'FitBoxToText','on','LineStyle','none','FontName','Times New Roman','FontSize',13)
end
if size(bar2Color,1)==1
    bar2Color=[bar2Color;bar2Color];
end
tx=linspace(0,1,size(bar2Color,1))';
ty1=bar2Color(:,1);ty2=bar2Color(:,2);ty3=bar2Color(:,3);
tX=linspace(0,1,size(Data,2))';
bar2Color=[interp1(tx,ty1,tX,'pchip'),interp1(tx,ty2,tX,'pchip'),interp1(tx,ty3,tX,'pchip')];
barHdlS.FaceColor='flat';
sstr{size(Data,2)}='';
for i=1:size(Data,2)
    barHdlS.CData(i,:)=bar2Color(i,:);
    sstr{i}=[num2str(sCount(i)),' '];
end
text(axS,sCount,1:size(Data,2),sstr,'HorizontalAlignment','right',...
    'VerticalAlignment','middle','FontName','Times New Roman','FontSize',12,'Color',[61,58,61]./255)
% 繪制關(guān)系連線 ---------------------------------------------------------------
patchColor=[248,246,249;255,254,255]./255;
for i=1:size(Data,2)
    fill(axL,axI.XLim([1,2,2,1]),[-.5,-.5,.5,.5]+i,patchColor(mod(i+1,2)+1,:),'EdgeColor','none')
end
[tX,tY]=meshgrid(1:length(pType),1:size(Data,2));
plot(axL,tX(:),tY(:),'o','Color',[233,233,233]./255,...
    'MarkerFaceColor',[233,233,233]./255,'MarkerSize',10);
for i=1:length(pType)
    tY=find(pBool(pType(i),:));
    oY=zeros(size(tY));
    for j=1:length(tY)
        oY(j)=find(sType==tY(j));
    end
    tX=i.*ones(size(tY));
    plot(axL,tX(:),oY(:),'-o','Color',lineColor(1,:),'MarkerEdgeColor','none',...
        'MarkerFaceColor',lineColor(1,:),'MarkerSize',10,'LineWidth',2);
end
% Zhaoxu Liu / slandarer (2023). upset plot 
% (https://www.mathworks.com/matlabcentral/fileexchange/123695-upset-plot), 
% MATLAB Central File Exchange. 檢索來源 2023/1/22.

對于本例子的解讀:

以上就是Matlab實(shí)現(xiàn)繪制高階版本韋恩圖(upset圖)的詳細(xì)內(nèi)容,更多關(guān)于Matlab繪制韋恩圖的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • C/C++語言宏定義使用實(shí)例詳解

    C/C++語言宏定義使用實(shí)例詳解

    這篇文章主要介紹了 C/C++語言宏定義使用實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • StretchBlt函數(shù)和BitBlt函數(shù)用法案例詳解

    StretchBlt函數(shù)和BitBlt函數(shù)用法案例詳解

    這篇文章主要介紹了StretchBlt函數(shù)和BitBlt函數(shù)用法案例詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • C++ getline函數(shù)用法詳解

    C++ getline函數(shù)用法詳解

    這篇文章主要介紹了C++ getline函數(shù)用法詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • Qt?QTableWidget基本操作及使用

    Qt?QTableWidget基本操作及使用

    QTableWidget?是?Qt?中的表格組件類。很類似于VC、C#中的DataGrid,本文就詳細(xì)來介紹一下Qt?QTableWidget基本操作及使用,感興趣的可以了解一下
    2021-11-11
  • C++11中內(nèi)聯(lián)函數(shù)(inline)用法實(shí)例

    C++11中內(nèi)聯(lián)函數(shù)(inline)用法實(shí)例

    內(nèi)聯(lián)函數(shù)本質(zhì)還是一個(gè)函數(shù),但在聲明的時(shí)候,函數(shù)體要和聲明結(jié)合在一起,否則編譯器將它作為普通函數(shù)來對待,下面這篇文章主要給大家介紹了關(guān)于C++11中內(nèi)聯(lián)函數(shù)(inline)的相關(guān)資料,需要的朋友可以參考下
    2022-10-10
  • C++多線程之互斥鎖與死鎖

    C++多線程之互斥鎖與死鎖

    互斥鎖和死鎖是C++多線程中常見的情況,這篇文章就帶大家進(jìn)一步了解多線程中的互斥鎖與死鎖這兩個(gè)概念,文中的示例代碼介紹得很詳細(xì),快來跟隨小編一起學(xué)習(xí)吧
    2021-12-12
  • QT編寫簡單登錄界面的實(shí)現(xiàn)示例

    QT編寫簡單登錄界面的實(shí)現(xiàn)示例

    登陸界面是網(wǎng)頁中常見的界面,本文主要介紹了QT編寫簡單登錄界面的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-02-02
  • C語言函數(shù)指針詳解

    C語言函數(shù)指針詳解

    本文主要介紹 C語言函數(shù)指針的知識,這里整理了詳細(xì)的資料及示例代碼以便大家學(xué)習(xí)參考,有需要學(xué)習(xí)此部分知識的朋友可以參考下
    2021-09-09
  • C++實(shí)現(xiàn)通訊錄功能

    C++實(shí)現(xiàn)通訊錄功能

    這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)通訊錄功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • C語言利用棧實(shí)現(xiàn)對后綴表達(dá)式的求解

    C語言利用棧實(shí)現(xiàn)對后綴表達(dá)式的求解

    這篇文章主要為大家詳細(xì)介紹了C語言利用棧實(shí)現(xiàn)對后綴表達(dá)式的求解,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-04-04

最新評論

玉田县| 新巴尔虎右旗| 丹巴县| 香格里拉县| 济南市| 凤庆县| 乌拉特中旗| 邛崃市| 西青区| 介休市| 依安县| 乌拉特后旗| 洛浦县| 留坝县| 五家渠市| 房山区| 澜沧| 海原县| 鹤庆县| 梅州市| 卢湾区| 巨鹿县| 普格县| 班玛县| 淮滨县| 德惠市| 乌什县| 扬中市| 奇台县| 赤峰市| 龙州县| 沛县| 佛坪县| 铁岭市| 庆元县| 宁蒗| 屯昌县| 东光县| 虹口区| 孝昌县| 体育|