The classic python plotting is matplotlib. It can’t do all those modern hipster graphs without hard labour and is awful at animations and interactions, and it fugly per default. It works OK out of the box. There are libraries which use matplotlib as a backend and build more eleaborate systems on the top, but these have not had much longevity so far, so I find myself falling back to plain old matplotlib. It is an acceptable default with lots of weird edge cases when you try to be clever, but gets the job 80% done.
Note some confusing terminology;
Axes object, which is constructed by an
Axis objects, but is much more than a list of such objects, being
the fundamental object upon which a graph is drawn.
But don’t listen to me describe it. Observe this lovely diagram which explains all.
Read Jakevdp’s manual for some pedagogic advice.
Here are some miscellaneous tips:
- If I am using jupyter, the nerdy extension is jupyter-matplotlib which integrates interactive plotting into the notebook better.
- Improving log y-axis plots, esp histograms
- drawnow allows dynamically updated diagrams. It is occasionally maintained.
Grammar of graphics
The default matplotlib stylesheet aspires to look like 80s spreadsheet defaults, but if you are not a retrofuturist, you want to change the stylesheet. Some of the built-in stylesheets are OK.
Seaborn is another vaunted extension, which I would describe as an “Edward Tufterizer”. Extends matplotlib with modern apperance and some missing plot types.
A cute hack to justify matplotlib’s existence: xkcd graphs.
from matplotlib import rc rc( 'font', family='serif', serif=['Palatino'] ) rc( 'mathtext', fontset='cm' )
Supported math fonts are reputedly
- dejavusans (horrible default)
- dejavuserif (beware of odd greek letters)
- cm (”Computer Modern”. Classic, dated. )
- stix (not sure)
- stixsans (sounds like sans serif to me)
Alternatively you can render your graph labels with TeX which leads to some weird spacing but allows you to match fonts better. It is also fragile and character set issues are terrible. Is this better if I use XeLaTeX/LuaLaTeX?
Yellowbrick is a matplotlib specialisation for hyperparameter optimisation.
Yellowbrick extends the Scikit-Learn API to make model selection and hyperparameter tuning easier. Under the hood, it’s using Matplotlib.