0

I am trying to plot some correlation data about temperature on a stereographic map of the north pole. the data is from different stations in this region.

I am using: from scipy.interpolate : griddata and from mpl_toolkits.basemap: Basemap. My code for the plotting part looks like the following: I am not very happy with how it looks in the south of Greenland. and some parts of Canada and on the edges in general. Can anyone suggest what I can do to improve the map?

The Figure:

import numpy as np
from scipy.interpolate import griddata
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import pandas as pd
from itertools import chain

def draw_map(m, scale=0.7):
    # draw a shaded-relief image
    # m.bluemarble(scale=scale)
    m.shadedrelief()
    
    
    # lats and longs are returned as a dictionary
    lats = m.drawparallels(np.linspace(-90, 90, 13))
    lons = m.drawmeridians(np.linspace(-180, 180, 13))

    # keys contain the plt.Line2D instances
    lat_lines = chain(*(tup[1][0] for tup in lats.items()))
    lon_lines = chain(*(tup[1][0] for tup in lons.items()))
    all_lines = chain(lat_lines, lon_lines)
    
    # cycle through these lines and set the desired style
    for line in all_lines:
        line.set(linestyle='-', alpha=0.3, color='w')

mydata = pd.read_csv("C:/Users/negar/negar/NewDirectory/cor_30.csv")

fig = plt.figure(figsize = (20, 20))
m = Basemap(projection='npstere',boundinglat=55,lon_0=0,resolution='l')
m.drawparallels(np.arange(-80.,81.,10.),  linewidth=0.4)
m.drawmeridians(np.arange(-180.,181.,10.),  linewidth=0.4)
x, y = m(mydata.iloc[:,5], mydata.iloc[:,4])
Jan_Feb = mydata.iloc[:, 6]
plt.scatter(x, y, c = Jan_Feb, cmap = "RdBu", marker = "o")
plt.colorbar(shrink = 0.65)
plt.title("Jan_Feb Correlation")
draw_map(m)
lllon = -180
lllat = 60
urlon = 180
urlat = 90
geo_df = mydata

# Make the edges:
lat = np.array(geo_df.iloc[:,4])
lat_all= np.append(lat, [lllat, urlat]) 
lon = np.array(geo_df.iloc[:,5])
lon_all = np.append(lon, [lllon, urlon])
data = np.array(geo_df.iloc[:,6])
# set up basemap chose projection!
m = Basemap(projection='npstere',boundinglat=55,lon_0=0,resolution='l')

# transform coordinates to map projection m
m_lon, m_lat = m(*(lon, lat))
m_on_all, m_lat_all = m(*(lon_all, lat_all))
# generate grid data
numcols, numrows = 500, 500
xi = np.linspace(m_lon_all.min(), m_lon_all.max(), numcols)
yi = np.linspace(m_lat_all.min(), m_lat_all.max(), numrows)
xi, yi = np.meshgrid(xi, yi)

# interpolate, there are better methods, especially if you have many datapoints
zi = griddata((m_lon,m_lat),data,(xi,yi),method='linear')

fig, ax = plt.subplots(figsize=(12, 12))

# draw map details
m.shadedrelief()
# m.drawmapboundary(fill_color = 'lightgreen', zorder = 1)

# Plot interpolated temperatures
m.contourf(xi, yi, zi, 500, cmap='RdBu', zorder = 2)

m.drawlsmask(ocean_color='skyblue', land_color=(0, 0, 0, 0), lakes=True, zorder = 3)

m.drawparallels(np.arange(-80.,81.,10.),  linewidth=0.4)
m.drawmeridians(np.arange(-180.,181.,10.),  linewidth=0.4)

c=plt.colorbar(shrink=0.75)
plt.clim(-1, 1) 
plt.title('Jan Feb Correlation')

plt.show()
2
  • Where is the figure? Commented Apr 18, 2023 at 11:07
  • @HMH1013 I added the lines for the figure. Commented Apr 18, 2023 at 14:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.