holoviz / holoviz/hvplot

Add datetime axis capability to categorical plots

Open
#483 5 comments 3 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
124
Avg merge
1d 18h
Merged PRs (30d)
1

Description

#### Is your feature request related to a problem? Please describe.
This issue was first raised here: https://discourse.holoviz.org/t/workaround-for-date-based-histogram-tick-labels/788

I have time series data, and would like to bin the data according to different time resolutions.
When I try linking axes and controlling axis tick labels, I find it difficult to do so:

```
import numpy as np
import pandas as pd

import hvplot.pandas
import holoviews as hv
from bokeh.models.formatters import DatetimeTickFormatter

# Create data frame
days = pd.date_range(start=pd.to_datetime('2001-01-01'), end=pd.to_datetime('2001-12-31'))
ncols = 5
columns = np.arange(ncols) + 1
data = np.random.rand(365, ncols)
df = pd.DataFrame(data, index=days, columns=columns)
df.index.name = 'time'

# Determine number of days where row mean is above 0.5
mean_above_midpoint = (df.agg('mean', axis=1) > 0.5).astype(int)
df['days_above_midpoint'] = mean_above_midpoint
df_weekly = df.resample('W').mean()
df_weekly['days_above_midpoint'] = df['days_above_midpoint'].resample('W').sum()
df_weekly.head()

formatter = DatetimeTickFormatter(months='%b')
columnLabels = [str(x) for x in columns]

lines = df_weekly.hvplot.line(x='time', y=columnLabels, title='Measurements', xformatter=formatter)
hist = df_weekly.hvplot.bar(x='time', y='days_above_midpoint', title='Days Above Midpoint', xformatter=formatter)

(lines + hist).cols(1)
```
![Screen Shot 2020-06-09 at 10 55 30 AM](https://user-images.githubusercontent.com/10638475/84409064-28888300-abca-11ea-95dc-09c17b0aadc6.png)

#### Describe the solution you'd like
Most categorical plots (histogram, box+whisker, violin) have utility when the bins are discrete time intervals, rather than categories. It would be nice if these plots allowed a datetime axis with all of the related linking abilities to other time series plots.

I am aware now of a workaround using Holoviews, but it's not something I could have figured out on my own.

Thanks for your consideration!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.