Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

background_gradient vmin and vmax #12145

Closed
alimanfoo opened this issue Jan 26, 2016 · 6 comments · Fixed by #29245
Closed

background_gradient vmin and vmax #12145

alimanfoo opened this issue Jan 26, 2016 · 6 comments · Fixed by #29245
Labels
good first issue IO HTML read_html, to_html, Styler.apply, Styler.applymap

Comments

@alimanfoo
Copy link

Working with the new style API, I would like to turn several columns of a dataframe into something like a heatmap. I would like to use the same range for all columns in the subset, i.e., the colour map should take a minimum and maximum value I specify, regardless of what actual range each column has. Currently using the "min" and "max" this is not intuitive. I would much prefer to be able to specify explicit vmin and vmax values, analogous to the seaborn.heatmap function.

Thanks for the style API, extremely useful.

@TomAugspurger
Copy link
Contributor

That's what I wanted initially as well, but didn't have time to do it properly before the last release. I wonder if we should just require seaborn for those parameters, and use its heuristics for determining a good colormap and handling vmin/vmax.

@TomAugspurger TomAugspurger added the IO HTML read_html, to_html, Styler.apply, Styler.applymap label Jan 26, 2016
@TomAugspurger TomAugspurger added this to the Next Major Release milestone Jan 26, 2016
@mpschr
Copy link

mpschr commented Feb 19, 2016

Hi,

I have some feedback which IIUC is related to what @alimanfoo is saying. The background_gradient as well as the bar style methods should have the same axis options as the highlight_max method:

axis: int, str, or None; default None

It can be very misleading if the color scale is only applied to each column separately - particulary when I specify a subset of columns (which represent the same measure) I expected them to be represented with the same color scale by default. I tried to set axis=None for the above mentioned methods, but unluckily an error is being raised from that.
I get that the feature is new and hopefully this will be possible soon. Apart from my negative criticism: Kudo's for the good work.

@interrogator
Copy link

Couldn't agree more with @mpschr --- axis = None should even be the default. Anybody know a workaround for now?

@TomAugspurger TomAugspurger added the Code Style Code style, linting, code_checks label Mar 11, 2016
@TomAugspurger TomAugspurger removed the Code Style Code style, linting, code_checks label May 17, 2016
@davidbrochart
Copy link

@alimanfoo I'm not sure it applies directly to your problem, but to get the equivalent of vmin/vmax for the colormap, I do the following:

# given df, cmap, vmin, vmax:
df_data = df.copy()
df = df.clip(vmin, vmax)
df = df.style.background_gradient(cmap=cmap)
df.data = df_data

@soxofaan
Copy link
Contributor

FYI: axis = None support is being added under PR #21259

immaxchen added a commit to immaxchen/pandas that referenced this issue Oct 27, 2019
Resolve pandas-dev#12145 and pandas-dev#28869
For `vmin` and `vmax` use the same implementation in `Styler.bar`
For dtype `Int64` issue, deprecated `.values` and use `.to_numpy` instead
Here explicitly assign the dtype to float since we are doing normalize
TomAugspurger pushed a commit that referenced this issue Nov 3, 2019
…29245)

* ENH: Styler.background_gradient to accept vmin vmax and dtype Int64

Resolve #12145 and #28869
For `vmin` and `vmax` use the same implementation in `Styler.bar`
For dtype `Int64` issue, deprecated `.values` and use `.to_numpy` instead
Here explicitly assign the dtype to float since we are doing normalize
@interrogator
Copy link

Thanks everyone, much appreciated.

Reksbril pushed a commit to Reksbril/pandas that referenced this issue Nov 18, 2019
…andas-dev#29245)

* ENH: Styler.background_gradient to accept vmin vmax and dtype Int64

Resolve pandas-dev#12145 and pandas-dev#28869
For `vmin` and `vmax` use the same implementation in `Styler.bar`
For dtype `Int64` issue, deprecated `.values` and use `.to_numpy` instead
Here explicitly assign the dtype to float since we are doing normalize
proost pushed a commit to proost/pandas that referenced this issue Dec 19, 2019
…andas-dev#29245)

* ENH: Styler.background_gradient to accept vmin vmax and dtype Int64

Resolve pandas-dev#12145 and pandas-dev#28869
For `vmin` and `vmax` use the same implementation in `Styler.bar`
For dtype `Int64` issue, deprecated `.values` and use `.to_numpy` instead
Here explicitly assign the dtype to float since we are doing normalize
proost pushed a commit to proost/pandas that referenced this issue Dec 19, 2019
…andas-dev#29245)

* ENH: Styler.background_gradient to accept vmin vmax and dtype Int64

Resolve pandas-dev#12145 and pandas-dev#28869
For `vmin` and `vmax` use the same implementation in `Styler.bar`
For dtype `Int64` issue, deprecated `.values` and use `.to_numpy` instead
Here explicitly assign the dtype to float since we are doing normalize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue IO HTML read_html, to_html, Styler.apply, Styler.applymap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants