Category: Python for Data Science
How to draw a diverging image with a zero-centered normalization in Matplotlib (with Code)
Pass TwoSlopeNorm(vmin=..., vcenter=0, vmax=...) as the norm of imshow with a diverging colormap.
How to plot a histogram with unequal bin widths in Matplotlib (with Code)
Pass increasing bin edges to hist and use density=True when bar areas should represent proportions.
How to format dates on a time-series axis in Matplotlib (with Code)
Give the axis an AutoDateLocator and a ConciseDateFormatter that uses the same locator.
How to add a logarithmic axis in Matplotlib (with Code)
Call ax.set_yscale("log", base=10) to display positive y values on a base-10 logarithmic axis.
How to plot error bars from measured standard errors in Matplotlib (with Code)
Pass the standard error for each plotted mean to the yerr argument of ax.errorbar.
How to share a colorbar across subplots in Matplotlib (with Code)
Give every subplot the same Normalize object and colormap, then pass the subplot axes to fig.colorbar.
How to save a figure with a transparent background in Matplotlib (with Code)
Pass transparent=True to fig.savefig and choose a format such as PNG that supports an alpha channel.
How to annotate heatmap values in Seaborn (with Code)
Set annot=True to print values inside Seaborn heatmap cells, and use fmt to control their display precision.
How to create small-multiple scatterplots in Seaborn (with Code)
Use sns.relplot with kind="scatter" and col set to the grouping column to draw one scatterplot per group.
How to mask the upper triangle of a correlation heatmap in Seaborn (with Code)
Pass a Boolean upper-triangle mask to sns.heatmap; cells whose mask is True are hidden.