המודול ui.Chart.image
מכיל קבוצה של פונקציות לצמצום אובייקטים מסוג Image
לפי אזורים וליצור תרשימים מהתוצאות. בחירת הפונקציה קובעת את סידור הנתונים בתרשים, כלומר מה מגדיר את הערכים של ציר ה-x וציר ה-y ומה מגדיר את הסדרה. תוכלו להיעזר בתיאורים ובדוגמאות הבאים כדי לקבוע מהי הפונקציה וסוג התרשים המתאימים ביותר למטרה שלכם.
פונקציות של תרשימים
אפשר להיעזר בתרשים התרשימים הבא כמדריך חזותי כדי להבין איך כל פונקציה מסדרת את התוצאות של צמצום אזור התמונה בתרשים. כלומר, אילו רכיבים מגדירים את ערכי x, ערכי y וסדרות.
אזורי ההפחתה מוצגים על ציר ה-X, עם תוויות של ערכים של מאפיין תכונה שנבחר. הסדרות מוגדרות לפי שמות של פסגות, ותוצאות הפחתת האזור שלהן מוצגות על ציר ה-y.
הלהקות מוצגות בציר ה-x. הסדרות מסומנות לפי ערכים של מאפיין. צמצום האזור שמוגדר על ידי הגיאומטריה של מאפייני הסדרות הרלוונטיות מוצג על ציר ה-y.
רצועות הנתונים מוצגות לאורך ציר ה-x. סדרות מיוצגות על ידי ערכים ייחודיים בפס של הכיתה. המיקום של ציר ה-Y מוגדר לפי תוצאות הפחתת האזור של הפיקסלים שמרכיבים כל סדרה.
תרשים היסטוגרמה של תדירות לערכים של הלהקות שנבחרו.
- ציר X: קטגוריות של היסטוגרמה לערכים של הלהקות שנבחרו
- ציר Y: תדירות הפיקסלים שעומדים בדרישות לכל קטגוריה בתרשים ההיסטוגרמה
נתונים לדוגמה
הדוגמאות הבאות מבוססות על FeatureCollection
שמורכב משלושה מאפייני אזור אקולוגי שמגדירים אזורים שבהם רוצים לצמצם את נתוני התמונות. נתוני Image
הם נתונים רגילים של אקלים PRISM, שבהם פסגות מתארות משתני אקלים לפי חודש. לדוגמה: כמות המשקעים ביולי או הטמפרטורה הממוצעת בינואר.
איך נוצר הנכס הזה
ui.Chart.image.byRegion
תרשים עמודות אנכי
בדוגמה הזו, רצועות התמונה שמייצגות את הטמפרטורה החודשית הממוצעת מצטמצמות לממוצע בין הפיקסלים שחופפים לכל אחד משלושת האזורים האקולוגיים. התוצאות מוצגות כעמודות לפי חודש לפי אזור אקולוגי, כאשר גובה העמודה מציין את הטמפרטורה החודשית הממוצעת הרלוונטית.
Code Editor (JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Load PRISM climate normals image collection; convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Define the chart and print it to the console. var chart = ui.Chart.image .byRegion({ image: normClim.select('[0-9][0-9]_tmean'), regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, xProperty: 'label' }) .setSeriesNames([ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]) .setChartType('ColumnChart') .setOptions({ title: 'Average Monthly Temperature by Ecoregion', hAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, vAxis: { title: 'Temperature (°C)', titleTextStyle: {italic: false, bold: true} }, colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ] }); print(chart);
תרשים עמודות
אפשר להציג את תרשים העמודות הקודם בתור תרשים עמודות אופקי על ידי שינוי הקלט .setChartType()
מ-'ColumnChart'
ל-'BarChart'
.
var chart = ui.Chart.image .byRegion({ image: normClim.select('[0-9][0-9]_tmean'), regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, xProperty: 'label' }) .setSeriesNames([ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]) .setChartType('BarChart') .setOptions({ title: 'Average Monthly Temperature by Ecoregion', hAxis: { title: 'Temperature (°C)', titleTextStyle: {italic: false, bold: true} }, vAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ] });
תרשים עמודות אנכי מוערם
אפשרות התרשים isStacked
קובעת אם העמודות בתרשים יהיו מוערמות או לא.
יש כמה אפשרויות למעקב אחרי מודעות. בדוגמאות הבאות מוסבר איך משתמשים באפשרויות 'absolute'
ו-'relative'
.
גובה מסוים
תרשים עמודות מוערם מוחלט משווה בין הסכום הכולל של משתנה מספרי לבין העליות בסדרה של משתנה קטגורי תורם. לדוגמה, בדוגמה הזו, כמות המשקעים הכוללת מוצגת כצבירת המשקעים החודשיים במהלך שנה, לפי אזור אקולוגי. הסכומים הכוללים של המשקעים החודשיים נגזרים מפסלי תמונה, שבהם כל פס מייצג רשת של משקעים כוללים ממוצעים בחודש נתון, שמופחתים לממוצע של הפיקסלים שחופפים לכל אחד משלושת האזורים האקולוגיים. אפשרות התרשים isStacked
מוגדרת ל-'absolute'
כדי לעצב את התוצאות כערכים מוחלטים.
Code Editor (JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Load PRISM climate normals image collection; convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Define the chart and print it to the console. var chart = ui.Chart.image .byRegion({ image: normClim.select('[0-9][0-9]_ppt'), regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, xProperty: 'label' }) .setSeriesNames([ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]) .setChartType('ColumnChart') .setOptions({ title: 'Average Monthly Precipitation by Ecoregion', hAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, vAxis: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true} }, colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ], isStacked: 'absolute' }); print(chart);
קרוב-משפחה
כדי להמיר את תרשים העמודות המוערם המוחלט הקודם לתרשים עמודות מוערם יחסי, משנים את אפשרות התרשים isStacked
מ-'absolute'
ל-'relative'
. תרשים עמודות מוערם יחסי משווה בין היחס של סדרות של משתנים קטגוריים שתורמים לנתון לבין הסכום הכולל של משתנה מספרי.
לדוגמה, בדוגמה הזו, נתוני המשקעים החודשיים מוצגים בתרשים כיחס למשקעים השנתיים הכוללים, לפי אזור אקולוגי.
var chart = ui.Chart.image .byRegion({ image: normClim.select('[0-9][0-9]_ppt'), regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, xProperty: 'label' }) .setSeriesNames([ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]) .setChartType('ColumnChart') .setOptions({ title: 'Average Monthly Precipitation by Ecoregion', hAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, vAxis: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true} }, colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ], isStacked: 'relative' });
תרשים פיזור
הטמפרטורות הממוצעות בינואר וביולי לדגימה אקראית של מיקומים במדינת קולורדו מוצגות בתרשים כפונקציה של הגובה. דגימת DEM מתבצעת באמצעות הפונקציה sample
שמחזירה FeatureCollection
עם תכונות של גיאומטריה וגובה. לאחר מכן, הערך FeatureCollection
שנוצר משמש כארגומנטים לפרמטר regions
של הפונקציה ui.Chart.image.byRegion
.
הסדרות מוגדרות על ידי פסגות שנבחרו בתמונה של התנאים האקלימיים הרגילים של הקלט.
Code Editor (JavaScript)
// Load SRTM elevation data. var elev = ee.Image('CGIAR/SRTM90_V4').select('elevation'); // Subset Colorado from the TIGER States feature collection. var colorado = ee.FeatureCollection('TIGER/2018/States') .filter(ee.Filter.eq('NAME', 'Colorado')); // Draw a random sample of elevation points from within Colorado. var samp = elev.sample( {region: colorado, scale: 30, numPixels: 500, geometries: true}); // Load PRISM climate normals image collection; convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Define the chart and print it to the console. var chart = ui.Chart.image .byRegion({ image: normClim.select(['01_tmean', '07_tmean']), regions: samp, reducer: ee.Reducer.mean(), scale: 500, xProperty: 'elevation' }) .setSeriesNames(['Jan', 'Jul']) .setChartType('ScatterChart') .setOptions({ title: 'Average Monthly Colorado Temperature by Elevation', hAxis: { title: 'Elevation (m)', titleTextStyle: {italic: false, bold: true} }, vAxis: { title: 'Temperature (°C)', titleTextStyle: {italic: false, bold: true} }, pointSize: 4, dataOpacity: 0.6, colors: ['1d6b99', 'cf513e'], }); print(chart);
תרשים משולב
בתרשים של שלושה אזורים אקולוגיים ב-ee.FeatureCollection
מוצגות הטמפרטורה הממוצעת והמשקעים הממוצעים ביוני. התוצאות נובעות מהצמצום של האזור בתמונה, שבה כל פס הוא רשת של ערכים רגילים של אקלים שמתארים את הטמפרטורה והמשקעים החודשיים. פסים שמייצגים את הטמפרטורה והמשקעים בחודש יוני הם קבוצת משנה. מכיוון שהמשקעים והטמפרטורה נמדדים ביחידות שונות, נעשה שימוש בשני צירי y על ידי הגדרת האפשרויות series
ו-vAxes
. שימו לב לשימוש באפשרות series.targetAxisIndex
כדי להגדיר איזה משתנה יופיע בציור בציר ה-y הימני והשמאלי. סמלים ספציפיים לסדרה (נקודות ועמודות) משמשים כדי להבדיל בקלות רבה יותר בין שני המשתנים שיש להם יחידות שונות.
Code Editor (JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Load PRISM climate normals image collection; convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Define the chart and print it to the console. var chart = ui.Chart.image .byRegion({ image: normClim.select(['06_tmean', '06_ppt']), regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, xProperty: 'label' }) .setSeriesNames(['Precipitation', 'Temperature']) .setChartType('ColumnChart') .setOptions({ title: 'Average June Temperature and Precipitation by Ecoregion', series: { 0: {targetAxisIndex: 1, type: 'bar', color: '1d6b99'}, 1: { targetAxisIndex: 0, type: 'line', lineWidth: 0, pointSize: 10, color: 'e37d05' } }, hAxis: {title: 'Ecoregion', titleTextStyle: {italic: false, bold: true}}, vAxes: { 0: { title: 'Temperature (°C)', baseline: 0, titleTextStyle: {italic: false, bold: true, color: 'e37d05'} }, 1: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true, color: '1d6b99'} }, }, bar: {groupWidth: '40%'}, }); print(chart);
ui.Chart.image.regions
דוגמה להגדרה
הפונקציה ui.Chart.image.regions
מקבלת רשימה שמאפשרת לכם לקבוע את התווית ואת הסדר של שמות הלהקות בציר x על ידי הקצאת ערכים מספריים להם. בתרשים הבא נעשה שימוש באפשרות הזו כדי להגדיר את שמות הפסגות בתור תוויות חודשיות ולמיין אותן בסדר כרונולוגי לפי כמות המשקעים החודשית הממוצעת.
תרשים עמודות אנכי
בתרשים הזה מוצגת כמות המשקעים הממוצעת הכוללת לחודש בשלושה אזורים אקולוגיים.
התוצאות נובעות מצמצום האזור של תמונה, שבה כל פס הוא רשת של כמות המשקעים הממוצעת הכוללת בחודש נתון. ההצגה של הלהקות היא לאורך ציר ה-X, והאזורים מגדירים את הסדרה. שימו לב לפעולות בצד הלקוח שמשמשות להגדרת הקלט של אפשרויות התרשים xLabels
ו-ticks
לצורך סידור מותאם אישית של ציר ה-x. פעולות הלקוח נדרשות כי האפשרויות שסופקו לפונקציה setOptions
חייבות להיות אובייקטים בצד הלקוח (כדי להבין את ההבדל, אפשר לעיין במאמר לקוח לעומת שרת). כדי להמיר לתרשים עמודות, משתמשים ב-'BarChart'
כקלט של .setChartType()
.
Code Editor (JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Load PRISM climate normals image collection, convert images to bands, and // subset precipitation bands. var precip = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m') .toBands() .select('[0-9][0-9]_ppt'); // Define a dictionary that associates band names with values and labels. var precipInfo = { '01_ppt': {v: 1, f: 'Jan'}, '02_ppt': {v: 2, f: 'Feb'}, '03_ppt': {v: 3, f: 'Mar'}, '04_ppt': {v: 4, f: 'Apr'}, '05_ppt': {v: 5, f: 'May'}, '06_ppt': {v: 6, f: 'Jun'}, '07_ppt': {v: 7, f: 'Jul'}, '08_ppt': {v: 8, f: 'Aug'}, '09_ppt': {v: 9, f: 'Sep'}, '10_ppt': {v: 10, f: 'Oct'}, '11_ppt': {v: 11, f: 'Nov'}, '12_ppt': {v: 12, f: 'Dec'} }; // Organize precipitation information into objects for defining x values and // their tick labels. Note that chart options provided to the .setOptions() // function must be client-side objects, which is why a client-side for // loop is used to iteratively populate lists from the above dictionary. var xPropVals = []; // List to codify x-axis band names as values. var xPropLabels = []; // Holds dictionaries that label codified x-axis values. for (var key in precipInfo) { xPropVals.push(precipInfo[key].v); xPropLabels.push(precipInfo[key]); } // Define the chart and print it to the console. var chart = ui.Chart.image .regions({ image: precip, regions: ecoregions, reducer: ee.Reducer.mean(), scale: 5e3, seriesProperty: 'label', xLabels: xPropVals }) .setChartType('ColumnChart') .setOptions({ title: 'Average Ecoregion Precipitation by Month', hAxis: { title: 'Month', titleTextStyle: {italic: false, bold: true}, ticks: xPropLabels }, vAxis: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true} }, colors: ['f0af07', '0f8755', '76b349'], }); print(chart);
תרשים קו
אפשר להציג את תרשים העמודות הקודם כתרשים קו על ידי שינוי הקלט .setChartType()
מ-'ColumnChart'
ל-'LineChart'
.
var chart = ui.Chart.image .regions({ image: precip, regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, seriesProperty: 'label', xLabels: xPropVals }) .setChartType('LineChart') .setOptions({ title: 'Average Ecoregion Precipitation by Month', hAxis: { title: 'Month', titleTextStyle: {italic: false, bold: true}, ticks: xPropLabels }, vAxis: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true} }, colors: ['f0af07', '0f8755', '76b349'], lineSize: 5 });
תרשים שטח
אפשר להציג את תרשים העמודות הקודם בתור תרשים שטח על ידי שינוי הקלט .setChartType()
מ-'ColumnChart'
ל-'AreaChart'
.
var chart = ui.Chart.image .regions({ image: precip, regions: ecoregions, reducer: ee.Reducer.mean(), scale: 500, seriesProperty: 'label', xLabels: xPropVals }) .setChartType('AreaChart') .setOptions({ title: 'Average Ecoregion Precipitation by Month', hAxis: { title: 'Month', titleTextStyle: {italic: false, bold: true}, ticks: xPropLabels }, vAxis: { title: 'Precipitation (mm)', titleTextStyle: {italic: false, bold: true} }, colors: ['f0af07', '0f8755', '76b349'], lineSize: 5 });
תרשים עוגה
כמות המשקעים החודשית הממוצעת מוצגת כחלק מתוך כמות המשקעים השנתית הממוצעת באזור אקולוגי של יער. פסלי התמונה שמייצגים את המשקעים החודשיים הם קבוצת משנה של מערך נתונים של נורמלי המצבים האקלימיים, והם מצטמצמים לממוצע של הפיקסלים שחופפים לאזור האקולוגי.
Code Editor (JavaScript)
// Import the example feature collection, subset the forest ecoregion. var forest = ee.FeatureCollection('projects/google/charts_feature_example') .filter(ee.Filter.eq('label', 'Forest')); // Load PRISM climate normals image collection, convert images to bands. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands(); // Define x-axis labels to replace default band names. var monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]; // Define the chart and print it to the console. var chart = ui.Chart.image .regions({ image: normClim.select('[0-9][0-9]_ppt'), regions: forest, reducer: ee.Reducer.mean(), scale: 5e3, seriesProperty: 'label', xLabels: monthNames }) .setChartType('PieChart') .setOptions({ title: 'Average Monthly Precipitation for Forest Ecoregion', colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ] }); print(chart);
תרשים טבעת
כדי להמיר את הדוגמה של תרשים העוגה לתרשים עיגול, מגדירים את אפשרות התרשים pieHole
. כדאי לנסות את הערכים 0.4 ו-0.6 כערכים ראשוניים.
var chart = ui.Chart.image .regions({ image: normClim.select('[0-9][0-9]_ppt'), regions: forest, reducer: ee.Reducer.mean(), scale: 5e3, seriesProperty: 'label', xLabels: monthNames }) .setChartType('PieChart') .setOptions({ title: 'Average Monthly Precipitation for Forest Ecoregion', colors: [ '604791', '1d6b99', '39a8a7', '0f8755', '76b349', 'f0af07', 'e37d05', 'cf513e', '96356f', '724173', '9c4f97', '696969' ], pieHole: 0.4 });
ui.Chart.image.byClass
תרשים קו
הפונקציה ui.Chart.image.byClass
מציגה תרשים סטטיסטי של ערכי הלהקה לפי פיקסלים באזורים מסווגים של 'להקת סיווג'. בדוגמה הזו, הוא משמש להצגת הפרופיל הספקטרלי של שלושה אזורים אקולוגיים. המאפיינים של האזור האקולוגי עוברים רסטריזציה ומתווספים כפס לתמונה של MODIS של השתקפות פני השטח (SR). לכל סיווג של אזור אקולוגי ולרצועת השתקפות, מחושב הממוצע של הפיקסלים הרלוונטיים ומתואר בציר y. אורכי הגל המרכזיים של פס ה-SR של MODIS מגדירים את הסימונים והתוויות של ציר ה-x. שימו לב שהאפשרות curveType
של תרשים הקו מוגדרת כ-'function'
כדי להחליק את הקווים.
Code Editor (JavaScript)
// Import the example feature collection. var ecoregions = ee.FeatureCollection('projects/google/charts_feature_example'); // Convert ecoregion feature collection to a classified image. var regionsBand = ecoregions .reduceToImage({properties: ['value'], reducer: ee.Reducer.first()}) .rename('class'); // 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_b0[0-7]') .mean(); // Reorder reflectance bands by ascending wavelength and // add the classified ecoregions image as a band to the SR collection and var modisSrClass = modisSr.select([2, 3, 0, 1, 4, 5, 6]).addBands(regionsBand); // Define a list of MODIS SR wavelengths for x-axis labels. var wavelengths = [469, 555, 655, 858, 1240, 1640, 2130]; // Define the chart and print it to the console. var chart = ui.Chart.image .byClass({ image: modisSrClass, classBand: 'class', region: ecoregions, reducer: ee.Reducer.mean(), scale: 500, classLabels: ['Desert', 'Forest', 'Grassland'], xLabels: wavelengths }) .setChartType('ScatterChart') .setOptions({ title: 'Ecoregion Spectral Signatures', hAxis: { title: 'Wavelength (nm)', titleTextStyle: {italic: false, bold: true}, viewWindow: {min: wavelengths[0], max: wavelengths[6]} }, vAxis: { title: 'Reflectance (x1e4)', titleTextStyle: {italic: false, bold: true} }, colors: ['f0af07', '0f8755', '76b349'], pointSize: 0, lineSize: 5, curveType: 'function' }); print(chart);
ui.Chart.image.histogram
היסטוגרמה של ערכי פיקסלים באזור שמקיף את סולט לייק סיטי, יוטה, ארה"ב, בשלושה פסגות של השתקפות פני השטח של MODIS.
Code Editor (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 (x1e4)', titleTextStyle: {italic: false, bold: true}, }, vAxis: {title: 'Count', titleTextStyle: {italic: false, bold: true}}, colors: ['cf513e', '1d6b99', 'f0af07'] }); print(chart);