Comments (16)
Beautiful! Definitely interested in implementing this as an option. Thanks!
from kepler-mapper.
@sauln Plotly displays a toolbar in the upper-right part of each plot (just hover the mouse over that region to see it), that allows to zoom in, zoom out, select a box, and more.
At this moment one works on ipyplotly
that will allow node dragging. It will
be available no sooner than two months.
In visuals.py there are a few lines to format the tooltips, meta data ,via html tags (i.e. the original meta_data), but when path_html
is None, the text is formated as in Plotly. These are the only duplicates.
Example:
if custom_tooltips is not None:
if path_html is None:
tooltip += "<br>Members: "
else:
tooltip += "<h3>Members</h3>"
for custom_tooltip in custom_tooltips[member_ids]:
tooltip += "%s " % (custom_tooltip)
from kepler-mapper.
Hi @empet!
- I wish we could use f-strings, but for the time being, we should continue to support older Python versions. An aesthetically pleasing replacement that I've been using is
text = "Foo is {age} {units} old".format(**locals())
If you have to do lots of string formatting, I would try to offload it to Jinja2 as much as possible.
-
I assume the histogram values originally assumed the color function was normalized between 0 and 1. The normalization you suggest in the function look great and I'd readily merge a PR with those changes!
-
Both look amazing, but I think the first on is a little easier to look at.
Thank you for putting all your hard work into this! I look forward to incorporating and using these great improvements!
from kepler-mapper.
These look beautiful! Thank you for working on this. I'm excited to use this for my own projects π
Please do open a PR and I will work over the next few weeks to review and demo everything.
from kepler-mapper.
@sauln Finally here are the saved pdfs from plotly images of the kmapper graphs:
from kepler-mapper.
This is really cool! Thanks for putting all of this together.
I would love to see what the changes are to the main kmapper.py file, but didn't see them on your fork. Please feel free to create a pull request so we can do a more formal code review.
I agree that this sort of setup could be more natural for many Python programmers, and I have been frustrated myself working with km in a notebook. For these reasons, I think this could be a great alternative.
My main worries are:
- Is there interactivity? I've relied on being able to manipulate and draw the nodes around, and I'm not sure if plotly will support this sort of manipulation.
- How fractured will the visualization tooling become? It would be preferable to not have to duplicate features in both systems.
from kepler-mapper.
@empet Sorry for the delay, I completed the code review. Overall, the changes look great. We'll definitely merge as soon as a few things in the PR are cleaned up. See my code review.
from kepler-mapper.
@sauln I performed the changes listed here. Let me know if more are needed.
from kepler-mapper.
Hi @Empt, I hope all has been going well. I implemented a basic adapter to convert the graph output to networkx representation, and started scratching some plotting methods using matplotlib. These can be found here and here respectively.
I'm thinking that the networkx representation will make it considerably easier to leverage existing visualization tools. Do you think the plotly methods will be able to build on this?
I know the original implementation followed the D3 visualization closely. Do you think it would be possible to have everything self contained in drawing.py
?
This code is all in draft, so any thoughts you have on how to architecture this would be great.
Thanks,
from kepler-mapper.
Hi @sauln,
Today I started working on the new version of Plotly viz of kmapper graphs.
It's not difficult to use networkx, but unfortunately it provides less graph layouts compared with igraph. Moreover, the kamada-kawai layout that is very useful for kmapper graphs does not work for disconnected networks: http://nbviewer.jupyter.org/github/empet/Networks/blob/master/kk-layout-in-3-packages-netsci.ipynb
Using Plotly 3.+ I can save a svg
or png
image of the graph. svg
can be converted to pdf
via Inkscape https://inkscape.org/en/ and then printed or included in a LaTeX file for publication.
from kepler-mapper.
@sauln To be more convincing I paste here three images for comparison:
- igraph kk layout for digits data set:
- networkx kk layout for the same data:
- networkx spring layout:
from kepler-mapper.
oh wow, the igraph layout is so much better! I'll have to familiarize myself with the library.
from kepler-mapper.
@sauln I have a few questions:
-
May I use f-strings that can be interpreted only by Python 3.6+? They have a much more simple syntax compared with older string formatting methods.
-
I have a perplexity about the function
build_histogram()
.
Why did you choose hmin=0, hmax=1?
For the breast cancer data set, for example, I chose
color_function=lens[:,0]-lens[:,0].min()
that has values between:
color_function.min(), color_function.max()=0.0, 0.30720700761143532
In this case
min(node_averages), max(node_averages)
are 0.044648797686642538, 0.29316562035235677
and the corresponding histogram is this one:
It looks odd because in the function
build_histogram
, h_min, h_max=0, 1
but in this case they should be min(node_averages), max(node_averages)
I normalized the data=node_averages
inside the body of the build_histogram()
and got the right histogram (see the next two images).
More precisely the modified function is:
def build_histogram(data):
# Build histogram of data based on values of color_function
h_min, h_max = min(data), max(data)#HERE
hist, bin_edges = np.histogram(data, range=(h_min, h_max), bins=10)
bin_mids = np.mean(np.array(list(zip(bin_edges, bin_edges[1:]))), axis=1)
histogram = []
max_bucket_value = max(hist)
sum_bucket_value = sum(hist)
for bar, mid in zip(hist, bin_mids):
height = int(((bar / max_bucket_value) * 100) + 1)
perc = round((bar / sum_bucket_value) * 100., 1)
print(_color_idx(mid))
color = palette[_color_idx((mid-h_min)/(h_max-h_min))]# AND HERE is the normalization
histogram.append({
'height': height,
'perc': perc,
'color': color
})
return histogram
- For Color function distribution I could display information only in tooltips or both in tooltips and in printed text on each bar. Which one do you suggest to implement?
Here are the two versions:
from kepler-mapper.
Hi @sauln,
Working further I realized that the function build_histogram()
is OK with h_min, h_max=0,1,
because the color_function
is normalized inside the function init_color_function()
.
It was my fault since I didn't integrate completely the plotlyviz in kepler-mapper, and I forced it to work by pasting a few functions from visual.py into the notebook. So my color_function
got non-normalized.
Hence no change is needed. I'm sorry for misleading you!
from kepler-mapper.
Hi @sauln,
Here are two images that illustrate how I decided to display the mapper graph+the mapper summary:
respectively the cluster stats:
The mapper summary is splitted into two parts:
the first one consists in data about graph, displayed under its plot, and the second, Algorithms and Functions + Graph Node Distribution as a separate dashboard.
I couldn't imitate your html layout, because the notebook page is a portrait page, not a landscape one, to include text on the two lateral sides.
The new version of plotly-kmapper requires plotly 3.1+, and ipywidgets. A plotly figure can be defined as a FigureWidget. Moreover the Ipywidgets allow to update the Cluster Member Distribution when hovering over the graph nodes (see the gif file), and the textbox displaying the cluster stats.
In a few days will be released the plotly 3.2 version that integrates a module for saving plotly plots as raster or vector images (svg, pdf). Then I'll add a function to save the mapper graph in one of these image formats.
Could you,please, suggest how to proceed with this new version? Should I open a new PR?
from kepler-mapper.
These all look great! Letβs start merging!
from kepler-mapper.
Related Issues (20)
- try different min_intersections from the visualization
- not able to understand this HOT 1
- Class methods are not being rendered by autosummary
- Examples, gallery not included in readthedocs build HOT 2
- idea: rewrite main readme and release file to .rst, import into docs HOT 5
- Bug: min_cluster_samples should not be set to a non-integer HOT 4
- plotlyviz expects 1d color values, but gets 2d instead HOT 1
- Outdated Documentation HOT 1
- `test_cubes_overlap` may be faulty HOT 2
- Idea - Convert networkx graph object or a graph in edge list format to a Mapper object HOT 8
- Doc toc restructure proposal (minor) HOT 4
- Shadowed test fails to run
- Min-Max confusion in projection statistic in cluster details
- making html files generated by visualize self-contained
- plotlyviz error
- Losing data
- Please refer to igraph instead of python-igraph HOT 2
- Directly producing color values for each node
- Overlapping bins in the HTML visualization.
- Issue with generating visuals in mapper HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kepler-mapper.