[go: nahoru, domu]

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

How to create a panel of plots when using, for example, tsne #137

Closed
fbrundu opened this issue May 1, 2018 · 6 comments
Closed

How to create a panel of plots when using, for example, tsne #137

fbrundu opened this issue May 1, 2018 · 6 comments

Comments

@fbrundu
Copy link
Contributor
fbrundu commented May 1, 2018

Hi,
Would it be possible to create a panel of plots using both rows and columns when plotting tsne?
I did something similar to this:
tsne markers

Basically the code calls the matplotlib subplots method based on the number of plots:

def _build_subplots(n):
  '''
  Build subplots grid
  n: number of subplots
  '''
  nrow = int(np.sqrt(n))
  ncol = int(np.ceil(n / nrow))
  fig, axs = plt.subplots(nrow, ncol, dpi=100, figsize=(ncol*5, nrow*5))

  return fig, axs, nrow, ncol

Then the plots are drawn:

genes = [...list of gene symbols...]
fig, axs, nrow, ncol = _build_subplots(len(genes))

if type(axs) != np.ndarray:
  axs = [axs]
else:
  axs = axs.ravel()

for i in range(nrow*ncol):
  if i < len(genes):
    gene = genes[i]
    # df is the numpy array containing tSNE
    axs[i].scatter(df[:, 0], df[:, 1], ...)

Is it something that is already done, planned or that you don't want to integrate?

Thanks,
Francesco

@falexwolf
Copy link
Member
falexwolf commented May 3, 2018

Dear Francesco,

sorry about the late response... These days are incredibly busy.

Currently this is not on the list of urgent things. If you find an elegant way of introducing this in all the plotting functions at once, happy to discuss some prototype code.

For now, you can just use your method

for i in range(nrow*ncol):
  if i < len(genes):
    gene = genes[i]
    # df is the numpy array containing tSNE
    ax = sc.pl.scatter(ax=axs[i], show=False)

What do you think?
Alex

@fbrundu
Copy link
Contributor Author
fbrundu commented May 3, 2018

Thanks @falexwolf ,
No worries. I'd like to contribute when I can, but I'd need some time to understand how the code is structured. For now I'll be using your suggestion. If I have time I'll provide a PR.

Thanks again for the library,
Francesco

@jamestwebber
Copy link
Contributor
jamestwebber commented Aug 15, 2018

@falexwolf we just tried the solution you posted and it reveals a bug: when ax is not None you don't create the variable axs and thus throw an error here: https://github.com/theislab/scanpy/blob/master/scanpy/plotting/anndata.py#L634

Should be a simple fix (I think):

if ax is None:
    axs, _, _, _ = setup_axes(ax=ax, panels=['x'] if groupby is None else keys, show_ticks=True, right_margin=0.3)
else:
    axs = [ax]

@falexwolf
Copy link
Member

Yes, indeed! Should be fixed 8fab0d1

But there were no problems with pl.scatter, right?

@jamestwebber
Copy link
Contributor

I didn't actually check, but @aopisco will tell you soon...

@aopisco
Copy link
Contributor
aopisco commented Aug 16, 2018

yes, now it works for pl.scatter and pl.violin

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

5 participants