0

Been struggling with this a while and think I've reached as far as I can on my own!

I'm trying to plot data from a .txt file onto basemap using contourf. I think I have reshaped the data correctly to fit, but it seems that the latitude values are only appearing when positive. Any ideas how to fix?

I would also like the zero values to appear blank rather than blue as they currently are.

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.basemap import Basemap

dataset = '/nfs/see-fs-02_users/ee11mr/mdrive/PhD/Python/ch4_v1_1x1.txt'
data = np.loadtxt(dataset, skiprows=3)

LAT=data[:,2]
LON=data[:,1]
Z=data[:,4]

Z=Z.reshape(180,360)
LON=LON.reshape(180,360)
#print LON[0]
LAT=LAT.reshape(180,360)
#print LAT[0]

fig_index=1
fig = plt.figure(num=fig_index, figsize=(12,7), facecolor='w')
fbot_levels = np.arange(0.05,1.0,0.05)


m = Basemap(projection='mill',lon_0=0,boundinglat=-45)
m.drawcoastlines()
x, y =m(LON,LAT)
meridians=[0,1,1,1]
plt.contourf(x,y,Z, origin='lower')
m.drawparallels(np.arange(-90.,120.,15.),labels=[1,0,0,0]) # draw parallels
m.drawmeridians(np.arange(0.,420.,30.),labels=meridians) # draw meridians
coloraxis = [0.11, 0.1, 0.8, 0.035]
cx = fig.add_axes(coloraxis, label='m', title='CH4 (kt/year) ')

cbar=plt.colorbar(cax=cx,orientation='horizontal',ticks=list(fbot_levels))
plt.show()

If you need any more information just ask. Any advice greatly appreciated! Thanks

Working plot

divibisan
  • 11,659
  • 11
  • 40
  • 58
  • Can you show more detail of your .txt file. If it's ok, you can upload you file, and then I can try to find what I can help. – Han Zhengzu Feb 21 '16 at 02:23
  • Hi Han. I eventually managed to fix my main problem and got the data to fit. Now just trying to better see the lower end of the spread and maybe blank out the zero values (there are quite a lot). If you've any ideas that'd be great. Thanks for replying anyway – M.Rowlinson Feb 22 '16 at 11:41
  • I noticed the colorbar of your working plot cling to the bottom edge of the main figure, may be you can shift down it a little bit using 'pad = xx'. That's my opinion. – Han Zhengzu Feb 23 '16 at 01:10

0 Answers0