Skip to content

Feature Request: enhance DatetimeIndex formatting if freq=None #12454

@RolandRitt

Description

@RolandRitt

I have a Dataframe with a DatetimeIndex spanning more than one day (freq=1D).
From this DataFrame i extract a subset with groupby (--> leads to a Dataframe with freq=None)
When I plot these DataFrames, the xaxis (DateTimeIndex) is fromatted in two different ways. If freq is specified (freq=1D) the xaxis-ticks look like I desire it.
But the Dataframe with freq=None the xaxis shows only timestamps without day, month or year (because the Timerange is more than one day some ticks are doubled..and so its confusing and hard to read)

It would be fine if the xaxis-Ticks would be formatted the same way (show year, month and day)
xaxisdatetimeindex2
xaxisdatetimeindex1

My code:

import os
mport sys
import datetime
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.dates as mdates
import numpy as np


%matplotlib notebook


dates = pd.date_range('2013-07-14 11:00:00', '2013-07-16 11:00:00', freq = 's')
cats = np.random.choice(['m', 'f', 'c'], len(dates))
data =np.random.randn(len(dates),1)
data2 =np.random.randn(len(dates),1)

df = pd.DataFrame(data, dates)
df.columns = ['data']
df['cats']= cats
df['data2'] = data2

df.plot()

data_grouped = df.groupby('cats')
df2 = pd.DataFrame(data_grouped.get_group('m'))
df2.plot()

Pandas Version

pd.__version__
'0.18.0rc1'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions