I typically write 100–200 lines of code each time I develop a scientific figure that is destined for publication. This is a dangerous length because it’s easy to create a functioning mess. With shorter code fragments, it’s feasible to start over from scratch, and with thousands of lines of code, it makes sense to invest time upfront to organise and plan. But in between these extremes lurks the appeal to write a script that feels coherent at the time, but just creates problems for future you.
Let’s say you want to create a moderately complicated figure like this:
A script for this figure could be envisaged as a series of sequential steps:
Read data in from a csv file
Remove any flagged data
Create four subplots
Plot the first line of data against time
Label the y axis
Set the y axis limit
Repeat steps 4–6 for the second and third lines of data
Keeping track of scripts used to generate figures is difficult. Before realising that Jupyter Notebooks could solve most of my problems, I would have directories with dozens of scripts with filenames of varying levels of ambiguity. Names that probably meant something to me at the time, but are hardly descriptive months or years later. Names like ISW_plume_plots.m, new_ISW_model_plots.m, and plot_model_behaviour.m. A certain PhD comic springs to mind.
Regardless of whether its Python, R, Julia, Matlab, or pretty much any other type of code, Jupyter Notebooks solve the problem. For example, I use a single notebook to archive the code for all figures in a paper and, more importantly, I can associate each set of code with the figure it generates. Rather than trying to remember what file I want, I need only remember which figure I want. (I say archive because I much prefer to do the bulk of my exploratory analysis in an editor. Alternatively, JupyterLab may work better for you.)
The command line is a large part of any Matlab user’s workflow. This vital tool, however, isn’t as user friendly as it should be: it’s cumbersome to recall multi-line commands from the history, there’s no support for Vim key bindings, and there’s no syntax highlighting if using the nodesktop option (on a remote computer, say). Fortunately, there’s an alternative that avoids these problems: IMatlab. This kernel also lets you run Matlab code in Jupyter Notebooks (originally known as IPython Notebooks).
Scientists should invest time in a good text editor: pay the upfront cost of learning to use and customising a single editor for all of your text needs. This may be obvious to programmers, but less so to scientists who may have yet to recognise the benefits of a good editor.
Much scientific analysis and documentation can be achieved with plain text files (e.g., .py, .m, .f, .r, .tex, or .md). The default method to work with multiple file types is to use multiple IDEs (Integrated Development Environments): Matlab for m-files, Spyder or IPython notebooks for python scripts, TexStudio or TeXnicCenter for latex files, RStudio for R, or one of the countless editors for Markdown currently available.
Using a single editor has many benefits over using a range of editors within each IDE:
Image file manipulation is typically associated with programs like Inkscape, Photoshop, or even MS Paint. A graphical user interface, however, isn’t a pre-requisite for manipulating images. Often it is overkill. Simple tasks such as resizing or converting file type can be achieved with little more than a right click (and the power of ImageMagick).
ImageMagick is a command-line, Swiss-army-knife of image manipulation. It can achieve all the usual manipulations: sharpen, rotate, resize, convert to grayscale, convert to a sketch. The list goes on… Instead of harnessing all its creative power, here I show how ImageMagick commands can be added to the right-click menu (in either Windows or Linux) to achieve simple changes without ever opening the file. Continue reading “Image conversion with a right-click”
Web pages are typically filled with numerous links, menus, and widgets that are intended to make it easy to find what you want. However, these become distracting when actually reading content online. Further, many websites appear to ignore guidelines for readability. Fortunately, there are ways to improve your own experience when reading.
LyX is a document processor that provides the power and professional-looking typesetting of LaTeX with the familiarity of an easy-to-use graphical interface à la MS Word. Effectively, it provides the best of both worlds. For someone without knowledge of LaTeX, LyX is less imposing and has a smaller learning curve. But even seasoned LaTeX users who have no desire to leave their favourite text editor can take advantage of some of LyX’s features.
If I could offer only one piece of advice to any scientist on how to improve the figures and presentations they produce, it would be ‘Learn how to use Inkscape’. If you ended up here by searching for “Inkscape scientists” or some variant of that, then what follows is just confirmation that you’re looking for the right thing.
Inkscape is a cross-platform, open-source vector graphics editor. Let’s break down all those adjectives to see how they help: