Leighton Regayre
unread,May 24, 2013, 1:21:17 PM5/24/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scitoo...@googlegroups.com
Hi all,
I'm attempting to follow a simple Cartopy example and am running into these problems:
Firstly I can generate a Robinson plot with coastlines, but cannot plot the data onto it.
Secondly, if I plot the data without transformation, it is rotated by 90 degrees and replicated.
The code I'm using is:
import numpy as np
from math import *
import os
import matplotlib.pyplot as plt
from netCDF4 import Dataset as netcdf_dataset
import iris
import iris.plot as iplt
import cartopy.crs as ccrs
from mpl_toolkits.basemap import Basemap
import pylab as plb
SO2data=np.loadtxt('data.dat', skiprows=0, dtype='float32')
lat = SO2data[:,0]
long = SO2data[:,1]
so2_rt = SO2data[:,2]
datalen = so2_rt.size
# Check for index of the first value in lat.
long_first = long[0]
index_long = np.argwhere(long==long_first)
# Here is where the 1st repeat of the original longitudinal value occurs:
long_len = index_long[1]
# This is the number of different longitudinal values for each lat. (180)
# The emissions array will be this wide.
# Take a slice of the longitude.
long_universal = long[:long_len]
lat_universal = lat[0:datalen:long_len]
# Now emissions can be converted into 2D:
so2_rt_2d = so2_rt.reshape(np.asscalar(long_len), lat_universal.size)
log_so2 = np.log(so2_rt_2d)
# Here's the construction of the grid for contour:
X,Y = plb.meshgrid(lat_universal,long_universal)
# so some attempts to plot:
ax = plt.axes(projection=ccrs.Robinson())
plt.contour(X, Y, log_so2, transform=Robinson())
ax.coastlines()
plt.show()
#Thanks