File:NPVIC participants.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file(SVG file, nominally 990 × 765 pixels, file size: 264 KB)

Captions

Captions

Add a one-line explanation of what this file represents

Summary[edit]

Description
English: Graph illustrating the history of U.S. state participation in the National Popular Vote Interstate Compact. Created with a MATLAB script and converted from PDF to SVG using Inkscape.
Date
Source Own work.
Author Swpb.
SVG development
InfoField
 
The SVG code is valid.
 
This diagram was created with MATLAB.

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following licenses:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
You may select the license of your choice.

Matlab code[edit]

%==========================================================================
%   PPRODUCES A LABELED AREA PLOT OF THE ENACTMENT HISTORY OF THE NPVIC
%   Author: Swpb
%   Date: 4-Apr-2014
%==========================================================================
clear all; 
%==========================================================================
%                       !!! ADD EVENTS HERE !!!
Events = [
    
% STATE   EVs        DATE        
{ '  '     0   '19-Jan-2006' }; %(First legislative introduction)
{ 'MD'    10   '10-Apr-2007' };
{ 'NJ'    14   '13-Jan-2008' };
{ 'IL'    20   ' 7-Apr-2008' };
{ 'HI'     4   ' 1-May-2008' };
{ 'WA'    12   '28-Apr-2009' };
{ 'MA'    11   ' 4-Aug-2010' };
{ 'DC'     3   ' 7-Dec-2010' };
{ 'VT'     3   '22-Apr-2011' };
{ 'CA'    55   ' 8-Aug-2011' };
{ 'RI'     4   '12-Jul-2013' };
{ 'NY'    29   '15-Apr-2014' };

%{ 'state'   EVs   'date' };    %Add new events above this line in the format shown
];


%                      =====Display Options =====
right_edge_gap = false;  %Set to true to display recent events properly
clr1 =  [0.4 0.9 0.4];    %Area plot face color (RGB)
clr2 =  [0.0 0.5 0.0];     %"Total" line color
backc = [1.0 1.0 0.8];     %Label background color
shadowc=[0.8 0.8 0.8];     %Label shadow color
altyrc =[.97 .97 .97]; %Alternate year stripe color

%        ----------------------------------------------------------
%OLD EV values (move here after each reapportionment and update code below)

%           i MD NJ IL HI WA MA DC
EVs_old1 = [0 10 15 21 04 11 12 03];  %values before 2010 reapportionment
%EVs_old2 = ;
 
%========================================================================== 
%CALCULATIONS

