Created
August 24, 2018 03:19
-
-
Save sergiolucero/21614aa47604436b8ac0753c5ca67f46 to your computer and use it in GitHub Desktop.
air quality plots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for every city, we fetch and plot data from all available parameters | |
import openaq | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
sns.set(style="white", palette='muted', font_scale=1.35, color_codes=True) | |
api = openaq.OpenAQ() | |
def get_city_data(city='Santiago'): | |
df = api.measurements(city=city, limit=10000, df=True) | |
df = df.query("value >= 0.0") # clean up the data by removing values below 0 | |
# Map the gas species from ugm3 to ppb (gas-phase species only) | |
df['corrected'] = df.apply(lambda x: openaq.utils.mass_to_mix(x['value'], | |
x['parameter'], unit='ppm'), axis=1) | |
return df | |
def dateplot(y, **kwargs): | |
ax = plt.gca() | |
data = kwargs.pop("data") | |
rs = kwargs.pop("rs", '12h') | |
data.resample(rs).mean().plot(y=y, ax=ax, grid=False, **kwargs) | |
df = get_city_data(') | |
g = sns.FacetGrid(df, col='parameter', col_wrap=3, size=4, hue='parameter', sharey=False) | |
g.map_dataframe(dateplot, "corrected", rs='12h') # Map the dataframe to the grid | |
g.set_titles("{col_name}", fontsize=16)# Set the titles | |
g.set_axis_labels("", "value") # Set the axis labels |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment