plotly-calplot icon indicating copy to clipboard operation
plotly-calplot copied to clipboard

plot for trailing 12 months

Open bhargavkakadiya opened this issue 2 years ago • 6 comments

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

bhargavkakadiya avatar Jan 09 '24 22:01 bhargavkakadiya

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 avatar Jan 10 '24 18:01 brunorosilva

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.

brunorosilva avatar Jan 10 '24 18:01 brunorosilva

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

bhargavkakadiya avatar Jan 10 '24 22:01 bhargavkakadiya

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 avatar Jan 11 '24 16:01 brunorosilva

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.

brunorosilva avatar Jan 16 '24 15:01 brunorosilva

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

bhargavkakadiya avatar Jan 17 '24 19:01 bhargavkakadiya