91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Matlab如何實現繪制有氣泡感的網絡圖

發布時間:2023-02-22 10:51:21 來源:億速云 閱讀:145 作者:iii 欄目:開發技術

這篇文章主要介紹“Matlab如何實現繪制有氣泡感的網絡圖”,在日常操作中,相信很多人在Matlab如何實現繪制有氣泡感的網絡圖問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Matlab如何實現繪制有氣泡感的網絡圖”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

    繪制效果如下:

    Matlab如何實現繪制有氣泡感的網絡圖

    0 數據準備

    數據需要的關系矩陣需要的是反對稱矩陣:

    % 隨機生成100x100的反對角矩陣
    Data=(rand(100)-.5).*(rand(100)>.978);
    Data(1:30,:)=Data(1:30,:).*3;
    Data=tril(Data)-tril(Data)';
    % 生成100x1列向量,分類標簽為1-10
    Class=(1:10).*ones(10,1);
    Class=Class(:);

    1 基礎繪圖

    兩行代碼完事:

    % 基礎繪圖
    BD=bubbleDigraph(Data,Class);
    BD=BD.draw();

    Matlab如何實現繪制有氣泡感的網絡圖

    2 氣泡大小

    可以使用bubblesize函數設置氣泡大小范圍,例如:

    bubblesize([5,40])

    Matlab如何實現繪制有氣泡感的網絡圖

    3 氣泡顏色

    使用setBubbleColor函數設置顏色:

    BD.setBubbleColor(turbo(10))

    Matlab如何實現繪制有氣泡感的網絡圖

    4 氣泡其他屬性

    可以使用setBubble函數進行設置,bubblechart圖形對象具有的屬性均可以修改:

    BD.setBubble('MarkerFaceAlpha',.2,'MarkerEdgeColor',[0,0,0])

    Matlab如何實現繪制有氣泡感的網絡圖

    5 連線配色

    直接使用colormap函數即可設置:

    colormap(bone)

    Matlab如何實現繪制有氣泡感的網絡圖

    6 添加節點及類標簽

    分別使用:

    • NodeName

    • ClassName

    倆屬性設置兩種標簽:

    for i=1:100
        nodeName{i}=[num2str(Class(i)),'-',num2str(i)];
    end
    className={'AAAAA','BBBBB','CCCCC','DDDDD','EEEEE','FFFFF','GGGGG','HHHHH','IIIII','JJJJJ'};
    
    BD=bubbleDigraph(Data,Class,'NodeName',nodeName,'ClassName',className);
    BD=BD.draw();
    
    bubblesize([5,25])

    Matlab如何實現繪制有氣泡感的網絡圖

    7 標簽距離

    分別通過:

    • RNode

    • RClass

    倆屬性設置兩種標簽距離中心的距離:

    BD=bubbleDigraph(Data,Class,'NodeName',nodeName,'ClassName',className,'RClass',1.38,'RNode',1.2);
    BD=BD.draw();

    Matlab如何實現繪制有氣泡感的網絡圖

    8 設置字體

    分別使用:

    • setNodeLabel

    • setClassLabel

    倆函數設置兩種標簽的屬性:

    BD.setNodeLabel('FontName','Cambria','Color',[0,0,.8])
    BD.setClassLabel('FontName','Cambria','Color',[.8,0,0],'FontSize',14)

    Matlab如何實現繪制有氣泡感的網絡圖

    工具函數完整代碼

    classdef bubbleDigraph
    % @author : slandarer
    % 公眾號  : slandarer隨筆 
    % Zhaoxu Liu / slandarer (2023). bubble digraph 
    % (https://www.mathworks.com/matlabcentral/fileexchange/125140-bubble-digraph), 
    % MATLAB Central File Exchange. 檢索來源 2023/2/21.
        properties
            ax,arginList={'ColorOrder','Colormap','ClassName','NodeName','BubbleSize','RClass','RNode'}
            ClassName   % 類名稱
            NodeName    % 節點名稱
            % 節點配色
            ColorOrder=[0.6510    0.8078    0.8902;    0.1216    0.4706    0.7059;    0.6980    0.8745    0.5412
                        0.2000    0.6275    0.1725;    0.9843    0.6039    0.6000;    0.8902    0.1020    0.1098
                        0.9922    0.7490    0.4353;    1.0000    0.4980         0;    0.7922    0.6980    0.8392
                        0.4157    0.2392    0.6039;    1.0000    1.0000    0.6000;    0.6941    0.3490    0.1569];
            % 連線配色
            Colormap=[1.0000    0.9686    0.9529;    0.9980    0.9454    0.9307;    0.9960    0.9221    0.9084;    0.9939    0.8988    0.8861
                      0.9920    0.8750    0.8630;    0.9910    0.8477    0.8336;    0.9900    0.8204    0.8043;    0.9890    0.7930    0.7750;    
                      0.9877    0.7629    0.7502;    0.9857    0.7245    0.7390;    0.9837    0.6860    0.7279;    0.9817    0.6476    0.7168;    
                      0.9793    0.6027    0.7022;    0.9762    0.5470    0.6820;    0.9732    0.4913    0.6617;    0.9701    0.4357    0.6415;    
                      0.9555    0.3815    0.6263;    0.9292    0.3289    0.6162;    0.9028    0.2763    0.6061;    0.8765    0.2237    0.5960;    
                      0.8369    0.1717    0.5763;    0.7894    0.1201    0.5510;    0.7418    0.0684    0.5257;    0.6942    0.0168    0.5004;    
                      0.6429    0.0039    0.4888;    0.5903    0.0039    0.4817;    0.5376    0.0039    0.4746;    0.4850    0.0039    0.4676;    
                      0.4350    0.0030    0.4552;    0.3855    0.0020    0.4420;    0.3359    0.0010    0.4288;    0.2863         0    0.4157];
            Data,Class          % 有向圖及節點分類
            BubbleSize=[5,25];  % 節點氣泡大小范圍[min,max]
            LineWidth=1.5;      % 連接線粗細
            AlphaLim=[.1,.9];
            ClassSet,ClassNum,
            RClass=1.25;
            RNode=1.08;
            ColorList;
            bubbleHdl,nodeLabelHdl,classLabelHdl
        end
    
        methods
            function obj=bubbleDigraph(Data,Class,varargin)
                obj.Data=Data;
                obj.Class=Class(:);
                obj.ClassSet=unique(Class);
                obj.ClassNum=length(obj.ClassSet);
    
                for i=1:size(obj.Data,1)
                    obj.NodeName{i}='';
                end
                for i=1:obj.ClassNum
                    obj.ClassName{i}='';
                end
                
                % 獲取其他數據
                disp(char([64 97 117 116 104 111 114 32 58 32,...
                     115 108 97 110 100 97 114 101 114]))
                for i=1:2:(length(varargin)-1)
                    tid=ismember(obj.arginList,varargin{i});
                    if any(tid)
                        obj.(obj.arginList{tid})=varargin{i+1};
                    end
                end
                if obj.ClassNum>size(obj.ColorOrder,1)
                    obj.ColorOrder=[obj.ColorOrder;rand([obj.ClassNum,3])];
                end
            end
            function obj=draw(obj)
                obj.ax=gca;hold on;
                colormap(obj.Colormap)
                obj.ax.XLim=[-1.2,1.2];
                obj.ax.YLim=[-1.2,1.2];
                obj.ax.XTick=[];
                obj.ax.YTick=[];
                obj.ax.XColor='none';
                obj.ax.YColor='none';
                obj.ax.PlotBoxAspectRatio=[1,1,1];
    
                % 調整初始界面大小
                fig=obj.ax.Parent;
                fig.Color=[1,1,1];
                if max(fig.Position(3:4))<600
                    fig.Position(3:4)=1.8.*fig.Position(3:4);
                    fig.Position(1:2)=fig.Position(1:2)./3;
                end
                % 繪制氣泡
                thetaList=linspace(0,2*pi,size(obj.Data,1)+1);thetaList(end)=[];
                XList=cos(thetaList);YList=sin(thetaList);
                obj.bubbleHdl=bubblechart(XList,YList,sum(abs(obj.Data)));
                bubblesize(obj.BubbleSize)
    
                obj.ColorList=zeros(size(obj.Data,1),3);
                for i=1:length(obj.ClassSet)
                    obj.ColorList(obj.Class==obj.ClassSet(i),:)=...
                        repmat(obj.ColorOrder(i,:),sum(obj.Class==obj.ClassSet(i)),1);
                end
                obj.bubbleHdl.CData=obj.ColorList;
                % 繪制連線
                alphaData=abs(obj.Data);
                alphaData=alphaData-min(min(alphaData));
                alphaData=alphaData./max(max(alphaData));
                alphaData=alphaData.*(obj.AlphaLim(2)-obj.AlphaLim(1))+obj.AlphaLim(1);
                for i=1:size(obj.Data,1)
                    for j=1:i-1
                        if obj.Data(i,j)~=0
                            bezierX=[cos(thetaList(i)),0,cos(thetaList(j))].*.93;
                            bezierY=[sin(thetaList(i)),0,sin(thetaList(j))].*.93;
                            bezierPnts=bezierCurve([bezierX',bezierY'],100);
                            bezierX=[bezierPnts(:,1);nan];
                            bezierY=[bezierPnts(:,2);nan];
                            fill(bezierX,bezierY,linspace(-1,1,101).*obj.Data(i,j)./abs(obj.Data(i,j)),'EdgeColor','interp',...
                                'LineWidth',obj.LineWidth,'EdgeAlpha',alphaData(i,j))
                        end
                    end
                end
                % 繪制節點標簽
                for i=1:size(obj.Data,1)
                    Ti=thetaList(i);
                    rotation=Ti/pi*180;
                    if rotation>90&&rotation<270
                        rotation=rotation+180;
                        obj.nodeLabelHdl(i)=text(cos(Ti).*obj.RNode,sin(Ti).*obj.RNode,obj.NodeName{i},...
                            'Rotation',rotation,'HorizontalAlignment','right','FontSize',9);
                    else
                        obj.nodeLabelHdl(i)=text(cos(Ti).*obj.RNode,sin(Ti).*obj.RNode,obj.NodeName{i},...
                            'Rotation',rotation,'FontSize',9);
                    end
                end
                % 繪制類標簽
                for i=1:obj.ClassNum
                    CTi=mean(thetaList(obj.Class==obj.ClassSet(i)));
                    rotation=CTi/pi*180;
                    if rotation>0&&rotation<180
                        obj.classLabelHdl(i)=text(cos(CTi).*obj.RClass,sin(CTi).*obj.RClass,obj.ClassName{i},'FontSize',14,'FontName','Arial',...
                        'HorizontalAlignment','center','Rotation',-(.5*pi-CTi)./pi.*180);
                    else
                        obj.classLabelHdl(i)=text(cos(CTi).*obj.RClass,sin(CTi).*obj.RClass,obj.ClassName{i},'FontSize',14,...
                        'HorizontalAlignment','center','Rotation',-(1.5*pi-CTi)./pi.*180);
                    end
                end
                % 貝塞爾函數
                function pnts=bezierCurve(pnts,N)
                    t=linspace(0,1,N);
                    p=size(pnts,1)-1;
                    coe1=factorial(p)./factorial(0:p)./factorial(p:-1:0);
                    coe2=((t).^((0:p)')).*((1-t).^((p:-1:0)'));
                    pnts=(pnts'*(coe1'.*coe2))';
                end
            end
            % 修改氣泡顏色
            function obj=setBubbleColor(obj,ColorList)
                obj.ColorOrder=ColorList;
                for i=1:length(obj.ClassSet)
                    obj.ColorList(obj.Class==obj.ClassSet(i),:)=...
                        repmat(obj.ColorOrder(i,:),sum(obj.Class==obj.ClassSet(i)),1);
                end
                set(obj.bubbleHdl,'CData',obj.ColorList);
            end
            % 修改氣泡其他屬性
            function obj=setBubble(obj,varargin)
                set(obj.bubbleHdl,varargin{:});
            end
            % 設置標簽
            function setNodeLabel(obj,varargin)
                for i=1:size(obj.Data,1)
                    set(obj.nodeLabelHdl(i),varargin{:});
                end
            end
    
            function setClassLabel(obj,varargin)
                for i=1:obj.ClassNum
                    set(obj.classLabelHdl(i),varargin{:});
                end
            end
        end
    % @author : slandarer
    % 公眾號  : slandarer隨筆 
    % Zhaoxu Liu / slandarer (2023). bubble digraph 
    % (https://www.mathworks.com/matlabcentral/fileexchange/125140-bubble-digraph), 
    % MATLAB Central File Exchange. 檢索來源 2023/2/21.
    end

    到此,關于“Matlab如何實現繪制有氣泡感的網絡圖”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!

    向AI問一下細節

    免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

    AI

    繁昌县| 绥阳县| 德保县| 衢州市| 临潭县| 宜阳县| 故城县| 韩城市| 旌德县| 邢台县| 威远县| 通化县| 乌什县| 天台县| 钦州市| 东乡族自治县| 长汀县| 南皮县| 陆河县| 沧源| 白城市| 乌拉特前旗| 库伦旗| 崇阳县| 双桥区| 南郑县| 交城县| 连山| 大方县| 宜宾市| 会昌县| 渝北区| 东莞市| 兴和县| 通海县| 阳春市| 鞍山市| 广宁县| 双峰县| 融水| 瑞昌市|