Home > matpower7.0 > most > lib > plot_uc_data.m

plot_uc_data

PURPOSE ^

PLOT_UC_DATA Plot generator commitment summary

SYNOPSIS ^

function hh = plot_uc_data(uc1, uc2, optin)

DESCRIPTION ^

PLOT_UC_DATA   Plot generator commitment summary

   PLOT_UC_DATA(UC1, UC2, OPT)
   H = PLOT_UC_DATA(UC1, ...)

   Inputs:
       UC1     (optional) matrix of 1's and 0's indicating commitment status for
               first commitment schedule (red)
               each row corresponds to a generator, each column to a period
       UC2     (optional) commitment statuses for second commitment schedule
               (gray)
       OPT     options struct with the following (all optional) fields, where
               default values are shown in parenthesis:
           'title'         ('Unit Commitment - %s') title for the plot, where
                           %s is an optional placeholder for the subtitle
           'subtitle'      ({'First', 'Second', 'Both'}) cell array of labels
                           to use for legend (if two schedules are provided)
                           and to replace a placeholder in the title (based
                           on which commitment schedule(s) is(are) provided in
                           UC1 and/or UC2); can also be a simple string, in
                           which case no legend will be displayed even if both
                           UC1 and UC2 are supplied
           'xlabel'        ('Period') label for horizontal axis
           'ylabel'        (<empty>) label for vertical axis
           'rowlabels'     ({'1', '2', '3', ...) labels for rows
           'saveit'        (false) flag to indicate whether to create PDF file
           'savepath'      ('') path to directory to save files in
           'savename'      ('uc-%s.pdf') name of PDF file
                           %s is optional placeholder for commitment schedule
                           index ('1', '2', or 'both')
           'size_factor'   (1) to scale font/marker sizes in case you want to
                           do sub-plots or something

   Returns handle to current figure window.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function hh = plot_uc_data(uc1, uc2, optin)
0002 %PLOT_UC_DATA   Plot generator commitment summary
0003 %
0004 %   PLOT_UC_DATA(UC1, UC2, OPT)
0005 %   H = PLOT_UC_DATA(UC1, ...)
0006 %
0007 %   Inputs:
0008 %       UC1     (optional) matrix of 1's and 0's indicating commitment status for
0009 %               first commitment schedule (red)
0010 %               each row corresponds to a generator, each column to a period
0011 %       UC2     (optional) commitment statuses for second commitment schedule
0012 %               (gray)
0013 %       OPT     options struct with the following (all optional) fields, where
0014 %               default values are shown in parenthesis:
0015 %           'title'         ('Unit Commitment - %s') title for the plot, where
0016 %                           %s is an optional placeholder for the subtitle
0017 %           'subtitle'      ({'First', 'Second', 'Both'}) cell array of labels
0018 %                           to use for legend (if two schedules are provided)
0019 %                           and to replace a placeholder in the title (based
0020 %                           on which commitment schedule(s) is(are) provided in
0021 %                           UC1 and/or UC2); can also be a simple string, in
0022 %                           which case no legend will be displayed even if both
0023 %                           UC1 and UC2 are supplied
0024 %           'xlabel'        ('Period') label for horizontal axis
0025 %           'ylabel'        (<empty>) label for vertical axis
0026 %           'rowlabels'     ({'1', '2', '3', ...) labels for rows
0027 %           'saveit'        (false) flag to indicate whether to create PDF file
0028 %           'savepath'      ('') path to directory to save files in
0029 %           'savename'      ('uc-%s.pdf') name of PDF file
0030 %                           %s is optional placeholder for commitment schedule
0031 %                           index ('1', '2', or 'both')
0032 %           'size_factor'   (1) to scale font/marker sizes in case you want to
0033 %                           do sub-plots or something
0034 %
0035 %   Returns handle to current figure window.
0036 
0037 %   MOST
0038 %   Copyright (c) 2015-2016, Power Systems Engineering Research Center (PSERC)
0039 %   by Ray Zimmerman, PSERC Cornell
0040 %
0041 %   This file is part of MOST.
0042 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0043 %   See https://github.com/MATPOWER/most for more info.
0044 
0045 %% default args
0046 if nargin < 3
0047     optin = [];
0048     if nargin < 2
0049         uc2 = [];
0050     end
0051 end
0052 
0053 %% data and dimensions
0054 if ~isempty(uc1)
0055     [m, n] = size(uc1);
0056     if isempty(uc2);
0057         uc2 = zeros(m, n);
0058         t = 1;              %% index of subtitle
0059         txt = '1';          %% for filename
0060     else
0061         if size(uc2) ~= [m n]
0062             error('plot_uc: size mismatch');
0063         end
0064         t = 3;              %% index of subtitle
0065         txt = 'both';       %% for filename
0066     end
0067 elseif ~isempty(uc2)
0068     [m, n] = size(uc2);
0069     uc1 = zeros(m, n);
0070     t = 2;                  %% index of subtitle
0071     txt = '2';              %% for filename
0072 end
0073 
0074 %% default options
0075 opt = struct( ...
0076     'title', 'Unit Commitment - %s', ...
0077     'subtitle', {{'First', 'Second', 'Both'}}, ...
0078     'xlabel', 'Period', ...
0079     'ylabel', '', ...
0080     'rowlabels', [], ...
0081     'saveit', false, ...
0082     'savepath', '', ...
0083     'savename', 'uc-%s.pdf', ...
0084     'size_factor', 1 );
0085 
0086 %% override default options
0087 fields = fieldnames(opt);
0088 for k = 1:length(fields)
0089     if isfield(optin, fields{k})
0090         opt.(fields{k}) = optin.(fields{k});
0091     end
0092 end
0093 if isempty(opt.rowlabels)
0094     opt.rowlabels = {m:-1:1};
0095 end
0096 
0097 %% set subtitle
0098 if iscell(opt.subtitle) && length(opt.subtitle) == 3
0099     subt = opt.subtitle{t};
0100 elseif ischar(opt.subtitle)
0101     subt = opt.subtitle;
0102 else
0103     warning('plot_uc_data: OPT.subtitle must be a string or 3 element cell array of strings');
0104     subt = '';
0105 end
0106 
0107 c1 = [1 0.2 0.2] * 0.8;     %% 1 committed
0108 c2 = [1 1 1] * 0.6;         %% 2 committed
0109 cb = [0.5 0.28 0.28];       %% both committed
0110 cn = [1 1 1];               %% neither committed
0111 
0112 h1 = []; h2 = []; hb = [];
0113 for i = 1:m
0114     for j = 1:n
0115         y = m-[i-1; i; i; i-1];
0116         x = [j-1; j-1; j; j];
0117         if uc1(i, j)                %% 1 committed
0118             h1 = patch(x, y, c1);
0119         end
0120         if uc2(i, j)                %% 2 committed
0121             h2 = patch(x, y, c2);
0122         end
0123         if uc1(i, j) && uc2(i, j)   %% both committed
0124             hb = patch(x, y, cb);
0125         end
0126         if ~uc1(i, j) && ~uc2(i, j) %% neither committed
0127             hn = patch(x, y, cn);
0128         end
0129     end
0130 end
0131 
0132 %% legend
0133 if strcmp(txt, 'both') && iscell(opt.subtitle) && length(opt.subtitle) == 3
0134     legend([h1 h2 hb], opt.subtitle, 'Location', [0.86 0.03 0.1 0.05], 'FontSize', 12*opt.size_factor);
0135 else
0136     legend('off')
0137 end
0138 
0139 %% pretty it up
0140 title(sprintf(opt.title, subt), 'FontSize', 18*opt.size_factor);
0141 axis([0 n 0 m]);
0142 h = gca;
0143 h.XTick = [0.5:1:n-0.5];
0144 h.YTick = [0.5:1:m-0.5];
0145 h.XTickLabel = {1:n};
0146 h.YTickLabel = {m:-1:1};
0147 h.TickLength = [0 0];
0148 h.YAxisLocation = 'right';
0149 h.YTickLabel = opt.rowlabels(m:-1:1);
0150 if ~isempty(opt.xlabel)
0151     xlabel(opt.xlabel, 'FontSize', 16*opt.size_factor);
0152 end
0153 if ~isempty(opt.ylabel)
0154     ylabel(opt.ylabel, 'FontSize', 16*opt.size_factor);
0155 end
0156 set(h, 'FontSize', 12*opt.size_factor);
0157 
0158 h = gcf;
0159 set(h, 'PaperOrientation', 'landscape');
0160 set(h, 'PaperPosition', [0 0 11 8.5]);
0161 if opt.saveit
0162     if isempty(strfind(opt.savename, '%s'))
0163         pdf_name = opt.savename;
0164     else
0165         pdf_name = sprintf(opt.savename, txt);
0166     end
0167     print('-dpdf', fullfile(opt.savepath, pdf_name));
0168 end
0169 
0170 if nargout
0171     hh = h;
0172 end

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005