子图中的最后一个图变得过大

时间:2014-11-01 07:27:00

标签: matlab subplot

我正在使用MATLAB的子图功能。令人惊讶的是,每个子图集中的最后一个图变得过大。有人可以帮我解决这个问题吗?我已经尝试了一些参数,但没有运气。我无法发布情节图。

function plotFluxVariabilityByGene(cRxn,KeggID,geneName)

load iJO1366; % Load the model iJO1366

%Find 'Gene' associated reactions from 'model'
reactions = rxnNamesFromKeggID(model,KeggID);

nCheck = 0; % Initialize counter

% Determine initial subplot dimensions
[R C setSize] = subplotSize(numel(reactions));

for n = 1 : numel(reactions)

    % Get the name of nth reaction
    rxn = reactions{n};

    % Define the array for control reaction fluxes
    cRxnArray = getCrxnArray(model,cRxn);

    % Initialize storage for lower and upper limit-values
    L = []; U = []; Avg = [];

    % Get the fluxVariability values
    for i = 1 : numel(cRxnArray)
        modelMod = changeRxnBounds(model,cRxn,cRxnArray(i),'b');
        [L(i) U(i)] = fluxVariability(modelMod,100,'max',{rxn});
        Avg(i) = (L(i) + U(i))/2;
        %fprintf('mthfcFlux = %f; Li = %f; Ui = %f\n',array(i),L(i),U(i));
    end

    % adjust the subplot number
    nCheck = nCheck + 1;

    % Determine the range of n to be saved in one file
    if nCheck == 1
        start = n;
    elseif nCheck == setSize;
        stop = n;
    end

    subplot(R,C,nCheck)
    plot(cRxnArray,L,'-r','LineWidth',1); hold on;
    plot(cRxnArray,L,'^r','MarkerSize',3,'LineWidth',2);
    plot(cRxnArray,U,'-.b','LineWidth',1);
    plot(cRxnArray,U,'^b','MarkerSize',2,'LineWidth',2);
    plot(cRxnArray,Avg,'-','Color',[0.45,0.45,0.45],'LineWidth',2.5);

    % Label X and Y axes
    %xlabel([cRxn ' Flux']);
    %ylabel(['fluxVariability ' char(rxn)]);
    xlabel('Flux');
    ylabel('fluxVariability');
    hold off;

    % Adjust X and Y axes limits
    %xmn = min(cRxnArray) - ((max(cRxnArray) - min(cRxnArray))*0.05);
    %xmx = max(cRxnArray) + ((max(cRxnArray) - min(cRxnArray))*0.05);
    %ymn = min([U L]) - ((max([U L]) - min([U L]))*0.05);
    %ymx = max([U L]) + ((max([U L]) - min([U L]))*0.05);

    %if xmn ~= xmx
    %    xlim([xmn xmx]);
    %end
    %if ymn ~= ymx
    %    ylim([ymn ymx]);
    %end

    % Print which reactions are done
    fprintf('\n......done for %s',char(rxn));

    % If 'setSize' subplots are done then save the set in a file
    if nCheck == setSize

        saveas(gcf,['TEST/' cRxn 'flux-Vs-' geneName '_fluxVariability' num2str(start) '-' num2str(stop) '.fig']);
        saveas(gcf,['TEST/' cRxn 'flux-Vs-' geneName '_fluxVariability' num2str(start) '-' num2str(stop) '.eps']); close(gcf);

        % Determine initial subplot dimensions
        [R C setSize] = subplotSize(numel(reactions)-n);

        % Return nCheck to zero;
        nCheck = 0;
    end
end

% If nCheck is not equal to 16 then there are subplot that is not saved
% inside the for loop. Let's save it here.
if nCheck ~= setSize
    stop = n;
    saveas(gcf,['TEST/' cRxn 'flux-Vs-' geneName '_fluxVariability' num2str(start) '-' num2str(stop) '.fig']);
    saveas(gcf,['TEST/' cRxn 'flux-Vs-' geneName '_fluxVariability' num2str(start) '-' num2str(stop) '.eps']); close(gcf);
end

fprintf('\nAll done\n');
end


%####################################################
%#               Other functions                   ##
%####################################################

function rxnNames = rxnNamesFromKeggID(model,KeggID)

% Find 'Gene' associated reactions from 'model'
associatedRxns = findRxnsFromGenes(model,KeggID);

% Extract the reaction details from the structure to a cell
rxnDetails = eval(sprintf('associatedRxns.%s',KeggID));

% Extract only the reaction names from the cell
rxnNames = rxnDetails(:,1);
end

%####################################################

function cRxnArray = getCrxnArray(model,cRxn)
    % Define the solver
    changeCobraSolver('glpk');

    % Find solution for the model
    sol = optimizeCbModel(model);

    % Change the objective of the default model to 'cRxn'
    tmpModel = changeObjective(model,cRxn);

    % Find slution for the changed model. This gives the maximum and
    % minimum possible flux through the reaction 'cRxn' when the model is
    % still viable
    %solMax = optimizeCbModel(tmpModel,'max');
    solMin = optimizeCbModel(tmpModel,'min');

    % Create an array of 20 euqally spaced flux values between 'solMin' and
    % 'sol.x'
    %array = linspace(solMin.f,solMax.f,10);
    cRxnArray = linspace(solMin.f,sol.x(findRxnIDs(model,cRxn)),20);
end

%####################################################

function [R C setSize] = subplotSize(remainingPlots)

% Sets number of columns and rows to 3 if total subplot >= 9
if remainingPlots > 7
    R = 3; C = 3; setSize = 9;
elseif remainingPlots < 7
    R = 2; C = 3; setSize = 6;
elseif remainingPlots < 5
    R = 2; C = 2; setSize = 4;
elseif remainingPlots < 4
    R = 1; C = 3; setSize = 3;
elseif remainingPlots < 3
    R = 1; C = 2; setSize = 2;
end
end

%####################################################

我的子图看起来像这样:

enter image description here

1 个答案:

答案 0 :(得分:0)

我怀疑它是因为你在循环中第二次调用subplotSize。这可能会改变您的R和C变量。

我建议在每个循环上检查subplot命令中的R和C变量。