Skip to content

Instantly share code, notes, and snippets.

@bkamapantula
Last active April 26, 2019 14:34
Show Gist options
  • Save bkamapantula/7f0480b22227b85c2467 to your computer and use it in GitHub Desktop.
Save bkamapantula/7f0480b22227b85c2467 to your computer and use it in GitHub Desktop.
Changing patterns in women MLAs (1955-2014)

Change in women MLAs in Indian states across the years

  • Chart depicts the % change in women MLAs in consecutive state assembly elections.
  • Lack of bars suggests that there is no change in number of MLAs.
  • Every Member of Legislative Assembly (MLA) is elected by people in respective constituency.
  • Election data for all the states for 1971 is not segregated by gender by ECI (Election Commission of India). Hence, missing from the analysis here.
<!DOCTYPE html>
<meta charset="utf-8">
<title>States - women representation trends</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<link href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/0.3.0/css/material.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<style>
.bar.positive {
fill: steelblue;
}
.bar.negative {
fill: brown;
}
.axis text {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
body {
font-family: 'Lato', sans-serif;
}
img {
width: 5%;
height: 5%;
}
a.hack {
min-width: 10px;
visibility: hidden;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<script src="underscore-min.js"></script>
<body>
<div class="container">
<h3 class="text-center">Explore state-wise women MLA trends for all the assembly election years (1955-2014)</h3>
<select id="states"></select>
<div class="row">
<div class="col-md-6">
<div class="svg"></div>
</div>
<div class="col-md-6">
<div class="row">
<div class="table">
</div>
</div>
<div class="row chart-info">
<ul class="list-unstyled">
<li>* Chart depicts the % change in women MLAs in consecutive state assembly elections.</li>
<li>* Lack of bars suggests that there is no change in number of MLAs.</li>
<li>* Every Member of Legislative Assembly (MLA) is elected by people in respective constituency.</li>
<li>* Election data for all the states for 1971 is not segregated by gender by ECI (Election Commission of India). Hence, missing from the analysis here.</li>
</ul>
</div>
</div>
</div>
<script>
var margin = {top: 75, right: 10, bottom: 40, left: 40},
width = 460 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var y_toyear_width = width - 25,
y_fromyear_width = 30;
var x = d3.scale.linear()
.range([0, width-20]);
var y = d3.scale.ordinal()
.rangeRoundBands([0, height], .2);
var y_fromyear = d3.scale.ordinal()
.rangeRoundBands([0, height], 0.2);
var y_toyear = d3.scale.ordinal()
.rangeRoundBands([0, height], 0.2);
var xAxis = d3.svg.axis()
.scale(x)
.orient("top");
var yAxisToYear = d3.svg.axis()
.scale(y_toyear)
.orient("right")
.tickSize(0);
var yAxisFromYear = d3.svg.axis()
.scale(y_fromyear)
.orient("right")
.tickSize(0);
var svg = d3.select(".svg").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("text")
.attr("x", 65)
.attr("y", -35)
.text("% Decrease | % Increase")
/*svg.append("text")
.attr("x", -25)
.attr("y", 400)
.text("How to read: Women MLA representation decreased by 47% in 2014 compared to 2009");*/
function loadTable(data, columns) {
// http://jsfiddle.net/7WQjr/
$(".table").html("<h4>No. women MLAs per election year</h4>");
var table = d3.select(".table").append("table"),
thead = table.append("thead"),
tbody = table.append("tbody");
// append the header row
thead.append("tr")
.selectAll("th")
.data(columns)
.enter()
.append("th")
.text(function(column) {
if(column.indexOf('Previous') === 0) {
return column.split('Previous ')[1] + " - ";
} else if(column.indexOf('Constituencies') === 0) {
return " Seats -";
} else if(column.indexOf('Percentage') === 0) {
return " Women MLAs %";
} else {
return column + " - ";
}
});
// create a row for each object in the data
var rows = tbody.selectAll("tr")
.data(data)
.enter()
.append("tr");
// create a cell in each row for each column
var cells = rows.selectAll("td")
.data(function(row) {
return columns.map(function(column) {
return {column: column, value: row[column]};
});
})
.enter()
.append("td")
.text(function(d) { return d.value; });
return table;
}
var nest = d3.nest()
.key(function(d) {
return d.State;
});
function drawAxes(data) {
x.domain(d3.extent(data, function(d) { return d.value; })).nice();
y.domain(data.map(function(d) { return d['Next year']; }));
y_toyear.domain(data.map(function(d) { return d['Next year']; }));
y_fromyear.domain(data.map(function(d) { return d['Election year']; }));
}
d3.csv("states-mlas-change.csv", type, function(error, data) {
var dataByState = nest.entries(data);
$("select#states").on("change", function() {
var selectedStateKey = $("select").val();
if(selectedStateKey) {
// removes data from existing table, if any
if($(".table").length) {
$(".table").empty();
}
// removes existing y axes and rectangles, if any
if($("svg").length) {
d3.selectAll(".bar").remove();
d3.selectAll(".y.axis").remove();
d3.selectAll(".x.axis").remove();
}
var table = loadTable(dataByState[selectedStateKey].values, ["Election year", "Previous #MLAs", "Constituencies", "Percentage"]);
var lastVal = dataByState[selectedStateKey].values[dataByState[selectedStateKey].values.length-1];
$("table").append("<tr><td>" + lastVal["Next year"] + "</td><td>" + lastVal["Next #MLAs"] + "</td><td>" + lastVal["Constituencies"] + "</td><td>" + lastVal["Percentage"] + "</td></tr>");
// dataByState[0].values
drawAxes(dataByState[selectedStateKey].values);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + y_toyear_width + ", 0)")
.call(yAxisToYear);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(-" + y_fromyear_width + ", 0)")
.call(yAxisFromYear);
// removes lines from y axis
d3.selectAll("path").remove();
svg.selectAll(".bar")
.data(dataByState[selectedStateKey].values)
.enter().append("rect")
.attr("class", function(d) { return d.value < 0 ? "bar negative" : "bar positive"; })
.attr("x", function(d) { return x(Math.min(0, d.value)); })
.attr("y", function(d) { return y(d['Next year']); })
.attr("width", function(d) { return Math.abs(x(d.value) - x(0)); })
.attr("height", y.rangeBand());
svg.append("g")
.attr("class", "x axis")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.append("line")
.attr("x1", x(0))
.attr("x2", x(0))
.attr("y2", height);
$(".table").css("font-size", "14px");
svg.selectAll("g")
.attr("font-size", "14px");
}
});
});
function type(d) {
d.value = +d.value;
return d;
}
</script>
<script>
$(document).ready(function() {
var states = ['Andhra Pradesh', 'Arunachal Pradesh', 'Assam', 'Bihar', 'Chhattisgarh', 'Delhi', 'Goa', 'Gujarat', 'Haryana', 'Himachal Pradesh', 'Jammu Kashmir', 'Jharkhand', 'Karnataka', 'Kerala', 'Madhya Pradesh', 'Maharashtra', 'Manipur', 'Meghalaya', 'Mizoram', 'Orissa', 'Pondicherry', 'Punjab', 'Rajasthan', 'Sikkim', 'Tamil Nadu', 'Tripura', 'Uttar Pradesh', 'Uttarakhand', 'West Bengal'];
$("#states").append('<option value="state">Select state</option>');
for(iter=0; iter<states.length; iter++) {
$("#states").append('<option value="' + iter + '">' + states[iter] + '</option>');
}
});
</script>
</div>
</body>
</html>
State Election year Next year Previous #MLAs Next #MLAs value Constituencies Percentage
Andhra Pradesh 1957 1962 7 10 42 85 8
Andhra Pradesh 1962 1967 10 11 10 300 3
Andhra Pradesh 1967 1978 11 10 -10 287 3
Andhra Pradesh 1978 1983 10 11 10 294 3
Andhra Pradesh 1983 1985 11 10 -10 294 3
Andhra Pradesh 1985 1989 10 17 70 294 3
Andhra Pradesh 1989 1994 17 8 -53 294 5
Andhra Pradesh 1994 1999 8 28 250 294 2
Andhra Pradesh 1999 2004 28 26 -8 294 9
Andhra Pradesh 2004 2009 26 34 30 294 8
Andhra Pradesh 2009 2014 34 18 -48 294 11
Arunachal Pradesh 1980 1984 1 2 100 30 3
Arunachal Pradesh 1984 1990 2 1 -50 30 6
Arunachal Pradesh 1990 1995 1 1 0 60 1
Arunachal Pradesh 1995 1999 1 1 0 60 1
Arunachal Pradesh 1999 2009 1 2 100 60 1
Arunachal Pradesh 2009 2014 2 2 0 60 3
Assam 1957 1962 5 4 -20 94 5
Assam 1962 1967 4 4 0 105 3
Assam 1967 1978 4 1 -75 126 3
Assam 1978 1983 1 2 100 126 0
Assam 1983 1985 2 5 150 109 1
Assam 1985 1991 5 5 0 126 3
Assam 1991 1996 5 6 20 126 3
Assam 1996 2001 6 10 66 122 4
Assam 2001 2006 10 13 30 126 7
Assam 2006 2011 13 14 7 126 10
Bihar 1957 1962 30 25 -17 264 11
Bihar 1962 1967 25 6 -76 318 7
Bihar 1967 1969 6 4 -34 318 1
Bihar 1969 1977 4 13 225 318 1
Bihar 1977 1980 13 11 -16 324 4
Bihar 1980 1985 11 15 36 324 3
Bihar 1985 1990 15 10 -34 324 4
Bihar 1990 1995 10 11 10 324 3
Bihar 1995 2000 11 19 72 324 3
Bihar 2000 20051 19 3 -85 324 5
Bihar 20051 20052 3 25 733 243 1
Bihar 20052 2010 25 34 36 243 10
Chhattisgarh 2003 2008 5 11 120 90 5
Chhattisgarh 2008 2013 11 10 -10 90 12
Delhi 1972 1977 3 4 33 56 5
Delhi 1977 1983 4 4 0 56 7
Delhi 1983 1993 4 3 -25 58 6
Delhi 1993 1998 3 9 200 70 4
Delhi 1998 2003 9 7 -23 70 12
Delhi 2003 2008 7 3 -58 70 10
Delhi 2008 2013 3 3 0 70 4
Delhi 2013 0 3 0 -100 70 4
Goa 1967 1977 1 1 0 30 3
Goa 1977 1989 1 2 100 30 3
Goa 1989 1994 2 4 100 40 5
Goa 1994 1999 4 2 -50 40 10
Goa 1999 2002 2 1 -50 40 5
Goa 2002 2007 1 1 0 40 2
Goa 2007 2012 1 1 0 40 2
Gujarat 1962 1967 11 8 -28 154 7
Gujarat 1967 1972 8 1 -88 168 4
Gujarat 1972 1975 1 3 200 168 0
Gujarat 1975 1980 3 5 66 181 1
Gujarat 1980 1985 5 16 220 182 2
Gujarat 1985 1990 16 4 -75 182 8
Gujarat 1990 1995 4 2 -50 182 2
Gujarat 1995 1998 2 4 100 182 1
Gujarat 1998 2002 4 12 200 182 2
Gujarat 2002 2007 12 16 33 182 6
Gujarat 2007 2012 16 16 0 182 8
Haryana 1968 1977 7 4 -43 81 8
Haryana 1977 1982 4 7 75 90 4
Haryana 1982 1987 7 5 -29 90 7
Haryana 1987 1991 5 6 20 90 5
Haryana 1991 1996 6 4 -34 90 6
Haryana 1996 2000 4 4 0 90 4
Haryana 2000 2005 4 11 175 90 4
Haryana 2005 2009 11 9 -19 90 12
Haryana 2009 2014 9 13 44 90 10
Himachal Pradesh 1972 1977 4 1 -75 68 5
Himachal Pradesh 1977 1982 1 3 200 68 1
Himachal Pradesh 1982 1985 3 3 0 68 4
Himachal Pradesh 1985 1990 3 4 33 68 4
Himachal Pradesh 1990 1993 4 3 -25 67 5
Himachal Pradesh 1993 1998 3 6 100 68 4
Himachal Pradesh 1998 2003 6 4 -34 68 8
Himachal Pradesh 2003 2007 4 5 25 68 5
Himachal Pradesh 2007 2012 5 3 -40 68 7
Jammu Kashmir 1972 1977 4 1 -75 75 5
Jammu Kashmir 1977 1987 1 1 0 76 1
Jammu Kashmir 1987 1996 1 2 100 76 1
Jammu Kashmir 1996 2002 2 2 0 87 2
Jammu Kashmir 2002 2008 2 3 50 87 2
Jammu Kashmir 2008 0 3 0 -100 87 3
Jharkhand 2005 2009 3 8 166 81 3
Karnataka 1957 1962 13 18 38 179 7
Karnataka 1962 1967 18 5 -73 208 8
Karnataka 1967 1978 5 8 60 216 2
Karnataka 1978 1983 8 1 -88 224 3
Karnataka 1983 1985 1 8 700 216 0
Karnataka 1985 1989 8 10 25 224 3
Karnataka 1989 1994 10 7 -30 224 4
Karnataka 1994 1999 7 6 -15 224 3
Karnataka 1999 2004 6 6 0 224 2
Karnataka 2004 2008 6 3 -50 224 2
Karnataka 2008 2013 3 6 100 224 1
Kerala 1957 1960 6 7 16 114 5
Kerala 1960 1965 7 3 -58 208 3
Kerala 1965 1967 3 1 -67 133 2
Kerala 1967 1977 1 1 0 133 0
Kerala 1977 1980 1 5 400 140 0
Kerala 1980 1982 5 4 -20 140 3
Kerala 1982 1987 4 8 100 140 2
Kerala 1987 1991 8 8 0 140 5
Kerala 1991 1996 8 13 62 140 5
Kerala 1996 2001 13 8 -39 140 9
Kerala 2001 2006 8 7 -13 140 5
Kerala 2006 2011 7 7 0 140 5
Madhya Pradesh 1957 1962 15 15 0 218 6
Madhya Pradesh 1962 1967 15 10 -34 288 5
Madhya Pradesh 1967 1977 10 10 0 296 3
Madhya Pradesh 1977 1980 10 18 80 320 3
Madhya Pradesh 1980 1985 18 31 72 320 5
Madhya Pradesh 1985 1990 31 11 -65 320 9
Madhya Pradesh 1990 1993 11 12 9 320 3
Madhya Pradesh 1993 1998 12 26 116 320 3
Madhya Pradesh 1998 2003 26 19 -27 320 8
Madhya Pradesh 2003 2008 19 25 31 230 8
Madhya Pradesh 2008 2013 25 30 20 230 10
Maharashtra 1962 1967 13 9 -31 264 4
Maharashtra 1967 1978 9 8 -12 270 3
Maharashtra 1978 1980 8 19 137 288 2
Maharashtra 1980 1985 19 16 -16 288 6
Maharashtra 1985 1990 16 6 -63 288 5
Maharashtra 1990 1995 6 11 83 288 2
Maharashtra 1995 1999 11 12 9 288 3
Maharashtra 1999 2004 12 12 0 288 4
Maharashtra 2004 2009 12 11 -9 288 4
Manipur 1990 2000 1 1 0 54 1
Manipur 2000 2002 1 1 0 60 1
Manipur 2002 2012 1 3 200 60 1
Meghalaya 1978 1988 1 2 100 60 1
Meghalaya 1988 1993 2 1 -50 60 3
Meghalaya 1993 1998 1 3 200 60 1
Meghalaya 1998 2003 3 2 -34 60 5
Meghalaya 2003 2008 2 1 -50 60 3
Meghalaya 2008 2013 1 4 300 60 1
Mizoram 1978 1979 1 1 0 30 3
Mizoram 1979 1987 1 1 0 30 3
Orissa 1957 1961 5 3 -40 101 4
Orissa 1961 1967 3 5 66 140 2
Orissa 1967 1974 5 4 -20 140 3
Orissa 1974 1977 4 7 75 146 2
Orissa 1977 1980 7 5 -29 147 4
Orissa 1980 1985 5 8 60 147 3
Orissa 1985 1990 8 7 -13 147 5
Orissa 1990 1995 7 8 14 147 4
Orissa 1995 2000 8 13 62 147 5
Orissa 2000 2004 13 11 -16 147 8
Orissa 2004 2009 11 7 -37 147 7
Orissa 2009 2014 7 11 57 147 4
Pondicherry 1964 1969 2 1 -50 30 6
Pondicherry 1969 1980 1 1 0 30 3
Pondicherry 1980 1985 1 1 0 30 3
Pondicherry 1985 1991 1 1 0 30 3
Pondicherry 1991 1996 1 1 0 30 3
Punjab 1957 1962 9 8 -12 121 7
Punjab 1962 1967 8 2 -75 154 5
Punjab 1967 1972 2 6 200 140 1
Punjab 1972 1977 6 3 -50 104 5
Punjab 1977 1980 3 6 100 117 2
Punjab 1980 1985 6 4 -34 117 5
Punjab 1985 1992 4 6 50 117 3
Punjab 1992 1997 6 7 16 117 5
Punjab 1997 2002 7 8 14 117 5
Punjab 2002 2007 8 7 -13 117 6
Rajasthan 1957 1962 8 8 0 136 5
Rajasthan 1962 1967 8 6 -25 176 4
Rajasthan 1967 1972 6 4 -34 184 3
Rajasthan 1972 1977 4 7 75 184 2
Rajasthan 1977 1980 7 10 42 200 3
Rajasthan 1980 1985 10 16 60 200 5
Rajasthan 1985 1990 16 11 -32 200 8
Rajasthan 1990 1993 11 9 -19 200 5
Rajasthan 1993 1998 9 14 55 199 4
Rajasthan 1998 2003 14 12 -15 200 7
Rajasthan 2003 2008 12 28 133 200 6
Rajasthan 2008 2013 28 28 0 200 14
Sikkim 1989 1994 1 1 0 32 3
Sikkim 1994 1999 1 1 0 32 3
Sikkim 1999 2004 1 3 200 32 3
Sikkim 2004 2009 3 4 33 32 9
Sikkim 2009 2014 4 3 -25 32 12
Tamil Nadu 1967 1977 3 2 -34 234 1
Tamil Nadu 1977 1980 2 5 150 234 0
Tamil Nadu 1980 1984 5 8 60 234 2
Tamil Nadu 1984 1989 8 9 12 234 3
Tamil Nadu 1989 1991 9 32 255 234 3
Tamil Nadu 1991 1996 32 9 -72 234 13
Tamil Nadu 1996 2001 9 25 177 234 3
Tamil Nadu 2001 2006 25 22 -12 234 10
Tamil Nadu 2006 2011 22 17 -23 234 9
Tripura 1977 1983 1 4 300 60 1
Tripura 1983 1988 4 2 -50 60 6
Tripura 1988 1993 2 1 -50 60 3
Tripura 1993 1998 1 2 100 60 1
Tripura 1998 2003 2 2 0 60 3
Tripura 2003 2008 2 3 50 60 3
Tripura 2008 2013 3 5 66 60 5
Uttar Pradesh 1957 1962 18 20 11 341 5
Uttar Pradesh 1962 1967 20 6 -70 430 4
Uttar Pradesh 1967 1969 6 18 200 425 1
Uttar Pradesh 1969 1974 18 21 16 425 4
Uttar Pradesh 1974 1977 21 11 -48 425 4
Uttar Pradesh 1977 1980 11 23 109 425 2
Uttar Pradesh 1980 1985 23 31 34 425 5
Uttar Pradesh 1985 1989 31 18 -42 425 7
Uttar Pradesh 1989 1991 18 10 -45 425 4
Uttar Pradesh 1991 1993 10 14 40 419 2
Uttar Pradesh 1993 1996 14 20 42 422 3
Uttar Pradesh 1996 2002 20 26 30 424 4
Uttar Pradesh 2002 2007 26 23 -12 403 6
Uttar Pradesh 2007 2012 23 35 52 403 5
Uttarakhand 2002 2007 4 4 0 70 5
Uttarakhand 2007 2012 4 5 25 69 5
West Bengal 1957 1962 6 10 66 195 3
West Bengal 1962 1967 10 9 -10 252 3
West Bengal 1967 1969 9 7 -23 280 3
West Bengal 1969 1977 7 3 -58 280 2
West Bengal 1977 1982 3 5 66 294 1
West Bengal 1982 1987 5 12 140 294 1
West Bengal 1987 1991 12 21 75 294 4
West Bengal 1991 1996 21 20 -5 294 7
West Bengal 1996 2001 20 28 40 294 6
West Bengal 2001 2006 28 37 32 294 9
West Bengal 2006 2011 37 34 -9 294 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment