Skip to content

ENH: I wish add a parameter to adjust bar function's height in Styler #36419

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
slsongge opened this issue Sep 17, 2020 · 11 comments · Fixed by #42483
Closed

ENH: I wish add a parameter to adjust bar function's height in Styler #36419

slsongge opened this issue Sep 17, 2020 · 11 comments · Fixed by #42483
Labels
Enhancement Styler conditional formatting using DataFrame.style
Milestone

Comments

@slsongge
Copy link

Is your feature request related to a problem?

I have a 'Styler' object, I wish add a parameter that can adjust bar's spacing to the bar function.

eg:
now the bar example like bottom:
image

but I wish like bottom:
image

Thx!!!

@slsongge slsongge added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 17, 2020
@MarcoGorelli
Copy link
Member

Hi @slsongge - could you write a descriptive title please?

I wish add a parameter

As in, are you interested in contributing it?

@MarcoGorelli MarcoGorelli added Styler conditional formatting using DataFrame.style and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 17, 2020
@rluong003
Copy link

Hi, I'm new to open source. May I work on this?

@rluong003
Copy link

take

@MarcoGorelli MarcoGorelli changed the title ENH: ENH: add parameter to adjust bar function's height in Styler Sep 24, 2020
@rluong003
Copy link

rluong003 commented Sep 27, 2020

@MarcoGorelli any pointers on how to do this?
I created a dataframe that goes from 1-10.
I used the render() function to take the HTML of the dataframe and recreate the table in JSFiddle.
I tried adding this CSS property in JSFiddle into the td tags :

border-bottom: 20px solid white;

and this seemed to create the spacing I wanted.

However, when I tried to inject this CSS property into the css_bar() function in the _bar static method as a string, it doesn't work when I run the bar function in my Jupyter notebook.

@MarcoGorelli
Copy link
Member

Hi @rluong003 - I'm not familiar with CSS or with this part of the code, sorry

cc @TomAugspurger in case you have suggestions

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Sep 28, 2020 via email

@rluong003
Copy link

@attack68 I see you have added many improvements to the Styler class recently, do you have any pointers on how to solve this?

@attack68
Copy link
Contributor

The _bar function works by adding a linear gradient background via CSS.
The simplest way I can think of doing this would be to add a margin or padding option to the cell to create the spacing, but that might have other unintended consequences and/or might not work.

Failing that, there might be another ways of manipulating the data or css to do this, but it would be quite complicated.

But, to be honest, the bar function is kind of a hack to get a bar chart in the background. This feature enhancement is really a hack to a hack, and would be rarely used.
If padding or margin did not work I would be inclined to pass on the request as simply being too esoteric with a high coding cost.

@rluong003 rluong003 removed their assignment Sep 29, 2020
@slsongge slsongge changed the title ENH: add parameter to adjust bar function's height in Styler ENH: I wish add a parameter to adjust bar function's height in Styler Sep 29, 2020
@MarcoGorelli
Copy link
Member

I would be inclined to pass on the request as simply being too esoteric with a high coding cost

Agreed - closing for now then to (slightly) declutter the issue tracker

@MarcoGorelli MarcoGorelli added this to the No action milestone Feb 7, 2021
@attack68
Copy link
Contributor

Actually realised a simple way of doing this:

  1. Add no-repeat center to the background CSS value
  2. Add background-size: 100% 50%; to control the vertical width of the bar.
df = pd.DataFrame({"A": [10, 11, 13, 15]})
df.style.bar(align="left", vmin=3, color=["#d65f5f", "#5fba7d"], width=60)

with CSS modified to:

#T_4bb6b_row0_col0 {
  width: 10em;
  background: linear-gradient(90deg,#5fba7d 35.0%, transparent 35.0%) no-repeat center;
  background-size: 100% 30%;
}
#T_4bb6b_row1_col0 {
  width: 10em;
  background: linear-gradient(90deg,#5fba7d 40.0%, transparent 40.0%) no-repeat center;
  background-size: 100% 30%;
}
#T_4bb6b_row2_col0 {
  width: 10em;
  background: linear-gradient(90deg,#5fba7d 50.0%, transparent 50.0%) no-repeat center;
  background-size: 100% 30%;
}
#T_4bb6b_row3_col0 {
  width: 10em;
  background: linear-gradient(90deg,#5fba7d 60.0%, transparent 60.0%) no-repeat center;
  background-size: 100% 30%;
}

the design is:
Screen Shot 2021-06-30 at 12 22 03
instead of:
Screen Shot 2021-06-30 at 12 22 29

@attack68 attack68 reopened this Jun 30, 2021
@jreback jreback modified the milestones: No action, 1.4 Jul 12, 2021
@slsongge
Copy link
Author

thank you

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

Successfully merging a pull request may close this issue.

6 participants