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

Show just selected months #19

Closed BabaMasha closed 1 year ago

BabaMasha commented 1 year ago

Hi, great plot!

Would it be possible to add the feature of showing just few months instead of Jan-Dec? For example only Mar-Aug.

Like in july (https://github.com/e-hulten/july)

Best, Maryna

brunorosilva commented 1 year ago

Hi, Maryna

Do you think something like this suits your purpose? image

Of course it'd be responsive with adjustable width image

BabaMasha commented 1 year ago

Hi Bruno,

Yes this would be perfect, thanks a lot!

Greetings, Maryna

brunorosilva commented 1 year ago

Great, I'll be adding it in the next release. I'm just wrapping up some CI/CD details and input validations.

The code will look like this

import numpy as np
import pandas as pd

from plotly_calplot.calplot import calplot, month_calplot

# mock setup
dummy_start_date = "2019-01-01"
dummy_end_date = "2022-10-03"
dummy_df = pd.DataFrame(
    {
        "ds": pd.date_range(dummy_start_date, dummy_end_date),
        "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",
    showscale=True,
    start_month=3,
    end_month=10
)

image