0

I have some code with a sample geotiff file, I'd like the plot to show the lat/lon coordinates and not the pixel (?) values.

How can I do that?

import rioxarray

fl = 'https://download.osgeo.org/geotiff/samples/gdal_eg/cea.tif'
da = rioxarray.open_rasterio(fl, masked=True)
da.plot()
plt.show()

content of da:

<xarray.DataArray (band: 1, y: 515, x: 514)>
[264710 values with dtype=float32]
Coordinates:
  * band         (band) int64 1
  * x            (x) float64 -2.846e+04 -2.84e+04 ... 2.268e+03 2.328e+03
  * y            (y) float64 4.256e+06 4.256e+06 ... 4.225e+06 4.225e+06
    spatial_ref  int64 0
Attributes:
    AREA_OR_POINT:  Area
    scale_factor:   1.0
    add_offset:     0.0

I'd like the x and y axis on the plot to display lat/lon coordinates (ie some value between -180 and 180) if possible.

da.lat and da.lon are empty

Rafael
  • 3,096
  • 1
  • 23
  • 61
  • 1
    what does this mean? I dont' know what a plot of the lat/lon coordinates is. can you show us what your data looks like, by pasting the result of `print(da)` as a code block into your question, and then describe exactly what you're hoping to see as a result? you can plot any variable, e.g. with `da.lon.plot()` but I expect it will be very boring... – Michael Delgado Oct 26 '22 at 16:05
  • oh ok - so your data is in some cartographic projection and you'd like to see lat/lon coordinates when plotting? we'll need more info than this, specifically do you have any CRS or projection information in the array attributes / file documentation / etc? I assume by "not the pixel values" you just mean you don't want the x/y labels to be in projected coordinates (meters or something) – Michael Delgado Oct 26 '22 at 22:59
  • correct, for this one I'm not sure. the .tif file is the one seen above, just downloaded from that URL, but was using this as an example for how to approach this issue: https://stackoverflow.com/questions/74208825/converting-geotiff-to-datarame-and-preserving-lat-lon-in-columns I have more meta information for that one, if easier/possible to figure out that question I'll probably close this one as there doesn't seem to be enough information to proceed here.. – Rafael Oct 27 '22 at 14:23
  • oh - haha I thought these were just two people asking the same question - didn't notice they were both you! happens a lot on this site :) yeah let's sort the idea / data for the projection in the other question. – Michael Delgado Oct 27 '22 at 16:06
  • closing this as it's mostly a duplicate – Rafael Oct 28 '22 at 14:43

0 Answers0