brunorosilva / plotly-calplot

The easiest and best looking Calendar Heatmap you'll find, made with Plotly.
https://pypi.org/project/plotly-calplot/
104 stars 10 forks source link

plot for trailing 12 months #29

Open bhargavkakadiya opened 8 months ago

bhargavkakadiya commented 8 months ago

Is it possible to have plot combining two different years for use case such as: trailing 12 months? So w.r.t. to given Image, expected result which starts at month Feb and ends at Jan in a single row image

brunorosilva commented 8 months ago

Hey @bhargavkakadiya , thanks for reaching out.

Unfortunately this is something that has been on my to-do list for a while now.

The best I can do for you is the years_as_columns=True option, which will plot horizontally but still separating the years.

import numpy as np
import pandas as pd

from plotly_calplot.calplot import calplot

# mock setup
dummy_start_date = "2022-12-01"
dummy_end_date = "2023-10-03"
dummy_df = pd.DataFrame(
    {
        "ds": pd.date_range(dummy_start_date, dummy_end_date, tz="Singapore"),
        "value": np.random.randint(
            -10,
            30,
            (pd.to_datetime(dummy_end_date) - pd.to_datetime(dummy_start_date)).days
            + 1,
        ),
    }
)

fig1 = calplot(
    dummy_df,
    x="ds",
    y="value",
    years_as_columns=True
)

fig1.show()

image

brunorosilva commented 8 months ago

When I end up doing the 12 month trailing plot, it will be a separate function to calplot and I'll mention this issue in the release.

bhargavkakadiya commented 8 months ago

Thanks @brunorosilva the update and closest solution to task. Great of see TTM plot function is coming up; would you able to share when could we expect this? I gave it a try but I wasn't able to wrap my mind around everything with time range, labels, layout, etc

brunorosilva commented 8 months ago

I'll check it over the weekend to see if it's as easy as I'm thinking and give you an estimate. The code is quite overwhelming and verbose, honestly this is a bit of Plotly's fault haha.

brunorosilva commented 8 months ago

Hey mate, I tried to work on it over the weekend but it's harder than I thought. I'll keep on working on it and give another update once it's closer to a solve.

bhargavkakadiya commented 8 months ago

thanks for the update and trying out @brunorosilva I have moved to different representation for now and hope to see this feature and try it out soon