Thanks Joe,
I forgot to convert my numeric time array into a form that mpl can
understand.
I198 time
O198
array([ 32643.78595805, 32643.82032609, 32643.85445309, ...,
32871.46535802, 32871.49946594, 32871.53384495])
I199 ncnt
O199
array([0001-01-01 09:04:03+00:00, 0001-01-01 09:04:03+00:00,
0001-01-01 09:04:03+00:00, ..., 0001-01-01 09:07:51+00:00,
0001-01-01 09:07:51+00:00, 0001-01-01 09:07:51+00:00], dtype=object)
Although, this doesn't give me millisecond precision. Is there any way to
get ms precision via datetime module?
This is not a matter for plotting, since second precision is good enough
for eyes.
Then setting extent properly and either calling ax.xaxis_date or calling
setters manually
I196 xmin = mdates.date2num(ncnt[0])
I197 xmax = mdates.date2num(ncnt[-1])
plt.imshow(z.T, interpolation='nearest', aspect='auto', origin='lower',
extent=[xmin, xmax, 0, z.shape[1]])
ax = plt.gca()
ax.xaxis.set_major_formatter(DateFormatter('%H:%M:%S'))
ax.xaxis.set_major_locator(SecondLocator(interval=30))
ax.xaxis.set_minor_locator(SecondLocator(interval=5))
gives me better control over the major/minor ticks.
On Thu, Nov 10, 2011 at 8:15 AM, Joe Kington <jking...@wisc.edu> wrote:
> On Wed, Nov 9, 2011 at 11:45 PM, Gökhan Sever <gokhanse...@gmail.com>wrote:
>
>> Hello,
>>
>> Is there any easy way to specify a time-axis using imshow to plot 2D data?
>>
>>
> Sure, just call "ax.xaxis_date()" (or "yaxis_date", depending on which
> axis you want to represent a date).
>
> As a quick example:
>
> import matplotlib.pyplot as plt
> import matplotlib.dates as mdates
> import numpy as np
>
> # Generate data...
> ny = 100
> xmin, xmax = mdates.datestr2num(['01/01/2011', '11/10/2011'])
> data = np.random.random((ny, int(xmax-xmin)+1)) - 0.5
> data = data.cumsum(axis=1)
>
> # Plot...
> fig, ax = plt.subplots()
> ax.imshow(data, extent=[xmin, xmax, 0, ny])
> ax.xaxis_date()
> fig.autofmt_xdate()
>
> plt.show()
>
> Cheers,
> -Joe
>
>
>
>
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Save $700 by Nov 18
> Register now
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
--
Gökhan
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users