Skip to content

ENH: allow ranges to be set on Styler .bar() #21526

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

Closed
psychemedia opened this issue Jun 18, 2018 · 6 comments
Closed

ENH: allow ranges to be set on Styler .bar() #21526

psychemedia opened this issue Jun 18, 2018 · 6 comments
Labels
Enhancement Styler conditional formatting using DataFrame.style

Comments

@psychemedia
Copy link
Contributor

When generating in table bar charts using the Styler .bar():

  • extreme outliers in a column mask differences in other values;
  • comparisons across columns are not supported.

One solution would be to allow the setting of explicit bounds on the range of values used to limit the bar extrema using explicit values rather than s.min() and s.max().

Cell values exceeding the range limits could be extending to the cell edge / maximum limit value and then coloured with an "overflow" colour.

@WillAyd WillAyd added Needs Info Clarification about behavior needed to assess issue Visualization plotting labels Jun 18, 2018
@WillAyd
Copy link
Member

WillAyd commented Jun 18, 2018

Please be sure to checkout out the contributing guide on how to open bug reports:

https://pandas.pydata.org/pandas-docs/stable/contributing.html#bug-reports-and-enhancement-requests

This is missing version information and a minimally reproducible example. You can find more information on how to construct one of those here:

http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports

It's difficult to infer from what you have here alone exactly what the problem is and what you are looking for, so try going through the above to see if we can get to something more explicit

@psychemedia
Copy link
Contributor Author

Pandas version 0.23.0

In the following example a dataframe is created with a column containing two outlier values (x1) and two columns where it would be useful to depict and compare the values over the same range even though in this example the ranges differ:

import pandas as pd
import numpy as np

df=pd.DataFrame({'x1':list(np.random.randint(-10,10,size=10))+[-500,1000, -1000],
               'y1':list(np.random.randint(-5,5,size=13)), 'y2':list(np.random.randint(-2,3,size=13)) })

df.style.bar( align='zero', color=[ '#5fba7d','#d65f5f'])

In column x1, the outlier values set the max/min range values used to display the styled bar and the variation in the non-outlier values is masked. It would be useful to be able to set max / min limits to so that variation in the non-outlier values can be depicted. For example, setting min,max=(-10,10) and then colouring squares with outlier values [-500,1000, -1000] differently to show they are outside the depicted range.

For columns y1 and y2, it may be desired to display the bars over the same range, for example min,max=(-5,5) so that a direct visual comparison can be made across columns y1 and y2.

@soxofaan
Copy link
Contributor

FYI: pull request #21548 now includes support for vmin and vmax arguments in Styler.bar

@TomAugspurger TomAugspurger added Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap and removed Needs Info Clarification about behavior needed to assess issue labels Jun 27, 2018
soxofaan added a commit to soxofaan/pandas that referenced this issue Jul 11, 2018
soxofaan added a commit to soxofaan/pandas that referenced this issue Jul 12, 2018
soxofaan added a commit to soxofaan/pandas that referenced this issue Jul 26, 2018
soxofaan added a commit to soxofaan/pandas that referenced this issue Aug 14, 2018
soxofaan added a commit to soxofaan/pandas that referenced this issue Aug 21, 2018
TomAugspurger pushed a commit that referenced this issue Aug 30, 2018
* ENH: Styler.bar: add support for tablewise application with axis=None #21548

- eliminate code duplication related to style.bar with different align modes
- add support for axis=None
- fix minor bug with align 'zero' and width < 100
- make generated CSS gradients more compact

* ENH: Styler.bar: add support for vmin/vmax #21526

* ENH: Styler.bar: properly support NaNs

* ENH: Styler.bar: docstring improvements
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this issue Oct 1, 2018
* ENH: Styler.bar: add support for tablewise application with axis=None pandas-dev#21548

- eliminate code duplication related to style.bar with different align modes
- add support for axis=None
- fix minor bug with align 'zero' and width < 100
- make generated CSS gradients more compact

* ENH: Styler.bar: add support for vmin/vmax pandas-dev#21526

* ENH: Styler.bar: properly support NaNs

* ENH: Styler.bar: docstring improvements
@domoritz
Copy link

Is there a way to set the color range in the currently released pandas version?

@soxofaan
Copy link
Contributor

@domoritz there is a color argument, see http://pandas.pydata.org/pandas-docs/stable/generated/pandas.io.formats.style.Styler.bar.html . Also: please specify which pandas version you are using ("currently released" doesn't say a lot).

@mroeschke mroeschke added Enhancement and removed Visualization plotting labels May 7, 2020
@jbrockmendel jbrockmendel added the Styler conditional formatting using DataFrame.style label Sep 22, 2020
@mroeschke mroeschke removed IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string labels Jun 20, 2021
@attack68
Copy link
Contributor

this issue would appear to be solved by the above PRs and acceptance by OP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Styler conditional formatting using DataFrame.style
Projects
None yet
Development

No branches or pull requests

8 participants