0

I have a pandas data frame with a datetime index and some variable z and I want to reproduce a plot similar to this:

"Fingerprint plot" of CO2 fluxes (Image source: University of Edinburgh, http://www.geos.ed.ac.uk/homes/rclement/micromet/Current/griffin/carbon/)

This is often called a "fingerprint plot" in the CO2 flux community.

A year of sample data:

import pandas as pd
import numpy as np
n = 366*24
df = pd.DataFrame(index=pd.date_range(start='2016-01-01 00:00', freq='H', periods=n),
                  data={'z': np.random.randn(n)})
df["x"] = df.index.date
df["y"] = df.index.hour
df.head()

How do I proceed from here? I played around with the solution to this question: how to plot a heat map for three column data, but I can't get it to work with the datetime data.

Community
  • 1
  • 1
Fred S
  • 1,421
  • 6
  • 21
  • 37

1 Answers1

1

Does this get what you are looking for?

from scipy.interpolate import griddata
from jdcal import jd2jcal
from datetime import datetime

n = 366*24
df = pd.DataFrame(index=pd.date_range(start='2016-01-01 00:00', freq='H', periods=n),
                  data={'z': np.random.randn(n)})
df["x"] = df.index.date
df["y"] = df.index.hour
df.head()

xi = np.linspace(df.index.to_julian_date().min(), df.index.to_julian_date().max(), 1000)
yi = np.linspace(df.y.min(), df.y.max(), 1000)
zi = griddata((df.index.to_julian_date(),df.index.hour),df.z,(xi[None,:],yi[:,None]),method='linear')
xij = [jd2jcal(0,v) for v in xi]
xid = [datetime(x[0],x[1],x[2]) for x in xij]
plt.contourf(xid,yi,zi)
plt.colorbar()
plt.show()
screenpaver
  • 1,120
  • 8
  • 14