AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Python scatter subplot legend7/31/2023 floating-box """ def add_plot( self, oAxes): # string buffer for the HTML: initially some CSS images to be appended self. ''' A class / object to display plots in a horizontal / flow layout below a cell ''' def _init_( self): Therefore, you can specify how many figures you want to plot per line, using the individual figsize argument. Store these figures in a list and pass them to the plot_nice() function which will plot all your figures side by side until it runs out of space, after which it will create a linebreak and continue. But if we specify show=False, it returns the axis and we can obtain the figure object using (). However, sc.pl.scatter isn't exposing the figure object but only the axis. even if we want to plot 2 plots side by side in a jupyter notebook (original post here: ). Good news is, that there is a way around using plt.subplots and using given Axes objects. ![]() The problem here is really that we don't have two separate figures / axes aren't handled correctly. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.Ĭurrent workaround (also for all other sort of plots) In a future version, a new instance will always be created and returned. MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. I cannot access them and I wonder where they are stored in this case. Shouldn't the legends be attached to the individual axes objects? Is there a way I can share the same legend with a scale from 0 to 1 (0%-100%) for both plots in this case?Īs you can see, the line removing the legend from sc_ax1 is commented out because get_legend() returns None in this case, which would lead to the error below:ĪttributeError Traceback (most recent call last)Ģ sc_fig, (sc_ax1, sc_ax2) = plt.subplots( 1, 2, figsize =( 12, 5))ģ sc.pl.scatter(adata_raw, 'total_counts ', 'n_genes_by_counts ', color = 'pct_counts_mt ', size = 10, ax =sc_ax1, show = False, title = "all counts ")ĥ sc.pl.scatter(adata_raw < 1000], 'total_counts ', 'n_genes_by_counts ', color = 'pct_counts_mt ', size = 10, ax =sc_ax2, show = False, title = "< 1000 counts ")ĪttributeError: 'NoneType' object has no attribute 'remove' ![]() ![]() Why doesn't it behave in the same way like in the example above? Plus, I cannot remove the legend from the first plot. Only one legend seems to be drawn and this one is not looking as expected. scatter( adata_raw < 1000], 'total_counts', 'n_genes_by_counts', color = 'pct_counts_mt', size = 10, ax = sc_ax2, show = False, title = "< 1000 counts")Įssentially the same thing but colored by the percentage of mitochondrial counts. scatter( adata_raw, 'total_counts', 'n_genes_by_counts', color = 'pct_counts_mt', size = 10, ax = sc_ax1, show = False, title = "all counts")
0 Comments
Read More
Leave a Reply. |