-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_contour.py
66 lines (50 loc) · 1.62 KB
/
plot_contour.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 14 18:32:50 2019
@author: blyons
"""
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.interpolate import griddata
def plot_contour(x, y, V, vmin=None, vmax=None, fs=1.0,
xrange=None, yrange=None, xlabel=None, ylabel=None):
if vmin is None:
vmin = 0.
if vmax is None:
vmax = V.max()
cmap = mpl.colors.ListedColormap(sns.color_palette("inferno", 256))
xl = x[0]
xu = x[-1]
yl = y[0]
yu = y[-1]
X0,Y0 = np.meshgrid(x,y)
X0 = X0.ravel()
Y0 = Y0.ravel()
V2 = V.ravel()
xi = np.linspace(xl,xu,1025)
yi = np.linspace(yl,yu,1026)
Xi,Yi = np.meshgrid(xi,yi)
V2 = griddata(X0,Y0,V2,Xi,Yi,method='linear')
f, ax = plt.subplots(figsize=[fs*11.,fs*9.])
extent = [xl,xu,yl,yu]
if xrange is None:
xrange = [xl,xu]
if yrange is None:
yrange = [yl,yu]
aspect = 1.0*(xrange[1]-xrange[0])/(yrange[1]-yrange[0])
im=ax.imshow(V2, origin='lower', cmap=cmap, vmin=vmin, vmax=vmax,
extent=extent, aspect=aspect, interpolation='nearest')
ax.set_xlim(xrange)
ax.set_ylim(yrange)
ax.tick_params(labelsize=fs*28)
if xlabel is not None:
ax.set_xlabel(xlabel,fontsize=fs*32)
if ylabel is not None:
ax.set_ylabel(ylabel,fontsize=fs*32)
cb = plt.colorbar(im,ax=ax,format='%1.3g')#,ticks=[0.,0.25,0.5,0.75,1.,1.25])
cb.ax.tick_params(labelsize=fs*28)
plt.tight_layout()
return (f,ax)