just can't overcome this issue
here is a small data sample to run the code: https://www.dropbox.com/s/jbba3ckwojb8gpq/BOZ_LfU_CAPdef5_sample.nc?dl=0 https://www.dropbox.com/s/57gqf5znsmc37i1/im_sample.csv?dl=0
i have the following code:
import numpy as np
import xarray as xa
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib.colors import ListedColormap
local_path = '/dir'
im = pd.read_csv(local_path + 'im_sample.csv')
im['time'] = pd.to_datetime(im['time'].astype(str), format='%Y-%m-%d %H:%M:%S', errors='coerce')
im = im.set_index('time')
cap = xa.open_dataset(local_path + 'BOZ_LfU_CAPdef5_sample.nc')
#separate inversion data into different groups and attach them to a pandas series
cap1 = cap.where(cap.number == 1, drop=True)
capB = cap1.where(cap1.kind == 'B', drop=True).time
capA = cap.where(cap.kind.sel(layer=0) == 'A', drop=True).time
capplus = cap.where(cap.number >1, drop=True)
capmix = capplus.where(capplus.kind.sel(layer=0) == 'B', drop=True).time
capN = cap.where(cap.kind.sel(layer=0) == 'nan', drop=True).time
s = pd.Series([1]*len(cap.time.values), cap.time.values)
for i in cap.time.values:
if i in capN.values:
s[i] = 0
elif i in capB.values:
s[i] = .25
elif i in capA.values:
s[i] = .5
else:
s[i] = .75
#get two different plots.. one timeseries for the immission data and one for the additional inversion data
cmap = ListedColormap(['black', 'red', 'green', 'yellow', 'white'])
colors = ['#7678ed', '#ee4266', '#ffd23f', '#808080']
im_dict = {'imtype': ['NO2','NOx', 'PM10'], 'imlabel': ['NO$_2$', 'NO$_x$', 'PM$_{10}$']}
imnames = pd.DataFrame(data=im_dict)
s = s.reindex(im['Cla_'+imnames.imtype[0]].index)
fig, (ax0, ax1) = plt.subplots(2, 1, figsize=(20,12), sharex=True, gridspec_kw={'height_ratios': [1,4], 'hspace':0})
fig.suptitle('Time Series for NO2 data', y=0.92, fontsize=15)
p = ax0.pcolor([np.arange(len(s)), s.values], cmap=cmap,vmin = 0, vmax = 1)
ax0.set_ylim(1,2)
ax0.set_yticks([])
ax1.plot(im['Cla_'+imnames.imtype[0]], linewidth=1.5, label='Claudia street', color=colors[0])
ax1.plot(im['Had_'+imnames.imtype[0]], linewidth=1.5, label='Hadrach street', color=colors[1])
ax1.plot(im['Lei_'+imnames.imtype[0]], linewidth=1.5, label='Leim Street', color=colors[2])
ax1.set_ylabel(imnames.imlabel[0] +' ($\mu$g/m$^3$)')
ax1.tick_params(axis='both', which='major', labelsize=13)
so there are a few problems. first the result gives me a plot beginning from 1970 to 2016 which doesn't make any sense at all. so immission graph is completely squeezed on the right and inversion data squeezed on the left side of their axes. i haven't figured out how to successfully implement a daterange data for the xaxis of the inversion plot (if that is the actually problem as i suppose right now).
if you have any additional improvement tips or ideas how to graphically represent the inversion type data .. i would be very happy to hear about them (:
the main goal is to illustrate the coherence between different types of inversions and the amount of pollutants in the surface-near air. so to every immission data point (every 30 minutes) i have information about whether there is inversion and which one. inversion data points are actually every 10 minutes but i thought about fitting them to the immission dataframe so both have the same size.