matplotlib is a plotting library for the Python programming language and its numerical mathematics extension numpy. matplotlib.pyplot provides a MATLAB-like plotting framework. pylab combines pyplot with numpy into a single namespace. pylab is now discouraged. [1, 2, 3]
1 | |
1 | |
1 | |
How to use plt.subplots()?
1 | |
1 | |
In matplotlib and PIL, figure’s size is given as (width, height) in inches. Width comes first.
However, height comes first in numpy (thus OpenCV), Tensorflow, PyTorch (the image convention is (N, C, H, W) ) and conventional matrix notation in mathematics.
Figure size (figsize) determines the size of the figure in inches. This gives the amount of space the axes (and other elements) have inside the figure. The default figure size is (6.4, 4.8) inches in matplotlib 2.
Dots per inches (dpi) determines how many pixels the figure comprises. The default dpi in matplotlib is 100.
For example, a figure of figsize = (w, h) will have
1 | |
In matplotlib, image size (in pixels) cannot be too large, it must be less than $2^{16}=65536$ pixels in each direction.
seaborn
For seaborn version 0.10.1,
1 | |
One can use the style context manager which sets a style temporarily:
1 | |
Valid style names include: "seaborn-darkgrid", "seaborn-whitegrid", "seaborn-dark", "seaborn-white", "seaborn-ticks", "seaborn-bright", "seaborn-colorblind", "seaborn-dark-palette", "seaborn-paper", "seaborn-poster", "seaborn-talk", "bmh", "classic", "dark_background", "fivethirtyeight", "ggplot", "grayscale", etc.
Set font size for seaborn. The value of font_scale should be proportional to the figure size.
1 | |
Plot pairplot
1 | |
Save figure
1 | |
For seaborn:
1 | |
References
[1] Matplotlib. (2005, October 14). Wikipedia, the free encyclopedia. Retrieved April 3, 2020, from https://en.wikipedia.org/wiki/Matplotlib
[2] Pyplot — Matplotlib 2.0.2 documentation. (n.d.). Matplotlib: Python plotting — Matplotlib 3.2.1 documentation. https://matplotlib.org/api/pyplot_api.html
[3] Matplotlib, Pyplot, Pylab etc: What’s the difference between these and when to use each? (2019, August 31). queirozf.com. https://queirozf.com/entries/matplotlib-pylab-pyplot-etc-what-s-the-different-between-thes`