Scatterplot of two rasters in Python

5082
1
Jump to solution
01-08-2015 01:50 AM
Leo_KrisPalao
New Contributor II

Hi ALL,

I am doing a Temperature-Vegetation Dryness Index (TDVI) analysis using Normalized Difference Vegetation Index (NDVI) and Land Surface Temperature (LST) for drought assessment. I need to create a scatterplot of LST and NDVI. Can you help me do this in Python? or at least guide me on how to do this.

Thanks,

-Leo

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

conceptually, if you are doing this on a cell by cell basis, you could use RasterToNumpyArray to convert the rasters to arrays...then 'flatten' the arrays so they essentially become X, Y pairs, then you can use matplotlib to do the scatter plot

from matplotlib import pyplot as plt
xs = [1,3,2,5,6,4]
ys = [3,2,1,5,3,2]
plt.scatter(xs, ys)
main_title ="My first graph"
plt.title(main_title, loc='center')  #loc is either left, right or center
plt.minorticks_on()
plt.tick_params(which='major', direction='in', length=6, width=2)
plt.tick_params(which='minor', direction='in', length=4, width=2)
plt.show()

View solution in original post

1 Reply
DanPatterson_Retired
MVP Emeritus

conceptually, if you are doing this on a cell by cell basis, you could use RasterToNumpyArray to convert the rasters to arrays...then 'flatten' the arrays so they essentially become X, Y pairs, then you can use matplotlib to do the scatter plot

from matplotlib import pyplot as plt
xs = [1,3,2,5,6,4]
ys = [3,2,1,5,3,2]
plt.scatter(xs, ys)
main_title ="My first graph"
plt.title(main_title, loc='center')  #loc is either left, right or center
plt.minorticks_on()
plt.tick_params(which='major', direction='in', length=6, width=2)
plt.tick_params(which='minor', direction='in', length=4, width=2)
plt.show()