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

Matplotlib matshow as custom tooltip #186

Open
holmbuar opened this issue Jan 15, 2020 · 3 comments
Open

Matplotlib matshow as custom tooltip #186

holmbuar opened this issue Jan 15, 2020 · 3 comments

Comments

@holmbuar
Copy link
Contributor

holmbuar commented Jan 15, 2020

Is your feature request related to a problem? Please describe.
I have a large-ish Mapper complex where the samples in each node are nine-dimensional points with grayscale values. I have manual routine for finding interesting nodes in the .html output, identify node by number, then plot these vectors using matplotlib.pyplot.matshow. That is quite tedious and not generalizable. My routine is this:

point_cloud = pd.read_csv(point_cloud_file_path, header=None, index_col=0)
# Load a list of indices for desired cluster
indices_from_node = mapper_graph['nodes']['cube232_cluster0']
spatial_map_dataframe = point_cloud.iloc[indices_from_node]
spatial_map_mean = spatial_map_dataframe.mean()
spatial_map_matrix = spatial_map_mean.values.reshape(3,3)
plt.matshow(spatial_map_matrix, cmap='gray')
plt.show()

Describe the solution you'd like
I would like to see the plt.show() from the snippet above to show as a tooltip in the .html output file.

Describe alternatives you've considered
I have looked around on the image tooltips and other variations from your website. Also automate routine of showing matrix subplots in a regular file.

Additional context
I don't mind trying to implement this myself, if the problem seem reasonable to solve.

@sauln
Copy link
Member

sauln commented Jan 16, 2020

I believe, instead of calling show, you could save the figure as a numpy array, such as in this SO question: https://stackoverflow.com/questions/7821518/matplotlib-save-plot-to-numpy-array

That should be roughly the same format as the image tooltips in the examples we provide.

If you generate the array for each of the nodes and set those as the tooltips, you should get the desired results.

Let me know if this makes sense and works, or if I can help with more detail.

Thanks

@holmbuar
Copy link
Contributor Author

Thanks, I'll try and implement your suggestion 👍

@holmbuar
Copy link
Contributor Author

holmbuar commented Jan 19, 2020

@sauln when passing my custom tooltips list to mapper.visualize(...), the HTML output file is corrupted due to an abundance of \n newlines in the <h3>Members</h3> tag.

Note that the python file in the gist is a mix of the custom tooltip algorithm and the whacky hack I did to avoid error in visuals.py.

I have little understanding of the HTML template. Could you please take a look and see if I have done something obviously wrong?

https://gist.github.com/torlarse/1ca1bdf50ec177822fa3d52d88b7b6e2

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

2 participants