%Extract data
states = Events(2:end,1);
dates = datenum(Events(:,3)')';
event_count = length(dates); 
evs = Events(:,2);
for i=1:size(Events,1)
    EVs(i)=evs{i,1};
end
date_0 = datenum(' 1-Jan-2006'); date_n = datenum(date);    %start and end dates
date_c = datenum('31-Dec-2010');                            %census reapportionment date

%Add census (or dummy) event to each state's column
dates2 = zeros(size(dates,1)+1,event_count);
for state=1:event_count
    if dates(1,state) < date_c                                        %if state's first event is before census
         dates2(:,state) = sort([dates(:,state) date_c]);            %insert date of census event
    else dates2(:,state) = sort([dates(:,state) dates(1,state)]);   %else duplicate date of first event
    end
end; dates = dates2;

%Create column of sorted event dates
event_list = unique(reshape(dates,size(dates,1)*size(dates,2),1));  %column of unique event dates
event_list = sort([date_0; event_list; event_list; date_n]);           %double entries, add start/end dates, and sort

%Generate EV_mat matrix for area plotting
EVs = [EVs_old1 zeros(1,length(EVs)-length(EVs_old1)); EVs];  %combine EV numbers into a matrix
EV_mat = zeros(length(event_list),event_count);
for state=1:event_count  %for each state, generate a column of EV values at each event date
    index0 = find(event_list == dates(1,state),1);  %index prior to first event
    EV_mat(1:index0,state) = zeros(index0,1);        %zero prior to first event
    for event = 2:size(dates,1)
        index0 = find(event_list == dates(event-1,state),1);   %index prior to previous event
        index1 = find(event_list == dates(event,state),1);     %index prior to current event
        EV_mat(index0+1:index1,state) = EVs(event-1,state);     %prior to subsequent dates
    end
    EV_mat(index1+1:end,state) = EVs(end,state);    %to end date
end

total = sum(EV_mat,2);  %total EVs following each event

%==========================================================================
%SET AXIS AND FIGURE PROPERTIES

%Set right edge value
if not(exist('right_edge_gap'))
    right_edge_gap = 0;
end
date_f = date_n+right_edge_gap*0.01*(date_n-date_0);

%Set top edge value
ymax = 20*ceil(total(end)/20)+5;

%Set x-axis tick positions
years = 0;
while datenum(['1-Jan-' num2str(year(date_0)+1+years)]) < date_f
    years = years + 1; end
str(1:years+1) = {'1-Jan-'};
grid_x_pos = datenum([char(str) num2str((year(date_0):year(date_0)+years)')]);

%Set text for x-axis tick labels
spaces = ['      '];
x_labels_num = [year(date_0):year(date_f)];
for i=1:length(x_labels_num)
    x_labels(i,:) = [spaces '’' strrep(num2str(x_labels_num(i)),'20','')];
end
if year(date_f) > year(date_f-90)  %if date_f is in first part of the year
    x_labels(length(x_labels),:) = [spaces '   '];    %hide label for current year
end
%Prepare figure for plotting
close all;
figure(1); hold on;
axis([date_0 date_f 0 ymax]);
set(gcf,'Position',[100,150,1180,800],...           %window (left, bottom, width, height)
    'Color',[.98 .98 .98]);
set(gca,'OuterPosition',[-.07,0.05,0.97,0.9],...   %axes (left, bottom, width, height)
    'Color',altyrc,'TickDir','out','FontSize',18,'YAxisLocation','right',...    
    'XAxisLocation','top','XTick', grid_x_pos,'XTickLabel',x_labels,'YTick',0:25:ymax);  %,'XGrid','on','GridLineStyle',':'

%set(gca,'OuterPosition',[-.07,-0.05,0.97,1.0],...   %axes (left, bottom, width, height)
%    'Color',altyrc,'TickDir','out','FontSize',18,'YAxisLocation','right',...    
%    'XAxisLocation','top','XTick', grid_x_pos,'XTickLabel',x_labels,'YTick',0:25:ymax);  %,'XGrid','on','GridLineStyle',':'

%==========================================================================
%PLOT ELEMENTS

%Draw solid background
rectangle('position',[date_0 0 date_f-date_0 ymax],'Facecolor','white');

%Draw stripes on alternating years
for yr = 2:2:years+1
    %rectangle('position',[grid_x_pos(yr) 0 365.25 ymax-0.5],'Facecolor',altyrc,'LineStyle','none');
    patch([grid_x_pos(yr) grid_x_pos(yr) grid_x_pos(yr)+365.25 grid_x_pos(yr)+365.25],[0 ymax ymax 0],altyrc,'EdgeColor',[.5 .5 .5]);
end

%Label x-axis
text((date_0+date_f)/2,1.1*ymax,{'Year'},'FontWeight','demi',...
    'FontSize',18,'Rotation',0,'HorizontalAlignment','center','VerticalAlignment','middle')

%Label y-axis
text(date_f+0.15*(date_f-date_0),ymax/2,{'Total' 'Electoral' 'Votes of' 'Adoptive' 'States'},'FontWeight','demi',...
    'FontSize',18,'Rotation',0,'HorizontalAlignment','center','VerticalAlignment','middle');

%Plot data
area(event_list,EV_mat,'FaceColor',clr1,'LineWidth',1,'EdgeColor','white');

%Determine positions of events
event_x_pos = event_list(2:2:end-1); event_y_pos = total(3:2:end);  %get x and y positions
event_y_pos = max(event_y_pos, [0; event_y_pos(1:end-1)] );             %bump up y-positions on decreases
lx0 = event_x_pos(1); ly0 = event_y_pos(1); %identify start position

%Plot reapportionment line
census_index = find(event_x_pos==date_c,1);        %get index of census event in sequence of dates
lxc = event_x_pos(census_index); lyc = event_y_pos(census_index); %identify census event position
%plot([lxc lxc],[0 lyc],':','Color',(clr1+1)./2);
plot([lxc lxc],[0 lyc],':','Color','black','LineWidth',2);

%Plot "total" line
plot(event_list(2:end),    total(2:end),       'LineWidth',3,'Color',clr2);
plot(event_list(5:end-1),  total(5:end-1),'s-','LineWidth',3,'Color',clr2,'MarkerSize',4,'MarkerEdgeColor','none','MarkerFaceColor',clr2);

%Plot a thickened plot border
plot([date_0 date_f date_f],[0    0 ymax],'k','LineWidth',1);
plot([date_0 date_0 date_f],[0 ymax ymax],'k','LineWidth',2);

%==========================================================================
%ADD LABELS

%Set label formats and adjustments 
alength = ones(1,event_count+1);   %length of anchor lines
alength(4)=1.8;                 %adjustment for HI
alength(7)=1.8;                 %adjstment for DC
alength(8)=2.8;                 %adjustment for VT
talgn(1:event_count)={'right '};   %horizontal text alignment
xshad = .003*(date_f-date_0);   %shadow x-displacement
yshad = -.004*ymax;             %shadow y-displacement
vertp = alength*0.04*ymax;              %adjust scale of vertical lines
horzp = alength*0.01*(date_f-date_0);   %adjust scale of horizontal lines

%Label state event dates
state_event_x_pos = event_x_pos([2:census_index-1 census_index+1:end]); %state events only
state_event_y_pos = event_y_pos([2:census_index-1 census_index+1:end]); %state events only
for n=1:length(state_event_x_pos)     %for each state, plot box shadows
   lxn = state_event_x_pos(n);
   lyn = state_event_y_pos(n);
   text(lxn-horzp(n)+xshad,lyn+vertp(n)+yshad,states(n,:),'VerticalAlignment','bottom',...
     'BackgroundColor',shadowc,'HorizontalAlignment',char(talgn(n)),'FontSize',15,'EdgeColor',shadowc,'Color',shadowc);  %box shadow
end
for n=1:length(state_event_x_pos)     %for each state, plot label boxes and lines
   lxn = state_event_x_pos(n);
   lyn = state_event_y_pos(n);
   plot([lxn-horzp(n) lxn],[lyn+vertp(n) lyn],'k-');                                                      %line
   text(lxn-horzp(n),lyn+vertp(n),states(n,:),'VerticalAlignment','bottom',...
     'BackgroundColor',backc,'HorizontalAlignment',char(talgn(n)),'FontSize',15,'EdgeColor','black');     %text box
end

%{
%Annotate start date
[currx curry]=dsxy2figxy(gca,lx0,ly0);
annotation('textarrow',[currx currx],[curry+0.06 curry],'LineWidth',1.5,'String',{'First' 'legislative' ' introduction '},...
    'HorizontalAlignment','center','FontSize',12,'TextBackgroundColor',[.85 .95 1],'TextEdgeColor',[0 0 0],'FontWeight','demi');

%Annotate census event
[currx curry]=dsxy2figxy(gca,lxc,lyc);
[null topy]=dsxy2figxy(gca,0,ymax)
annotation('textarrow',[currx currx],[0.9*topy curry],'LineWidth',1.5,'String',{' Reapportionment ' 'based on' '2010 Census'},...
    'HorizontalAlignment','center','FontSize',12,'TextBackgroundColor',[.85 .95 1],'TextEdgeColor',[0 0 0],'FontWeight','demi');
%}

%Annotate start date
[startx starty]=dsxy2figxy(gca,lx0,ly0);
annotation('textarrow',[startx startx],[starty-0.05 starty],'LineWidth',1.5,'String',{'First' 'legislative' ' introduction '},...
    'HorizontalAlignment','center','FontSize',12,'TextBackgroundColor',[.85 .95 1],'TextEdgeColor',[0 0 0],'FontWeight','demi');

%Annotate census event
[censx censy]=dsxy2figxy(gca,lxc,lyc);
[null topy]=dsxy2figxy(gca,0,ymax);
annotation('textarrow',[censx censx],[starty-0.05 starty],'LineWidth',1.5,'String',{' Reapportionment ' 'based on' '2010 Census'},...
    'HorizontalAlignment','center','FontSize',12,'TextBackgroundColor',[.85 .95 1],'TextEdgeColor',[0 0 0],'FontWeight','demi');

%Annotate current EV total
[currx curry]=dsxy2figxy(gca,date_n,total(end));    
annotation('textarrow',[currx+.02 currx],[curry curry],'Color',clr2,...
    'String',[' ' num2str(total(end)) ' (' num2str(round(total(end)/2.7)) '% of 270)'],'FontSize',15,'FontWeight','bold');

%==========================================================================
%EXPORT AS PDF

orient landscape
print NPVIC_participants.pdf -painters -dpdf
orient portrait
%close(gcf)

%==========================================================================
%DISPLAY INTRUCTIONS TO CONVERT TO SVG

clc;
disp([ ...
'  TO CONVERT PDF TO SVG USING INKSCAPE:        ';
'  1. Open NPVIC_participants.PDF in inkscape   ';
'  2. Select all             (Ctrl-A)           ';
'  3. Path -> Object to Path (Ctrl-Shift-C)     ';
'  4. Path -> Stroke to Path (Ctrl-Alt-C)       ';
'  5. Save as Plain SVG                         ';
]);

%==========================================================================
%End of code

File history

Click on a date/time to view the file as it appeared at that time.

(newest | oldest) View (newer 10 | ) (10 | 20 | 50 | 100 | 250 | 500)
Date/TimeThumbnailDimensionsUserComment
current16:54, 12 November 2016Thumbnail for version as of 16:54, 12 November 2016990 × 765 (264 KB)Swpb (talk | contribs)x
21:42, 9 November 2016Thumbnail for version as of 21:42, 9 November 2016990 × 765 (263 KB)Swpb (talk | contribs)x
21:29, 9 November 2016Thumbnail for version as of 21:29, 9 November 2016990 × 765 (262 KB)Swpb (talk | contribs)x
22:04, 20 May 2016Thumbnail for version as of 22:04, 20 May 2016990 × 765 (262 KB)Swpb (talk | contribs)Moved years to top to allow easier visual tracing
13:50, 5 May 2016Thumbnail for version as of 13:50, 5 May 2016990 × 765 (269 KB)Swpb (talk | contribs)rm incorrect year
23:17, 22 April 2016Thumbnail for version as of 23:17, 22 April 2016990 × 765 (262 KB)Swpb (talk | contribs)Fix overlapping state labels
23:09, 22 April 2016Thumbnail for version as of 23:09, 22 April 2016990 × 765 (262 KB)Swpb (talk | contribs)Update
22:00, 3 September 2015Thumbnail for version as of 22:00, 3 September 2015990 × 765 (258 KB)Swpb (talk | contribs)Fix margin
21:58, 3 September 2015Thumbnail for version as of 21:58, 3 September 2015990 × 765 (258 KB)Swpb (talk | contribs)Update 09/2015
19:20, 2 January 2015Thumbnail for version as of 19:20, 2 January 2015990 × 765 (302 KB)Swpb (talk | contribs)Jan 2015 update
(newest | oldest) View (newer 10 | ) (10 | 20 | 50 | 100 | 250 | 500)

File usage on other wikis

The following other wikis use this file:

Metadata