In this recipe, we will look at how to explore the properties of a column of numeric values. We will look at the tools that QGIS offers and apply them to analyze the elevation values in our sample POI dataset.
To follow this recipe, please load poi_names_wake.shp. If you followed the previous recipe, Listing unique values in a column, you can continue directly from there.
A good way to get a first impression of the properties of a numeric column is using the Basic Statistics tool from Vector. This allows you to calculate statistical values, such as the minimum and maximum values, mean and median, standard deviation, and sum.
If you want to examine the distribution of elevation values, there is the handy Statist plugin. Statist generates an interactive histogram representation of the value distribution:

Thanks to Python Console and the editor, we are not limited to the existing tools and plugins. Instead, we can create or own specialized scripts such as the following one. This script creates a short layer statistics report using HTML and the Google Charts Javascript API (for more information and API docs refer to https://developers.google.com/chart/), which it then displays in a QWebView window. Of course, you can use any other JavaScript charting API as well. (Note that you need to be connected to the Internet for this script to work because it has to download the Javascript.) We recommend using the editor that was introduced in the previous recipe. Don't forget to select the layer in the legend:
import processing
from PyQt4.QtWebKit import QWebView
layer = iface.activeLayer()
values = []
features = processing.features(layer)
for f in features:
values.append( f['elev_m'])
myWV = wQWebView(None)
html='<html><head><script type="text/javascript"'
html+='src="https://www.google.com/jsapi"></script>'
html+='<script type="text/javascript">'
html+='google.load("visualization","1",{packages:["corechart"]});'
html+='google.setOnLoadCallback(drawChart);'
html+='function drawChart() { '
html+='var data = google.visualization.arrayToDataTable(['
html+='["%s"],' % (field_name)
for value in values:
html+='[%f],' % (value)
html+=']);'
html+='var chart = new google.visualization.Histogram('
html+='document.getElementById("chart_div"));'
html+='chart.draw(data, {title: "Histogram"});}</script></head>'
html+='<body><h1>Layer: %s</h1>' % (layer.name())
html+='<p>Values for %s range from: ' % (field_name)
html+='%d to %d</p>' % (min(values),max(values))
html+='<div id="chart_div"style="width:900px; height:500px;">'
html+='</div></body></html>'
myWV.setHtml(html)
myWV.show()Of course, custom reports such as this one lend themselves to adding more details. For example, we can create separate histograms for each POI class or add other types of charts, such as scatter charts:

The first part (lines 1 to 12) is very similar to the script explained in the previous recipe, Listing unique values in a column: We get the active layer and collect all elevation values in the values list.
The QWebView created on line 14 enables us to display the HTML content, which we then generate in the following section (lines 16 to 34). First, we load the Google Charts Javascript. The actual magic happens in the drawChart() function starting on line 21. Lines 22 to 26 create the data object, which is filled with the elevation values from our values list. The last three lines of the function (lines 27 to 29) finally create and draw the histogram chart. Finally, lines 30 to 34 contain the HTML body definition with the header stating the layer name and a short introduction text that states the min and max elevation values.