how to color individual lines in a plot
1,755 ビュー (過去 30 日間)
古いコメントを表示
Hello all,
I'm a novice user and I'm attempting to use something like "colormap jet" on a plot so that each line within the plot is a different color. The x-axis is temperature and the y-axis is depth. Each line is at a temperature, so I'd like the colors to make the graph easier to read (e.g. colder to hotter).
I haven't found a solution on here that works so far. I think it might have to do with how the data are plotted.
Here's the code:
dates = datevec(datetime); %set matlab dates to year,month,day,hour,min,sec
dates = dates'; %invert
temp_crop = calTemp(387:417,:); %only interested in temps along this length of cable
ind_midnight = find(dates(4,:)==0); %finding all temp measures along cable where hour is 0 (midnight)
ind_noon = find(dates(4,:)==12); %same as above, but with noon
midnighttemps = temp_crop(:,ind_midnight); %have all temps along cropped section of cable for each day at midnight
noontemps = temp_crop(:,ind_noon); %same as above, but with noon
close all
figure;
subplot(1,2,1);
plot(midnighttemps);
view([90 -90]);
title('midnight');
subplot(1,2,2);
plot(noontemps);
view([90 -90]);
title('noon');
You can see how the plot is actually plotting individual matrices with a single column. I think this might be why I can't do a simple colormap or colorbar. I've also tried a few for loops such as this:
x = [0:0.1:10];
linecolors = jet(5);
for i=1:5
plot(x,x.^(i/3),'color',linecolors(i,:));
hold on;
end
I found this on StackOverflow, and the graph it produces is what I'd like, individually colored lines on a gradient, but I can't seem to get it to work. Again, I think this is because I'm plotting an entire matrix. Any suggestions?
Thank you for any assistance.
0 件のコメント
採用された回答
Image Analyst
2019 年 1 月 4 日
You can change the default color order to do exactly what you want. In fact I already have a demo that does it. See attached m-file.
その他の回答 (1 件)
Arvind Sathyanarayanan
2019 年 1 月 4 日
編集済み: Arvind Sathyanarayanan
2019 年 1 月 4 日
Josh,
You can specify plot color by using the 'color' property and specifying a color or a normalized RGB code when using the plot command. Please see the example below.
%Using color names
plot(midnighttemps, 'color', 'red');
%Using RGB code
plot(noontemps, 'color', [1 1 0.8]);
4 件のコメント
Image Analyst
2019 年 1 月 5 日
Josh:
take a look at my answer above again. Look at the screenshot I posted. It seems to me it looks like the one below that your posted sample code makes, don't you think?
If you ran the code, you'll see it asks you to pick one of several colormaps and it does give you a gradient fo colors as you go from one line to the other. Did you actually run the code or not? Or you can tell just from looking at it that you don't want it, or the one above from StackOverflow? Do you instead want one where the color is not different for each line (each line has one color for the entire line), but maybe you want one where the color of each line actually changes as it goes from left to right (possible, but this is not what we though you wanted)?
参考
カテゴリ
Help Center および File Exchange で Colormaps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!