brunorosilva / plotly-calplot

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

Years title interaction #3

Closed ghhar98 closed 2 years ago

ghhar98 commented 2 years ago

Hi, I tried using this package, which I find really useful. My problem is that when I'm making my calendar heatmap, the year label interact with the heatmap above :

image

The code I'm using to generate the plot is

fig = calplot( df_day_count, x="date", y="count", name="Number of events", years_title=True )

While my df looks like this : image

Thanks.

brunorosilva commented 2 years ago

Hey @ghhar98 ,

The spacing between two years is a bit sketchy at times and I'll work on a definite fix, but as a quick fix for your problem, try to use the space_between_plots parameter, it's default is 0.08 as this worked ok(ish) on the data I tested.

Here are some examples on how to use it with sample data:

with space_between_plots = 0.08 (default) image

with space_between_plots = 0.12 image

with space_between_plots = 0.25 image

ghhar98 commented 2 years ago

Thanks for your response, it's now working. Maybe off subject, but I was also wondering if it currently was possible to add a legend to the plot for the color scale? I can't find an option for it

brunorosilva commented 2 years ago

Yes, this is possible. It's not a native option in the library, but you can do it using update_traces with the heatmap selector updating the showscale property to None or to True, as the example below.

fig = calplot(
    dummy_df,
    x="ds",
    y="value",
    years_title=True,
    space_between_plots=0.12,
)
fig.update_traces(showscale=True, selector=dict(type="heatmap"))
image

And of course you can add customization to the scale

fig.update_traces(colorbar=dict(
    title="Events per Cell",
    thicknessmode="pixels", thickness=10,
    lenmode="pixels", len=300,
    yanchor="middle",
    ticks="outside", 
    ticksuffix=" events",
    dtick=2
), showscale = True, selector=dict(type='heatmap'))
image
brunorosilva commented 2 years ago

@ghhar98 sorry to tag you, but did my response solve your issue?

ghhar98 commented 2 years ago

Yes, thank you!