This page contains the Python/matplotlib/pyplot script I badly hacked together to try and graph election opinion polls. In theory all you need to do is add the most recent numbers at the end of each line of data and then rerun the script to generate the new svg file. They could probably do with a bit of attention from someone who understands what they are doing.

Setup

edit

Download the appropriate Python and Matplotlib versions for your system (the Python 2.7 version worked best for me) - copy and save the text below as a .py file and then run it with the Python interpreter - the packaged IDE works well.

Two Party Preferred

edit
# -*- coding: cp1252 -*-
 
from pylab import * 
figure(figsize=(10, 6))
# update the end of the line with the latest results

Labor = [50.20,50.10,50,50,48,48,52,50,48,50,46,51,45,47,46,48,45,45,42,44,44,43,41,42,43,46,47,43,46,46,45,47,47,43,44,41,45,46,46,45,44,44,46,47,45,50,46,50,49,49,46,49,44,45,48,42]
Coalition = [49.80,49.90,50,50,52,52,48,50,52,50,54,49,55,53,54,52,55,55,58,56,56,57,59,58,57,54,53,57,54,54,55,53,53,57,56,59,55,54,54,55,56,56,54,53,55,50,54,50,51,51,54,51,56,55,52,58]
plot(Labor, 'r-', linewidth=2, label = r"Labor")
plot(Coalition, 'b-', linewidth=2, label = r"Coalition")
 
legend(loc=1, ncol=2, shadow=True)
 
ylabel('Percent [%]') 
vlines(x=1, ymin=36, ymax=64, linewidth=1)
text(1.3, 60, '2010 Election', rotation=270)    
title('Two Party Preferred') 

#update the dates too
xlabel ("Newspoll, 17-19 Aug 2010 to 22-24 Mar 2013 - Margin of error +/-3%")

yticks([36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64])
ylim(36,64)

xticks([])

savefig("twopartypreferred.svg")  

show()

Primary Vote

edit
# -*- coding: cp1252 -*-
 
from pylab import * 
figure(figsize=(10, 6))
# update the end of the line with the latest results
Labor = [36.20,38.00,34,35,33,34,36,34,32,36,30,36,32,33,33,34,31,30,27,29,29,27,27,26,29,29,32,30,31,30,32,35,31,28,29,27,30,32,31,30,31,28,33,35,33,36,33,36,36,36,32,38,32,31,34,30]
Coalition = [43.40,43.30,41,42,43,43,39,41,44,41,45,40,45,44,46,44,46,46,49,47,47,47,50,48,49,45,44,48,44,45,46,45,43,47,48,51,45,46,44,46,48,46,45,45,46,41,45,41,43,43,46,44,48,47,44,50]
Greens =[13.90,11.80,14,14,14,13,14,14,14,13,15,12,12,12,10,14,11,11,12,13,12,14,12,13,12,15,12,10,13,12,11,11,12,11,12,11,12,12,14,12,11,11,10,11,8,12,10,10,10,11,11,9,9,11,11,10]
Other = [6.50,7.00,11,9,10,10,11,11,10,10,10,12,12,11,11,8,12,13,12,11,12,12,11,13,10,11,12,12,12,13,11,9,14,14,11,11,13,10,11,12,10,15,12,9,13,11,12,13,11,10,11,9,11,11,11,10]
 
plot(Labor, 'r-', linewidth=2, label = r"Labor")
plot(Coalition, 'b-', linewidth=2, label = r"Coalition")
plot(Greens, 'g-', linewidth=2, label = r"Greens")
plot(Other, 'y-', linewidth=2, label = r"Other")
 
legend(loc=1, ncol=4, shadow=True)

yticks([2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52])
ylim(0,60)
xticks([])

ylabel('Percent [%]') 
vlines(x=1, ymin=0, ymax=60, linewidth=1)
text(1.3, 30, '2010 Election', rotation=270)    
 
title('Primary vote') 
#update the dates too
xlabel ("Newspoll, 17-19 Aug 2010 to 22-24 Mar 2013 - Margin of error +/-3%")
savefig("primaryvote.svg")   
 
show()

Better PM

edit
# -*- coding: cp1252 -*-
 
from pylab import * 
figure(figsize=(10, 6))
# update the end of the line with the latest results
Abbott = [37,34,31,32,34,31,32,35,31,36,31,37,36,38,37,38,40,43,41,40,39,43,40,40,39,40,35,36,37,40,38,37,37,41,41,40,37,38,38,39,40,38,38,38,32,33,34,32,33,34,33,39,40,38,43]
Gillard = [50,50,52,53,49,54,52,48,53,45,50,46,45,42,44,41,39,38,40,39,38,34,35,35,36,39,40,43,40,37,36,39,40,39,36,36,40,42,39,36,36,36,38,39,46,43,45,46,46,43,45,41,36,42,35]
plot(Abbott, 'b-', linewidth=2, label = r"Tony Abbott")
plot(Gillard, 'r-', linewidth=2, label = r"Julia Gillard")
legend(loc=1, ncol=2, shadow=True)
ylabel('Percent [%]') 
 
