Making color plots that are also clear in greyscale
54 views (last 30 days)
Show older comments
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)
2 Comments
Image Analyst
on 17 Aug 2023
I think you already asked this. And I answered it here: https://www.mathworks.com/matlabcentral/answers/2008917-setting-graph-colour-also-visible-in-greyscale#answer_1287962
Answers (2)
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
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)
0 Comments
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.
0 Comments
See Also
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!