|
From: Fabien <fab...@gm...> - 2014-12-02 14:30:20
|
Folks, I'm trying to use BrokenBarHCollection with pandas timeseries object. Here's a minimal example: (python 3.3, pandas 0.15.1, matplotlib 1.4.2) #----------------------------------------------------- import pandas as pd import numpy as np from datetime import datetime as dt import matplotlib.pyplot as plt import matplotlib.collections as collections span_where = collections.BrokenBarHCollection.span_where # init the dataframe time = pd.date_range(pd.datetime(1950,1,1), periods=5, freq='MS') df = pd.DataFrame(np.arange(5), index=time, columns=['data']) df['cond'] = df['data'] == 3 # Make the plot fig = plt.figure() ax = fig.add_subplot(111) df['data'].plot(ax=ax, c='black') c = span_where(df.index, ymin=0, ymax=4, where=df['cond'], facecolor='green', alpha=0.5) #----------------------------------------------------- I get the error: "TypeError: float() argument must be a string or a number" Basically, span_where() is not happy with my x values which are a panda timeserie. I tried several stuffs (df.index.to_*) but there is something I still don't get in the internal representation of dates in matplolib. Any hint? Thanks a lot! Fabien |