title('Better Prime Minister') 
#update the dates too
xlabel ("Newspoll, 17-19 Aug 2010 to 22-24 Mar 2013 - Margin of error +/-3%")

yticks([30,32,34,36,38,40, 42, 44, 46, 48, 50, 52, 54, 56])
ylim(30,56)

xticks([])

savefig("betterpm.svg")  

show()

Coalition Leadership

edit
# -*- coding: cp1252 -*-
 
from pylab import * 
figure(figsize=(10, 6))
# update the end of the line with the latest results

Satisfied = [42,48,39,41,44,42,42,42,38,39,33,36,42,38,37,35,39,42,39,39,36,39,34,36,34,34,34,33,32,36,31,32,32,35,33,34,31,32,31,32,30,32,34,31,30,33,30,27,30,28,29,33,33,36,39]
Dissatisfied = [50,38,47,46,42,45,43,44,49,51,54,53,48,51,53,52,52,49,52,52,55,52,54,53,55,57,55,57,55,52,57,58,58,54,55,56,60,59,58,57,61,56,54,59,60,55,58,63,61,59,58,56,55,55,50] 
 
plot(Satisfied, 'b-', linewidth=2, label = r"Satisfied")
plot(Dissatisfied, 'k-', linewidth=2, label = r"Dissatisfied")
 
legend(loc=1, ncol=2, shadow=True)
 
ylabel('Percent [%]') 
 
title('Coalition Leadership Satisfaction (Tony Abbott)') 
#update the dates too
xlabel ("Newspoll, 17-19 Aug 2010 to 22-24 Mar 2013 - Margin of error +/-3%")



yticks([20,22,24,26,28,30,32,34,36,38,40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74])
ylim(20,74)

xticks([])

savefig("coalitionleadership.svg")  

show()

Labor Leadership

edit
# -*- coding: cp1252 -*-
 
from pylab import * 
figure(figsize=(10, 6))
# update the end of the line with the latest results
Satisfied = [44,44,48,44,41,46,45,45,50,39,40,39,38,34,35,30,28,30,32,33,29,23,27,28,31,30,34,36,33,32,26,28,31,28,28,27,30,32,30,27,29,29,27,31,36,36,35,37,37,36,38,36,30,32,26]
Dissatisfied = [43,36,33,37,41,37,38,42,39,51,47,49,49,55,54,55,62,59,59,58,61,68,61,60,61,60,55,56,55,57,64,62,58,62,63,63,60,58,59,61,62,59,60,57,52,50,51,52,52,52,49,52,58,57,65] 
plot(Satisfied, 'r-', linewidth=2, label = r"Satisfied")
plot(Dissatisfied, 'k-', linewidth=2, label = r"Dissatisfied")
 
legend(loc=1, ncol=2, shadow=True)
 
ylabel('Percent [%]') 
 
title('Labor Leadership Satisfaction (Julia Gillard)') 
#update the dates too
xlabel ("Newspoll, 17-19 Aug 2010 to 22-24 Mar 2013 - Margin of error +/-3%")

yticks([20,22,24,26,28,30,32,34,36,38,40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74])
ylim(20,74)

xticks([])

savefig("laborleadership.svg")  

show()

Net Leadership Satisfaction

edit
# -*- coding: cp1252 -*-
 
from pylab import * 
figure(figsize=(10, 6))
# update the end of the line with the latest results 
Abbott = [-8,10,-8,-5,2,-3,-1,-2,-11,-12,-21,-17,-6,-13,-16,-17,-13,-7,-13,-13,-19,-13,-20,-17,-21,-23,-21,-24,-23,-16,-26,-26,-26,-19,-22,-22,-29,-27,-27,-25,-31,-24,-20,-28,-30,-22,-28,-36,-31,-31,-29,-23,-22,-19,-11]
Gillard = [1,8,15,7,0,9,7,3,11,-12,-7,-10,-11,-21,-19,-25,-34,-29,-27,-25,-32,-45,-34,-32,-30,-30,-21,-20,-22,-25,-38,-34,-27,-34,-35,-36,-30,-26,-29,-34,-33,-30,-33,-26,-16,-14,-16,-15,-15,-16,-11,-16,-28,-25,-39]
 
plot(Abbott, 'b-', linewidth=2, label = r"Tony Abbott")
plot(Gillard, 'r-', linewidth=2, label = r"Julia Gillard")
 
legend(loc=1, ncol=2, shadow=True)
 
ylabel('Net of Satisfaction/Disatisfaction ratings') 
 
title('Leadership Satisfaction (Net)') 
#update the dates too
xlabel ("Newspoll, 17-19 Aug 2010 to 22-24 Mar 2013 - Margin of error +/-3%")

yticks([-50,-48,-46,-44,-42,-40,-38,-36,-34,-32,-30,-28,-26,-24,-22,-20,-18,-16,-14,-12,-10,-8,-6,-4,-2,0,2,4,6,8,10,12,14,16,18,20])
ylim(-50,20)

xticks([])

savefig("netleadership.svg")  

show()