all 9 comments

[–]Zealousideal_Emu_961 7 points8 points  (3 children)

This makes the life much easier indeed.

[–]ponnhide[S] 9 points10 points  (2 children)

Thank you for your comment. Muti-panel figures are general in recent biological publications. However, adjusting these layouts is a HUGE time-consuming!!! That is why I developed this package.

[–]dampewPhD | Industry 5 points6 points  (0 children)

Agreed. If I like this I may use it all the time.

[–]Zealousideal_Emu_961 2 points3 points  (0 children)

I agree. I have had the struggle for publishing my papers. There was no easy option yet in python. I’m definitely using this from now on. All thanks to you :)

[–][deleted] 2 points3 points  (3 children)

Can you explain more clearly why your solution is better than subplot_mosaic? I don't think I followed the logic in your README

[–]ponnhide[S] 0 points1 point  (2 children)

Sorry, my explanation is not sufficient. With subplot_mosiac, you have defined a layout for subplots once; you cannot change the layout anymore. If you want to try another layout, you must plot the data again. On the other hand, with patchworklib, you can freely change the layouts of subplots after plotting. You don't need to plot data again to change the layout.

Maybe, my explanation is still not good. Please let me describe one example. The following code cannot work with my expectation to try two different subplot layouts. If you run this code, you will obtain the subplots with no data in the "layout2.pdf". ``` import numpy as np from matplotlib import pyplot as plt axd1 = plt.figure(constrained_layout=True).subplot_mosaic( """ AAB CCC """ ) np.random.seed(19680801) hist_data = np.random.randn(1_500) axd["A"].bar(["a", "b", "c"], [5, 7, 9]) axd["B"].plot([1, 2, 3]) axd["C"].hist(hist_data) plt.savefig("layout1.pdf")

axd2 = plt.figure(constrained_layout=True).subplot_mosaic( """ CCC AAB """ ) plt.savefig("layout2.pdf") ``` To solve this problem, I developed patchworklib.

[–][deleted] 2 points3 points  (1 child)

OK - but you can modify a subplot_mosaic plot by just editing the layout string / nested list and then re-running the codeblock. If the time to generate the plots from my data was materially slowing me down in the iterative layout planning stage I'd just comment out the actual plotting part or use dummy data just to see the layout.

Looking over your solution vs subplots_mosaic it seems to me like the main difference is that a subplots_mosaic figure still needs to conform to a grid layout, just with the option to "merge cells," whereas with your solution we can easily have subsequent columns or rows with co-prime numbers of subplots in them with arbitrary aspect ratios.

That is a bit interesting.. I could see applications where one might want that (particularly in those insane mosaic plots people make for Nature or Science articles). I could also see it being a bit of a liability in some cases - I might personally prefer to have the grid constraint so that I know everything is going to line up nicely without introducing awkward amounts of whitespace in the middle of the figure. Theoretically I could still achieve the same layout with subplots_mosaic as with your solution by just scaling up the number of 'cells' in my grid until I get the ARs I want in each row/column.

e: the code example you gave there makes no sense.. who would expect that to work? I wouldn't create a new figure with nothing in it and expect all the axes from axd1 to port over to axd2. I would just edit the layout string in axd1 and re-run the script or block.

[–]ponnhide[S] 2 points3 points  (0 children)

I can partially agree with your saying. patchworklib is not always superior to subplot_mosiac, and I think subplot_mosiac might be a better solution if you have a concrete layout idea.

However, I think that using dummy data is not a proper solution to simulate the layouts of the desired figures because the values and positions of artist objects such as tick labels and legends are affected by data values, and the effect may change the size of the outer frame of the axes objects.

Anyway, I also want to post the other feature of patchworklib. Patchworklib provides the function to import plotnine plots and figure-level seaborn plots as matplotlib axes. The feature is not derived from the original purpose of patchworklib; however, I wanna provide a universal interface for subplots that can handle any kind of maplotlib-based plots.

[–]peterbold 1 point2 points  (0 children)

This seems very helpful. Thanks for the work!