Articles published in science and research journals usually include one or more figures in them. It is often convenient for the authors to produce colour versions of such images, particularly when there are many varieties of data for inclusion in a single image – points, lines or regions corresponding to different groups of data are plotted using different colours so that they may be readily distinguished by a reader. However, given the high costs of publishing, authors are often forced to opt for a “colour online only” version where plots would appear in colour in the electronic versions of an article (e.g., pdf files), but when printed on paper using a black-and-white printer, the colours in the plots are expected to map on to appropriate shades of gray such that the elements of the plots are still discernible in the resulting grayscale plot.
Unfortunately, publishing companies generally do not provide any guidelines on how to chose colours appropriately for such purposes. When one has to produce plots using Matlab, Matplotlib or R software, choosing appropriate values for the red, green & blue components to result in a desired colour usually takes several trial-and-error attempts. I had to produce “colour online only” plots for an article which is now published in the Journal of the Acoustical Society of America (JASA). Exhaustive googling at the time had not given me any direct solutions. But the effort did lead me to a formula for transforming constituent rgb values into equivalent single-valued grayscale numbers that match the gray levels in black-and-white printed versions of colour images. The formula to convert rgb colour components into a single grayscale value G
is
G = (0.299 × r) + (0.587 × g) + (0.114 × b)
.
There are a few alternatives to the set of coefficients in the formula (see this article), but this combination seemed to work well with a few printers that I experimented with. The grayscale values obtained using the formula correspond to those that a black-and-white printer would produce when it prints a colour image. I had then come up with a scheme that I could readily reuse in other work. I decided to document my findings so that other researchers facing a similar hurdle could use it as a quick reference.
Using Matlab’s hsv()
function, I produced an array of 15 colours. These are listed, along with pure black and white, in the table below.
No. |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
r |
0 |
255 |
255 |
255 |
204 |
102 |
0 |
0 |
0 |
0 |
0 |
0 |
102 |
204 |
255 |
255 |
255 |
g |
0 |
0 |
102 |
204 |
255 |
255 |
255 |
255 |
255 |
204 |
102 |
0 |
0 |
0 |
0 |
0 |
255 |
b |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
102 |
204 |
255 |
255 |
255 |
255 |
255 |
204 |
102 |
255 |
Result |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
The values listed are in the range 0 – 255, corresponding to the hexadecimal range 00 – FF. For use in Matlab, one must simply divide each number by 255 to convert it to the range 0 – 1. For example, to plot a line using the colour numbered 12, a Matlab code snippet might look like:
plot(x_data, y_data, ‘color’, [102, 0, 255] ./ 255);
Applying the above transformation formula to these colours yields the following result:
No. |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
Result |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
♦ |
If you were to print this page on a black-and-white printer, the last rows in the above two tables would (should, ideally) appear the same.
Now all that one needs to do for producing colour plots that can appear well in grayscale prints is to choose a subset of colours from the first table above such that the corresponding grayscale shades are also distinguishable. Note that there may be other schemes available for tackling the ordeal of choosing colours, but the lookup-table method proposed here is meant to offer a quick reference guide for researchers that cannot be bothered with the hassles of acquiring DTP skills. For further convenience, I have included here an image which lists the above set of colours sorted according to grayscale levels. It’s a full-page sized image so you can print it out and hang it on your pinup board for easy access. Remember to print it in colour Hope you’ll find it useful.