pertpy icon indicating copy to clipboard operation
pertpy copied to clipboard

Suggestion for a better layout of coda `plot_boxplots()` subplots

Open shihsama opened this issue 10 months ago β€’ 5 comments

Description of feature

Hi, Thank you for your attention to the issue I raised last time. This time, I have a suggestion for layout of plot_boxplots(). In source code:

 g = sns.FacetGrid(
            plot_df,
            col="Cell type",
            sharey=False,
            col_wrap=int(np.floor(np.sqrt(K))),
            height=height,
            aspect=aspect,
        )

If we have 5 to 8 subplots, the np.floor() will make it 2 columns, if 10 to 15, 3 columns. Some users may like such a "long" layout, but some may not. Therefore, could you add an arguement to define subplot layout to choose "long" or "wide". If we choose "long",col_wrap=int(np.floor(np.sqrt(K))); if we choose β€œwide”, col_wrap=int(np.ceil(np.sqrt(K))). Thanks for your attention gain! For better experience~

shihsama avatar Feb 27 '25 04:02 shihsama

Thank you very much for the idea! We'll see what we can do but pull requests with such a change that outline the before and after are also welcome.

Zethson avatar Feb 27 '25 06:02 Zethson

@shihsama: Do you have a public (small) dataset that could be used as an example for this issue? If you could provide some code for me to reproduce the 'long' plot you are talking about, I could tackle the implementation of the 'wide' version.

mschilli87 avatar Jun 16 '25 07:06 mschilli87

@mschilli87: Sorry for the delayed reply. I have not found a suitable public dataset. I had tested the code described above in my unpublished data. Because I prefer the 'wide' plot layout, I directly modified it in the source code of pertpy. Probably, the PBMC5k dataset is suitable. To produce specific number of cell types, we could subset the dataset with 'cell type' labels :)

As described above, for instance, assume that we have 5~8 cell types, int(np.floor(np.sqrt(K))) will produce 2 columns of subplots ("long" layout) while int(np.ceil(np.sqrt(K))) will produce 3 columns of subplots ("wide" layout). As for 4, 9, or 16 cell types (subplots), it's easy for us to get that it is a "square" layout :)

layout = layout  ##assume a new arguement called "layout"

if layout == "wide":
    col_wrap = int(np.ceil(np.sqrt(K)))  
else:  
    col_wrap = int(np.floor(np.sqrt(K)))  

g = sns.FacetGrid(
    plot_df,
    col="Cell type",
    sharey=False,
    col_wrap=col_wrap,
    height=height,
    aspect=aspect,
)

shihsama avatar Jun 18 '25 09:06 shihsama

No worries. I wouldn't get to this before next week or the one after anyway. Until then it would really help me to have a small example I can copy/paste to generate the (current default) 'long' layout and ideally the 'wide' version generated by your modified code for the same dataset. This way, I have a very clear way of making sure I understood your suggestion correctly which will make it easier for me to add this more quickly.

If you don't have time, I think you feature request contains all information required to do it. But the more effort you put in, the higher this will be on my priority list. πŸ˜‰

mschilli87 avatar Jun 18 '25 09:06 mschilli87

No worries. I wouldn't get to this before next week or the one after anyway. Until then it would really help me to have a small example I can copy/paste to generate the (current default) 'long' layout and ideally the 'wide' version generated by your modified code for the same dataset. This way, I have a very clear way of making sure I understood your suggestion correctly which will make it easier for me to add this more quickly.

If you don't have time, I think you feature request contains all information required to do it. But the more effort you put in, the higher this will be on my priority list. πŸ˜‰

Not quite urgent and big issueπŸ˜‰πŸ€πŸ»πŸ€πŸ»πŸ€πŸ».

shihsama avatar Jun 18 '25 10:06 shihsama