umap icon indicating copy to clipboard operation
umap copied to clipboard

umap.plot got the legend blocking some data points

Open jfredfan opened this issue 4 years ago • 4 comments

How do I configure the legend position, at least moving it outside of the main figure? I am in Ubuntu and running the following source code from shell.

import numpy as np import sklearn.datasets import umap import umap.plot

data, labels = sklearn.datasets.fetch_openml( 'mnist_784', version=1, return_X_y=True )

mapper1 = umap.UMAP().fit(data)

umap.plot.points(mapper1, labels=labels) umap.plot.plt.show()

Figure_1

jfredfan avatar Aug 19 '20 01:08 jfredfan

It is a matplotlib figure, you you can use the standard matplotlib commands to handle the legend. For example adding a line with:

plt.legend(bbox_to_anchor=(1, 1.05), loc=2)

might do the job.

lmcinnes avatar Aug 19 '20 13:08 lmcinnes

plt.legend seems to error with "No handles with labels found to put in legend."

Does umap.plot.points return a matplotlib Axis object?

  • Trying to treat it as an Axis object and extracting label handles doesn't seem to work either.

stan-hua avatar Jul 14 '21 04:07 stan-hua

In practice you may need to create your own handles to pass to legend. This is, obviously, not ideal but it should work. Ultimately this is not meant to be a comprehensive plotting library -- more just helper functions to get things up and running quickly. If you really need custom plotting I would suggest just going to matplotlib or datashader directly. Sorry I can't be more help.

lmcinnes avatar Jul 19 '21 15:07 lmcinnes

same problem.

jacklanda avatar Jul 28 '23 08:07 jacklanda