Matplotlib matshow as custom tooltip
Opened this issue · 3 comments
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.
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
Thanks, I'll try and implement your suggestion 👍
@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