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

Manually Change min and max Value #18

Open soerenetler opened 1 year ago

soerenetler commented 1 year ago

Hello again, When using calplot I notice that the min value of the heatmap is fixed to 0 und the max value is fixed to the highest datapoint in the column. It would be great to manually change these values to e.e. allow for negative number and change the maximum value e.g. from 980 in the dataset to 1000 to make the scale easier to understand. This is currently not possible or did I miss anything. thank you for your work again and all the best, Sören

brunorosilva commented 1 year ago

Hi, that's true. It's not currently possible to assign a min value. I'll work on this ASAP.

soerenetler commented 1 year ago

Amazing! If you want I could also take a look. Sounds like a good first issue to solve :)

OmniaData commented 1 year ago

Hi Bruno, great package; as soon as I saw it I thought it would be great for visualising the return on public transport usage for my dissertation. However, a lot of the data I'm looking at has movement from a zero baseline either in the positive and negative direction.

As Sören pointed out, it would be great to be able to visualise -ve to +ve values or set the min and max range.

Looking forward to the update!

Chris

brunorosilva commented 1 year ago

Hi @soerenetler and @OmniaData , I'll be adding this feature in the next release.

I'd be happy to hear some opinions.

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(
            0,
            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,
    cmap_max=20,
    cmap_min=10
)

image


fig1 = calplot(
    dummy_df,
    x="ds",
    y="value",
    showscale=True,
    cmap_max=50
)

image

fig1 = calplot(
    dummy_df,
    x="ds",
    y="value",
    showscale=True,
    cmap_max=25,
    cmap_min=-10,
    colorscale="rdylgn"
)

image

OmniaData commented 1 year ago

That's fantastic, Bruno. Looking forward to it!

I do prefer manually setting min and max values; however, for end-user experience, I would suggest the option to auto scale min and max based on the dataframe values.

I've also been using arcGIS the last few days. A cool feature they have on mapping colours is the ability to choose from natural breaks (Jenks), equal interval, and quantiles. Additionally, you are able to select the number of classes (last image) that the colour steps are broken in to. No pressure to add it as a feature, but it may be something that you'd like to check out for the future.

image

If you are interested, more information can be found here:

brunorosilva commented 1 year ago

@OmniaData that's awesome. I've been looking for something like the natural breaks algorithm for a while, just didn't know how to phrase it correctly.

I should've been clearer, I've added auto scaling by default based on the dataframe min and max values and added the cmap_max and cmap_min as optional params.

brunorosilva commented 1 year ago

I'll leave this issue open so these references won't get lost.