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

Overlapping bins in the HTML visualization. #251

Open
fferegrino opened this issue Nov 27, 2023 · 0 comments
Open

Overlapping bins in the HTML visualization. #251

fferegrino opened this issue Nov 27, 2023 · 0 comments

Comments

@fferegrino
Copy link

Description
There is overlap in the member distribution histogram when the number of visualized bins is greater than 10.

To Reproduce

import kmapper as km
from sklearn import datasets
data, labels = datasets.make_circles(n_samples=5000, noise=0.03, factor=0.3)

mapper = km.KeplerMapper(verbose=1)

projected_data = mapper.fit_transform(data, projection=[0,1]) # X-Y axis

graph = mapper.map(projected_data, data, cover=km.Cover(n_cubes=10))

NBINS = 20

mapper.visualize(graph, path_html="make_circles_keplermapper_output_5.html",
                 nbins = NBINS,
                 title="make_circles(n_samples=5000, noise=0.03, factor=0.3)")

With keppler-mapper version 2.0.1.

Expected behavior
It would be great if all the histogram bars would adjust their size to accommodate all the desired bins.

Screenshots

The above code generates the following:

Overflowing bins

But I have some internal code that generates this, where the overlap is more evident:

More evident overlap

Additional context
I was digging around and found that the code that generates the histogram is in the function set_histogram

function set_histogram(selection, data){
selection.selectAll('.bin')
.data(data)
.join(
enter => enter.append('div')
.attr('class', 'bin')
.call(enter => enter.append('div')
.text(d => d.perc + '%'))
,
update => update
.call(update => update.select('div')
.text(d => d.perc + '%'))
)
.style('height', (d) => (d.height || 1) + 'px')
.style('background', (d) => d.color);
}

I was thinking it would be possible to modify the width of the bars (just like the height is), however I can't find a clean way to get the parent's width.

I am happy to open a PR with my current, not-so-great solution, but I was wondering if you had any guidance on how to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant