Histograms

Use ui.Chart.image.histogram to get a column chart representing the histogram of band values in a region. Consider the following example which creates a histogram of Landsat 8 DNs in an arbitrary region and uses setOptions() to style the chart:

// Load a Landsat 8 image's reflective bands.
var image = ee.Image('LANDSAT/LC8_L1T/LC80440342014077LGN00').select('B[2-5]');

// Define an arbitrary region over San Francisco.
var region = ee.Geometry.Rectangle(-122.45, 37.74, -122.4, 37.8);

// Pre-define some customization options.
var options = {
  title: 'Landsat 8 DN histogram, bands 2-5',
  fontSize: 20,
  hAxis: {title: 'DN'},
  vAxis: {title: 'count of DN'},
  series: {
    0: {color: 'blue'},
    1: {color: 'green'},
    2: {color: 'red'},
    3: {color: 'magenta'}}
};

// Make the histogram, set the options.
var histogram = ui.Chart.image.histogram(image, region, 30)
    .setSeriesNames(['blue', 'green', 'red', 'NIR'])
    .setOptions(options);

// Display the histogram.
print(histogram);
    

Observe that the chart is customizable with an object of configuration parameters. Use these parameters to control fonts, colors, axis titles and other display characteristics of the chart. The chart gallery is useful for understanding the configuration options available for a particular chart type. The result should look something like Figure 1. (You may need to pop out the chart into a new page to see the legend and x-axis labels).

ui.Chart.image.histogram
Figure 1. Histogram of Landsat 8 DNs in San Francisco, CA, USA.

Send feedback about...

Google Earth Engine API