What is the standard way to build timers (dates) for a quiver or thorns? I often have timeouts in a Pandas DataFrame, and lay them out like this:
plt.plot(df.index.to_pydatetime(), df.parameter)
This works very well, the x axis can be considered as genuine dates, which is very convenient for formatting or setting xlim () using a Datetime object, etc.
Using this with a quiver or spines in the same way, do:
TypeError: float() argument must be a string or a number
This can be overcome with something like:
ax.barbs(df.index.values.astype('d'), np.ones(size) * 6.5, df.U.values, df.V.values, length=8, pivot='middle') ax.set_xticklabels(df.index.to_pydatetime())
Which works, but will mean that everywhere I have to convert the dates to float and then manually redefine the labels. Is there a better way?
Here is a sample code similar to my case:
import matplotlib.pyplot as plt import numpy as np import pandas as pd size = 10 wspd = np.random.randint(0,40,size=size) wdir = np.linspace(0,360 * np.pi/180, num=size) U = -wspd*np.sin(wdir) V = -wspd*np.cos(wdir) df = pd.DataFrame(np.vstack([U,V]).T, index=pd.date_range('2012-1-1', periods=size, freq='M'), columns=['U', 'V']) fig, ax = plt.subplots(1,1, figsize=(15,4)) ax.plot(df.index.values.astype('d'), df.V * 0.1 + 4, color='k') ax.quiver(df.index.values.astype('d'), np.ones(size) * 3.5, df.U.values, df.V.values, pivot='mid') ax.barbs(df.index.values.astype('d'), np.ones(size) * 6.5, df.U.values, df.V.values, length=8, pivot='middle') ax.set_xticklabels(df.index.to_pydatetime())
