Home > matpower6.0 > most > 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 http://www.pserc.cornell.edu/matpower/ 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) && ~uc2(i, j)
0118             h1 = patch(x, y, c1);
0119         elseif ~uc1(i, j) && uc2(i, j)  %% 2 committed
0120             h2 = patch(x, y, c2);
0121         elseif uc1(i, j) && uc2(i, j)
0122             hb = patch(x, y, cb);
0123         else
0124             hn = patch(x, y, cn);
0125         end
0126     end
0127 end
0128 
0129 %% legend
0130 if strcmp(txt, 'both') && iscell(opt.subtitle) && length(opt.subtitle) == 3
0131     legend([h1 h2 hb], opt.subtitle, 'Location', [0.86 0.03 0.1 0.05], 'FontSize', 12*opt.size_factor);
0132 end
0133 
0134 %% pretty it up
0135 title(sprintf(opt.title, subt), 'FontSize', 18*opt.size_factor);
0136 axis([0 n 0 m]);
0137 h = gca;
0138 h.XTick = [0.5:1:n-0.5];
0139 h.YTick = [0.5:1:m-0.5];
0140 h.XTickLabel = {1:n};
0141 h.YTickLabel = {m:-1:1};
0142 h.TickLength = [0 0];
0143 h.YAxisLocation = 'right';
0144 h.YTickLabel = opt.rowlabels(m:-1:1);
0145 if ~isempty(opt.xlabel)
0146     xlabel(opt.xlabel, 'FontSize', 16*opt.size_factor);
0147 end
0148 if ~isempty(opt.ylabel)
0149     ylabel(opt.ylabel, 'FontSize', 16*opt.size_factor);
0150 end
0151 set(h, 'FontSize', 12*opt.size_factor);
0152 
0153 h = gcf;
0154 set(h, 'PaperOrientation', 'landscape');
0155 set(h, 'PaperPosition', [0 0 11 8.5]);
0156 if opt.saveit
0157     if isempty(strfind(opt.savename, '%s'))
0158         pdf_name = opt.savename;
0159     else
0160         pdf_name = sprintf(opt.savename, txt);
0161     end
0162     print('-dpdf', fullfile(opt.savepath, pdf_name));
0163 end
0164 
0165 if nargout
0166     hh = h;
0167 end

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005