How to plot multiple lines with gray color

929 ビュー (過去 30 日間)
TESFALEM ALDADA
TESFALEM ALDADA 2021 年 8 月 11 日
コメント済み: Image Analyst 2021 年 8 月 12 日
Hello,
I wanted display a plot of all multiple lines into gray colors. In addition i wanted to display title of a plot (ABC) inside the box.
For the sample code shown below, and figure attached.
Best
p=rand(12,5);
figure (2)
plot(p)
title('ABC')

採用された回答

Scott MacKenzie
Scott MacKenzie 2021 年 8 月 11 日
編集済み: Scott MacKenzie 2021 年 8 月 11 日
Here's one way to do this:
p=rand(12,5);
figure (2)
plot(p, 'color', [.5 .5 .5], 'linewidth', 1.5); % gray lines
% put text label inside axes
ax = gca;
x = mean(ax.XLim); % middle
y = ax.YLim(1) + diff(ax.YLim) * 0.93; % near top
text(x,y,'ABC', 'horizontalalignment', 'center', 'fontsize', 12, 'fontweight', 'bold');
  5 件のコメント
Scott MacKenzie
Scott MacKenzie 2021 年 8 月 11 日
I made them the same color only because I thought that's what the poster wanted. Sometimes knowing the source of the individual lines isn't that important. For example, if you are showing the performance patterns for participants in a user study, you might not care which line corresponds to which participant -- only the overall patterns of performance are important.
Image Analyst
Image Analyst 2021 年 8 月 12 日
OK. Makes sense. I once did something where a person plotted hundreds of curves and wanted to make a "heat map" of the curves, like where it was red in the dense part where lots of them overlapped, and went down to blue where the curves thinned out and became less overlapping. In that case he didn't care what color the curves were, he just wanted to convert the curves into a heat map showing the curve density as a function of location on the graph.

サインインしてコメントする。

その他の回答 (2 件)

Esen Ozbay
Esen Ozbay 2021 年 8 月 11 日
編集済み: Esen Ozbay 2021 年 8 月 11 日
Replace plot(p) with:
plot(XAxis, p, 'Color', [0.5 0.5 0.5])
You can write any number between 0 and 1 instead of 0.5, as long as all three numbers are the same, the line will be gray. Smaller numbers will give you a darger grey, larger numbers will give you a lighter grey, [1 1 1] will give you white.
If you don't have data for XAxis, you can write
plot(1:length(p), p, 'Color', [0.5 0.5 0.5])
If you want a range of different tones of gray, you can use:
plot(p)
set(gca, 'ColorOrder', colormap(gray(6)))
Here, I chose 6 because you have 5 lines. Set the number to be 1 more than the number of lines you want to plot (or else the last line will be white and you will not be able to see it).
To add text inside the plot, you can use the Tool Bar:
Insert>TextBox

Image Analyst
Image Analyst 2021 年 8 月 11 日
Try this:
p=rand(12,5);
numPlots = height(p)
% Make a color map of grays going from pure black to 75% of white (so we can still see it)
ramp = linspace(0, 0.75, numPlots);
listOfGrayColors = [ramp; ramp; ramp]';
% Plot each plot in a different gray color.
for k = 1 : numPlots
plot(p(k, :), '-', 'Color', listOfGrayColors(k, :), 'LineWidth', 6)
hold on;
end
grid on;
caption = sprintf('%d curves in gray', numPlots);
title(caption, 'FontSize', 18);
ylabel('Y', 'FontSize', 18);
xlabel('X', 'FontSize', 18);
% Put text inside box.
yl = ylim;
xl = xlim;
% Get coordinates for the text
yt = yl(2) * 0.99;
xt = mean(xl);
caption = 'ABC';
text(xt, yt, caption, 'Color', 'r', ...
'FontSize', 24, 'FontWeight', 'bold', ...
'HorizontalAlignment', 'center',...
'VerticalAlignment', 'Top');

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by