0

I am having issues figuring out how to label the following plot. When I use the pad option, it takes away from title of the subplots.

Here is my code so far:

Data=xr.open_dataset(in_file)
precip_data=Data['pre']

NHNA=precip_data.sel(lon = np.arange(-128.715, -64.557, 0.5), lat = np.arange(24, 50, 0.5), method='nearest')

study_date = NHNA[935:1452]

Seas_NHNA = study_date.groupby('time.season').mean('time')


Seas_NHNA.plot.contourf(x = 'lon', y = 'lat', col = 'season', col_wrap = 2, cmap = 'Blues', vmin = 0, vmax = 200)

ax =plt.axes(projection =ccrs.PlateCarree())

fig = plt.figure(figsize =(11,7))
plt.title('Average Seasonal Precipiation Jan. 1979 - Dec. 2021 ')
cs = Seas_NHNA.plot.contourf(x = 'lon', y = 'lat', col = 'season', col_wrap = 2, cmap = 'Blues', vmin = 0, vmax = 200)

ax.coastlines()
plt.show()

Plot of Seasonal Precip

I have tried subplots, cartopy.

Michael Delgado
  • 13,789
  • 3
  • 29
  • 54

1 Answers1

0

To put a main title, you have to use the plt.suptitle() or fig.suptitle():

plt.suptitle('Average Seasonal Precipiation Jan. 1979 - Dec. 2021 ')

You can see this question for more details: How to position suptitle

It looks like you're plotting your data twice, as you do two calls to Seas_NHNA.plot.contourf(...) with the same data, while creating a new figure in the middle, so maybe you want it on two different figures?

If you want to work with multiple figures, you should name them, and then use fig1.suptitle() to make sure your title goes on the correct one.

XaC
  • 432
  • 3
  • 9