Bookmarks
- Python graph gallery
- Seaborn
- Matplotlib
- Examples - has a lot of examples
- Userguide
- Matplotlib Colors
To try out
- pygwalker
- Bokeh
- ggplot
Aesthetics
Colors
- Colormaps - matplotlib
- Color palettes - seaborn
- Cubehelix palette to generate custom colormap
- Colorbrewer colormaps - available through seaborn
As a list of colors:
As colormap:
Stylesheet
Seaborn styles guide. Example:
Axes
-
Despline:
-
I prefer removing the axes and spine. despine from seaborn generally works well, but in some cases spines still remain so I switch of visibility for those
-
more axes modifications
Matplotlib
Figure layout
-
use subfigures + subfigures to make publication level figures in one shot
-
subplot_mosaic for complicated axes - guide
-
changing gaps between subplots
Figure axes
-
axis labels
-
axis limits
Multiple x, y axis
-
guide - here
-
Make multiple y axis by:
-
Make multiple x axis by using
ax.twiny()
Plot
the workhorse - doc sheet
Scatter
Fill between
- Easy to make filled plots, highlight stimulus areas, etc
- demo
Images
Plotting images using matplotlib
Example code with an overlay:
Dual axis plot
For two y-axis:
Ordering artists
-
Note: This does not work with twin axes
-
Probably works with other types of axes, not sure
-
Works with different plots. Higher zorder implies it will be on top1
Labels
-
Changing location orientation of x and y labels
Colorbars
-
Adding an colorbar to an axes:
-
Modifying cbar labels:
Legends
- a very nice guide for customizing legends (doc sheet)
- use
_nolegend_
to skip plots from appearing in legend2 - you can hook it to subplots or subfigures or figures.
bbox_to_anchor
coupled withloc
is a good way of moving the legend to where you would like it in the plot.
example:
Text
Saving figures
- Typically, I save as a pdf as svg rarely works well for me with Affinity designer.
- Using
bbox_inches='tight'
allows legends and other modifications that go beyond 1 in a normalized fig size.3
Seaborn
Heatmap
Setting one color bar across multiple axes
FacetGrid
Facegrid (guide here) is very useful to do ridgeplots and other multi-plot grids.
The downside is that this does not work with subfigures so it is hard to have multicolumn figures with different types of plots.
I tried using facetgrid for ridge plots, but the subfigure limitation made it hard to use. I found it easier to actually plot it using matplotlib.