X Tutup
Skip to content

Improperly spaced time axis #6437

@jbwhit

Description

@jbwhit

I've put a short reproducible example in this gist: https://gist.github.com/jbwhit/467e154cef029f8098d560924f14612c

The problem can be seen in this screenshot

screenshot 2016-05-16 20 44 57

Notice how, for example, November is wider than December (so it isn't merely the number of days in each month). My conda installed setup's details:

Software    Version
Python  2.7.11 64bit [GCC 4.2.1 (Apple Inc. build 5577)]
IPython 4.2.0
OS  Darwin 14.5.0 x86_64 i386 64bit
numpy   1.11.0
matplotlib  1.5.1
pandas  0.17.1
Mon May 16 20:54:59 2016 PDT

The code in the gist is as follows:

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
ids = [1,2,3,4]
dates = pd.date_range('20150704', '20160331')
vals = np.random.randn(len(ids)*len(dates))
allids = np.array([np.repeat(i, len(dates)) for i in ids]).ravel()
alldates = np.tile(dates, len(ids))

df = (pd.DataFrame(np.vstack((allids, vals)).T, index=alldates)
    .reset_index().rename(columns={'index':'datetime',0:'unique_id',1:'height'}))

time_group = '1w'
threshold = 0.50

fig, axes = plt.subplots(nrows=4, ncols=1, figsize=(12, 16), sharex=True)

for (i, temp), ax in zip(df.groupby('unique_id'), axes.ravel()):
    (temp.set_index('datetime').height
         .groupby(pd.TimeGrouper(time_group))
         .mean()
         .plot(ax=ax))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup