This page demonstrates Python tips and tricks that I use in my everyday programming as an atmospheric science graduate student.
-Brian Blaylock

Monday, April 23, 2018

Tips for Publication-worthy Matplotlib Figures

Matplotlib is the graphical plotting package for Python and is heavily used to create. Here are a few tips to create a publication-quality image in Python. There is nothing worse than seeing a poorly made, blurry, or crowded figure when you read a journal article.

The American Meteorological Society has a document that explains best practices to make your figures. These are good rules of thumb to follow.

  1. Create each figure in its own Jupyter Notebook. I recently learned why Jupyter Notebooks are so's a great way to document and cleanly see each step. You can easily share notebooks and upload them to GitHub. They also give you the power to make minor changes and do figure 'touch-ups'. These touch-ups are what will make your figures look amazing. 
  2. Pay attention to the dpi: dpi is the 'dots per inch'. A high dpi will make your images look crisp. Generally, anything less than 150 is ideal for viewing on a web, but for print, you want at least 300 dpi. If you figure is just black and white, use at least 1000 dpi. If it includes shades of grey or colors it is acceptable to bump the dpi down to 600. 
  3. Do not manually resize your picture after it has been created. For example, do not make a large picture, load it into PowerPoint, and then shrink the image. This will distort the image, change the dpi, make lines too thin, and cause all sorts of asthetic problems. It is best to make the image the size you want it to be from the beginning.
  4. Pay careful consideration to label, titles, and legends. You want these to be readable, so pay attention to their font size. In fact, most of the time you can get away with not using a figure title--that is the purpose of the figure caption.
  5. Do not use the `Jet` color map. Jet is just horrible. If you need some convincing, then watch this. You can also read a million other articles why Jet is horrible.
  6. Use colors that make sense. If you are showing two diverging values, like negative-ness and positive-ness of a value, use a diverging color map. If you are illustrating hot temperatures, use red.
  7. Consider the right marker shape.
In general, make your figures look good. It is worth spending extra time to make your figures look good. After all, the pretty pictures in your article are the most-looked-at part of your paper.