Tuesday, 31 January 2017

Seaborn for informative graphs in python - 31/01/2017

SEABORN FOR INFORMATIVE GRAPHS IN PYTHON

  • ABOUT SEABORN 
Seaborn is a library for making attractive and informative statistical graphics in Python. It is built on top of matplotlib and tightly integrated with the PyData stack, including support for numpy and pandas data structures and statistical routines from scipy and statsmodels.

Seaborn offers the following features-
  1. Tools that fit and visualize linear regression models for different kinds of independent and dependent variables
  2. Functions that visualize matrices of data and use clustering algorithms to discover structure in those matrices
  3.  A function to plot statistical timeseries data with flexible estimation and representation of uncertainty around the estimate
  4. Some of the functions plot directly into a matplotlib axes object, while others operate on an entire figure and produce plots with several panels. In the latter case, the plot is drawn using a Grid object that links the structure of the figure to the structure of the dataset in an abstract way. 
  5.  Because seaborn uses matplotlib, the graphics can be further tweaked using matplotlib tools and rendered with any of the matplotlib backends to generate publication-quality figures. Seaborn can also be used to target web-based graphics through the mpld3 and Bokeh libraries. 
  • USING SEABORN TO PLOT GRAPHS IN PYTHON-
Installing Seaborn-



Importing the required libraries-



Graph 1 -

Loading the dataset brain_networks -> Select a subset of the networks -> Create a custom palette to identify the networks -> Convert the palette to vectors that will be drawn on the side of the matrix ->  Create a custom heatmap for the heatmap values -> Draw the full plot



Graph 2-




Graph 3-

Load the long-form example gammas dataset -> Plot the response with standard error



Graph 4 -

Generate an example radial dataset -> Convert the dataframe to long form -> Set up a grid of axes with a polar projection -> Draw a scatterplot onto each axes in the grid.



Tuesday, 24 January 2017

Plotting specific addresses - 25/01/2017


Plotting schools of Kolkata alongwith my own school " City Montessori School , Lucknow "

Plotting states on a map - 25/01/2017


Plotting cities on map - 25/01/2017


Monday, 23 January 2017

D3js- Treemap 20/01/2017


HTML Iframes

Treemap

Creating interactive google chart - Dashboard 2



Basic Column Chart Showing All Data

DATA SOURCE

Creating interactive google chart - Dashboard 1



Basic Column Chart Showing All Data

DATA SOURCE

Data visualization - Specifying the range of data and selecting columns



Data from a Spreadsheet

The Chart below displays the the poverty among the top 10 states of INDIA


=========================================================================================================
  " the code for the above Google chart is displayed Below "


<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", '1', {packages:['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
  var query = new google.visualization.Query(
      'https://docs.google.com/spreadsheets/d/1BiBAL-DDDj2kpk8Gqohi_aV42FfcsBokUk7G2JysbRs/edit?usp=sharing');

  query.send(handleQueryResponse);
}

function handleQueryResponse(response) {
  if (response.isError()) {
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
    return;
  }

  var data = response.getDataTable();
  var options = {'title'

Sunday, 15 January 2017

Google charts using google docs


Data from a Spreadsheet

========================================
   <div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", '1', {packages:['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
  var query = new google.visualization.Query(
      'https://docs.google.com/spreadsheets/d/1ZKpGtoWg5yz_TX8CbadBVNJVaR_k4yIE81q0qpuEPLE/edit?usp=sharing');

  query.send(handleQueryResponse);
}

function handleQueryResponse(response) {
  if (response.isError()) {
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
    return;
  }

  var data = response.getDataTable();
  var options = {'title':'Crime among children 2011',
                       'width':400,
                       'height':600};
  var chart = new google.visualization.PieChart(document.getElementById('columnchart'));
  chart.draw(data, options);
}
</script>

<title>Data from a Spreadsheet</title>
</head>

<body>
<span id='columnchart'></span>
</body>
========================================

Wednesday, 11 January 2017

12/01/2017 - Basic Google Chart


========================================
   <!--Load the AJAX API-->
    <script src="https://www.google.com/jsapi" type="text/javascript"></script>
    <script type="text/javascript">

      // Load the Visualization API and the piechart package.
      google.load('visualization', '1.0', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Topping');
        data.addColumn('number', 'Slices');
        data.addRows([
          ['Mushrooms', 3],
          ['Onions', 1],
          ['Olives', 1],
          ['Zucchini', 1],
          ['Pepperoni', 2]
        ]);

        // Set chart options
        var options = {'title':'How Much Pizza I Ate Last Night',
                       'width':400,
                       'height':300};

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div1'));
        chart.draw(data, options);
      }
    </script>
========================================

Data Visualisation : An Introduction to GGPlot2 ( 05/01/2017 )



DATA VISUALIZATION USING GGPLOT2

BASIC

Visualizations bring data to life. A good visualization will give you new insights and will often lead to new ideas for additional analyses or visualizations. As humans we are much better at processing visual information than numeric information - both in terms of comprehension and speed. 

The ggplot2 library is one of the gems of R. The syntax for producing plots may appear at bit strange at first, but once we “get it”, it will be easy to  produce beautiful and insightful visualizations in no time. With ggplot2 one can  create visualizations by adding layers to a plot.
  • Any plot in ggplot2 consists of
    • Data
    • Aesthetics: which variables go on the x-axis, y-axis, colors, styles etc.
    • Style of plot: Bar, scatter, line etc. These are called plot layers in ggplot and are specified using the syntax geom_layer, e.g., geom_pointgeom_linegeom_histogram etc.
Let’s get some data to plot. We will be working with Iris dataset which is a pre installed dataframe in R.


  • GLIMPSE  OF THE DATASET 





  • USING HEAD( )  FUNCTION TO VIEW THE FIRST FEW OBSERVATIONS






  • USING FUNCTION QPLOT( )
Firstly , we will plot sepal. length against petal.length and obtain the plot. Sepal.Length goes into the x axis , Petal.Length goes into the y axis and data refers to the iris dataframe. Here we have used a single color to denote all the points of the different species. 


We can also represent the different species by different colors as shown below using color=Species argument.

Similarly, we can let the size of each point denote sepal width, by adding a size = Sepal.Width argument. The scatter plot shown below is the modified version of the above plot in which an additional size agrument is added while plotting the two variables , this argument increases the size of the petal.width ,which increases the size of the dots in the scatter plots denoting the petal.width. Here we see that the Iris Setosa flowers have the smallest petals.


Here we see that we can add the value of alpha to avoid over plotting . So we add an argument  called alpha with a  value of  0.7 , to reduce the affects of over plotting 
Alpha transparency for overlapping elements expressed as a fraction between 0 (complete transparency) and 1 (complete opacity).


We add the axes labels and titles to the plot.


Specifies the geometric objects that define the graph type. The geom option is expressed as a character vector with one or more entries. geom values include "point", "smooth", "boxplot", "line", "histogram", "density", "bar", and "jitter".


In the scatterplot examples above, we implicitly used a point geom, the default when you supply two arguments to qplot().



In this plot we use the geometric object as line to define the graph object in the graph below the lines of different  colors shows the different species of the flowers plotted  below .


Orange is another built in data-frame that describes the growth of orange trees. Variation of orange tree circumference with age.


We can also plot both points and lines.




ADVANCED