Making color plots that are also clear in greyscale

53 views (last 30 days)
Em
Em on 16 Aug 2023
Edited: DGM on 17 Aug 2023
Hi evryone,
I have a selection of a few plots that I would like to make visible also in grey scale. Please could someone explain if there is a way of specifying colour that would allow this? Thank you!
My current code specifies colour like this
plot(dimethylsulphoxide8a(end-1000:end,1)*10^-6, dimethylsulphoxide8a(end-1000:end,3)*10^9,'Color',c(75,:), 'LineWidth',1)

Answers (2)

Adam Danz
Adam Danz on 16 Aug 2023
Edited: Adam Danz on 16 Aug 2023
Converting a colormap to grayscale
If you have an existing colormap c that you would like to convert to grayscale, you could use MATLAB's rgb2gray
grayscaleColors = rgb2gray(c);
It uses the NTSC formula
grayscaleColors = 0.299*c(:,1) + 0.587*c(:,2) + 0.114*c(:,3) * ones(1,3)
Example:
tiledlayout(3,2)
ax = nexttile;
surf(peaks(10))
colormap(ax,parula(10))
ax = nexttile;
surf(peaks(10))
gc = rgb2gray(parula(10));
colormap(ax,gc)
ax = nexttile;
plot(magic(5),'LineWidth',2)
ax = nexttile;
ax.ColorOrder = rgb2gray(ax.ColorOrder);
hold on
plot(magic(5),'LineWidth',2)
ax = nexttile;
imagesc(magic(30))
colormap(ax,turbo(30))
ax = nexttile;
imagesc(magic(30))
colormap(ax,rgb2gray(turbo(30)))
Creating a gray colormap
To create a gray colormap equal in size to your existing c colormap, use MATLAB's gray
grayscaleColors = gray(size(c,1));
However, you may want to trim the white end of the colormap, assuming your axes background is white.
Example: Removing pure white
figure
tiledlayout(3,2)
ax = nexttile;
surf(peaks(10))
colormap(ax,parula(10))
ax = nexttile;
surf(peaks(10))
gc = gray(11);
gc(end,:) = [];
colormap(ax,gc)
ax = nexttile;
plot(magic(5),'LineWidth',2)
ax = nexttile;
gc = gray(size(ax.ColorOrder,1)+1);
gc(end,:) = [];
ax.ColorOrder = gc;
hold on
plot(magic(5),'LineWidth',2)
ax = nexttile;
imagesc(magic(30))
colormap(ax,turbo(30))
ax = nexttile;
imagesc(magic(30))
gc = gray(31);
gc(end,:) = [];
colormap(ax,gc)

DGM
DGM on 17 Aug 2023
Edited: DGM on 17 Aug 2023
I think the answer is as old as printed media. If you want something to appear distinct in monochrome, deal with the aspects of color and form that remain distinct when all the chroma information is lost. Use few colors with distinct brightness, and broaden the set of categories as necessary by using different linestyles, weights, or marker types.
% a very short color table with distinct luma (3 colors)
CT = parula(16);
CT = CT(4:4:end-4,:);
% some fake data (9 data series)
os = linspace(0,pi,9).';
x = linspace(0,2*pi,100);
y = sin(x + os);
% plot the data using only three colors
colororder(CT) % set the colors
hp = plot(x,y,'linewidth',1.5);
[hp(4:6).LineStyle] = deal('--'); % set the linestyles
[hp(7:9).LineStyle] = deal(':');
If you need to plot more than a couple handfuls of things in the same plot, clarity is usually going to be a casualty anyway.
Alternatively, if your concern is dealing with accessibility, see:
and the sources linked therein:
The solutions for the two goals have considerable overlap.

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!