0

I am trying to make seasonal maps out of climate datasets using the function imshow from the matplotlib toolbox. My problem is that I can only get imshow to plot the logical coordinates x and y which makes my map of Spain upside down: enter image description here I have tried different methods and I think one of my problems might be that my longitude and latitude coordinates are 2d data arrays and not just vectors.

So far my code looks like this:

    seasonal = PET.groupby('time.season').mean(dim=['time'])
    seasonal.plot.imshow(col= 'season', robust = True)

And my data looks like this:

<xarray.DataArray 'PET' (year: 1, x: 834, y: 1115)>
array([[[nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        ...,
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan]]], dtype=float32)
Coordinates:
    lon      (x, y) float64 ...
    lat      (x, y) float64 43.99 43.99 43.99 43.99 ... 35.75 35.75 35.75 35.75
  * year     (year) int64 2008
Dimensions without coordinates: x, y

Does anyone know how to solve this, so imshow plots with longitude and latitude instead of x and y?

Idalh
  • 31
  • 3
  • For further update on the problem I think I am not able to plot it with longitude and latitude because my 'lon' and 'lat' coordinates are not "dimension coordinates". I think it is the same problem in this post: https://stackoverflow.com/questions/34987972/expand-dimensions-xarray where I have tried to implement the solution in the comments, but it does not work for me. Does anyone know hoe to make coordinates into "dimension coordinates"? – Idalh Apr 23 '20 at 12:55
  • Try keyword `origin='upper'` in the call to imshow. – kmuehlbauer Apr 23 '20 at 14:29
  • This works! Thank you! Just to spell it out for others who might want to see it, this is how i added it: ```seasonal.plot.imshow(col= 'season', robust = True, origin='upper')``` – Idalh Apr 25 '20 at 09:08
  • 2
    For using lon, lat you might try just `seasonal.plot(x='lon', y='lat')`, plus your parameters. – kmuehlbauer Apr 25 '20 at 09:56

1 Answers1

0

You've found from comments on the question that theimshow arg, origin='upper', will display your plots in the correct orientation:

seasonal.plot.imshow(col= 'season', robust = True, origin='upper')

To plot your axes in geographic lon, lat vs. logical x, y, trying using the imshow arg, extent=[left, right, bottom, top], to set the bounds of the axes and plot in these coordinates. Something like this:

seasonal.plot.imshow(col= 'season', robust = True, origin='upper', extent=[min(lon), max(lon), min(lat), max(lat)])

You can read more about origin and extent arg's inimshow here.