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

Add value labels of your data to hvplot by using parameter instead of hv.Labels() #375

Open
SandervandenOord opened this issue Nov 17, 2019 · 6 comments · May be fixed by #496
Open

Add value labels of your data to hvplot by using parameter instead of hv.Labels() #375

SandervandenOord opened this issue Nov 17, 2019 · 6 comments · May be fixed by #496
Labels
type: enhancement New feature or request
Milestone

Comments

@SandervandenOord
Copy link
Contributor

SandervandenOord commented Nov 17, 2019

If you want to add value labels to your data you have to overlay holoviews hv.Label() on your plot:

# import libraries
import numpy as np
import pandas as pd

import holoviews as hv
import hvplot.pandas

# create some sample data
df = pd.DataFrame({
    'col1': ['bar1', 'bar2', 'bar3'],
    'col2': np.random.rand(3)
})

# create your plot
plot = df.hvplot(kind='bar', x='col1', y='col2', ylim=(0, 1.2))

# create your labels separately
# kdims specifies the x and y position of your value label
# vdims specifies the column to use for the value text of your label
labels = hv.Labels(data=df, kdims=['col1', 'col2'], vdims='col2')

# use the * symbol to overlay your labels on your plot
plot * labels

It would be nice if you could just use something like parameter

value_labels=True

to do this automagically right away with hvplot:

plot = df.hvplot(kind='bar', x='col1', y='col2', ylim=(0, 1.2), value_labels=True)

See also: https://stackoverflow.com/questions/58900736/adding-value-labels-to-hvplot-bar

If possible the default offset should also be a bit smart:

Screenshot 2019-11-17 at 16 24 49

@jsignell
Copy link
Member

I think this would be a really nice feature.

Just as a note - I ran into this as well while working on a bar plot that is grouped:

df = pd.DataFrame([
    (' Spark', 'Row count', 17.6),  # The space is to order Spark first
    (' Spark', 'Feature engineering', 63),
    (' Spark', 'Random forest', 166),
    ('RAPIDS', 'Row count', 20.8),
    ('RAPIDS', 'Feature engineering', 24.1),
    ('RAPIDS', 'Random forest', 1.75)
], columns=['tool', 'task', 'runtime_seconds'])
df.hvplot.bar(x='task', y='runtime_seconds', by='tool')

image

I wasn't able to figure out the right hv.Labels to overlay that would put the values at the top of the bars.

@jsignell
Copy link
Member

If this is agreed to be a good idea, I'd be happy to open a PR :)

@jbednar
Copy link
Member

jbednar commented Jul 27, 2020

Sounds good to me; I too have wanted this!

@jsignell jsignell linked a pull request Jul 28, 2020 that will close this issue
@andreale28
Copy link

If you want to add value labels to your data you have to overlay holoviews hv.Label() on your plot:

# import libraries
import numpy as np
import pandas as pd

import holoviews as hv
import hvplot.pandas

# create some sample data
df = pd.DataFrame({
    'col1': ['bar1', 'bar2', 'bar3'],
    'col2': np.random.rand(3)
})

# create your plot
plot = df.hvplot(kind='bar', x='col1', y='col2', ylim=(0, 1.2))

# create your labels separately
# kdims specifies the x and y position of your value label
# vdims specifies the column to use for the value text of your label
labels = hv.Labels(data=df, kdims=['col1', 'col2'], vdims='col2')

# use the * symbol to overlay your labels on your plot
plot * labels

It would be nice if you could just use something like parameter

value_labels=True

to do this automagically right away with hvplot:

plot = df.hvplot(kind='bar', x='col1', y='col2', ylim=(0, 1.2), value_labels=True)

See also: https://stackoverflow.com/questions/58900736/adding-value-labels-to-hvplot-bar

If possible the default offset should also be a bit smart:

Screenshot 2019-11-17 at 16 24 49

Is there any solution to adding labels for each bar on your example, or maybe each bar with different colors?

@jbednar
Copy link
Member

jbednar commented Aug 29, 2022

Agreed; that would be a good feature. Does .plot support this? If so we can copy its interface.

@andreale28
Copy link

andreale28 commented Sep 7, 2022

We can input a parameter c= in hvplot.bar(c='name-of-x-columns'). This is a trick/tip I have found to make hvplot.bar() display each bar with different colors and labels.

This trick/tip is from notebook

@maximlt maximlt added type: enhancement New feature or request and removed TRIAGE labels Oct 18, 2022
@maximlt maximlt added this to the 0.9.0 milestone Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants