ui.Chart.image.histogram

根据图片生成图表。计算并绘制指定图像区域中各波段值的直方图。

  - X 轴:直方图分桶(频段值)。

  - Y 轴:频次(具有相应波段值的像素数量)。

返回图表。

用法返回
ui.Chart.image.histogram(image, region, scale, maxBuckets, minBucketWidth, maxRaw, maxPixels)ui.Chart
参数类型详细信息
image图片要从中生成直方图的图片。
regionFeature|FeatureCollection|Geometry,可选要缩减的区域。如果省略,则使用整个图片。
scale数字,可选应用直方图缩减器时使用的像素比例(以米为单位)。
maxBuckets数字,可选构建直方图时要使用的最大分桶数;将向上舍入为 2 的幂。
minBucketWidth数字,可选最小直方图分桶宽度,如果为 null,则允许任何 2 的幂。
maxRaw数字,可选在构建初始直方图之前要累积的值的数量。
maxPixels数字,可选如果指定,则会替换直方图缩减中允许的最大像素数。默认值为 1e6。

示例

代码编辑器 (JavaScript)

// Define a MODIS surface reflectance composite.
var modisSr = ee.ImageCollection('MODIS/006/MOD09A1')
                  .filter(ee.Filter.date('2018-06-01', '2018-09-01'))
                  .select(['sur_refl_b01', 'sur_refl_b02', 'sur_refl_b06'])
                  .mean();

// Define a region to calculate histogram for.
var histRegion = ee.Geometry.Rectangle([-112.60, 40.60, -111.18, 41.22]);

// Define the chart and print it to the console.
var chart =
    ui.Chart.image.histogram({image: modisSr, region: histRegion, scale: 500})
        .setSeriesNames(['Red', 'NIR', 'SWIR'])
        .setOptions({
          title: 'MODIS SR Reflectance Histogram',
          hAxis: {
            title: 'Reflectance (scaled by 1e4)',
            titleTextStyle: {italic: false, bold: true},
          },
          vAxis:
              {title: 'Count', titleTextStyle: {italic: false, bold: true}},
          colors: ['cf513e', '1d6b99', 'f0af07']
        });
print(chart);