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

Manually Change min and max Value

Open soerenetler opened this issue 3 years ago • 7 comments

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

soerenetler avatar Jan 17 '23 09:01 soerenetler

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

brunorosilva avatar Feb 09 '23 18:02 brunorosilva

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

soerenetler avatar Feb 10 '23 09:02 soerenetler

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

OmniaData avatar Mar 19 '23 04:03 OmniaData

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

brunorosilva avatar Mar 23 '23 07:03 brunorosilva

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:

  • https://doc.arcgis.com/en/power-bi/design/classification-types.htm
  • https://pro.arcgis.com/en/pro-app/latest/help/mapping/layer-properties/data-classification-methods.htm

OmniaData avatar Mar 23 '23 22:03 OmniaData

@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 avatar Mar 27 '23 13:03 brunorosilva

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

brunorosilva avatar Mar 27 '23 19:03 brunorosilva