aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2023-10-14 00:44:11 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2023-10-14 00:44:11 +0200
commitee869da58b7cacd77523c32ae5b7f129679f133d (patch)
tree358b352efa433be2ddac98ed9abfaff8400d319b /test
parentb8a849c797b9e7e9b474c45353f1f1c031aa5091 (diff)
downloadmeteo_toolbox-ee869da58b7cacd77523c32ae5b7f129679f133d.tar.gz
custom colormap WIP
Diffstat (limited to 'test')
-rwxr-xr-xtest/cross.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/test/cross.py b/test/cross.py
index de6b9be..6194630 100755
--- a/test/cross.py
+++ b/test/cross.py
@@ -1,10 +1,32 @@
#!/usr/bin/env python3
import matplotlib.pyplot as plt
+import matplotlib as mpl
+from matplotlib.colors import LinearSegmentedColormap
import xarray as xr
from metpy.interpolate import cross_section
+clcov_cmap = {
+ 'red': (
+ (0.0, 0.0, 0.0),
+ (0.1, 1.0, 1.0),
+ (1.0, 0.2, 0.2),
+ ),
+ 'green': (
+ (0.0, 0.0, 0.0),
+ (0.1, 1.0, 1.0),
+ (1.0, 0.2, 0.2),
+ ),
+ 'blue': (
+ (0.0, 1.0, 1.0),
+ (0.1, 1.0, 1.0),
+ (1.0, 0.2, 0.2),
+ ),
+}
+
+mpl.colormaps.register(LinearSegmentedColormap('clcov', clcov_cmap))
+
data = xr.load_dataset('dwd_icon-eu/combined.grib2', engine='cfgrib')
lat, lon = (47.96, 11.99)
data = data.sel(latitude=lat, longitude = lon, method='nearest')
@@ -14,13 +36,16 @@ print(data)
# start figure and set axis
fig, ax = plt.subplots(figsize=(5, 5))
+ax.set_ylabel('Pressure level [hPa]')
+
#clc = ax.plot(data.step.values.astype('float64'), data.isobaricInhPa, data.ccl.transpose())
#clc = ax.imshow(data.ccl.transpose(), extent=(data.step.values.astype(float).min(), data.step.values.astype(float).max(), data.isobaricInhPa.min(), data.isobaricInhPa.max()), aspect='auto', cmap='Blues_r', vmin=0, vmax=100)
#plt.colorbar(clc, label='clcov')
-clc = ax.contourf(data.step.values.astype('float64'), data.isobaricInhPa, data.ccl.transpose(), cmap='Blues_r', vmin=0, vmax=100, levels=9)
+# Blues_r
+clc = ax.contourf(data.step.values.astype('float64'), data.isobaricInhPa, data.ccl.transpose(), cmap='clcov', vmin=0, vmax=100, levels=9)
# use Format parameter for n/8
-plt.colorbar(clc, label='clcov', extendfrac=None, ticks=[100*n/8 for n in range(9)], format=lambda x,_: f'{int(x/12.5)}/8')
+plt.colorbar(clc, label='cloudcov', extendfrac=None, ticks=[100*n/8 for n in range(9)], format=lambda x,_: f'{int(x/12.5)}/8')
cf = ax.contour(data.step.values.astype('float64'), data.isobaricInhPa, data.t.metpy.convert_units('degC').transpose())