How To Modify Color of Legend Markers?
14 次查看(过去 30 天)
显示 更早的评论
I'm currently attempting to create figures from .csv files, however the resulting figures all appear to have duplicates present in the legend. I'm unsure of how to correct this issue, and have used multiple 'legend' commands to no avail. Any and all advice would be very appreciated. The code I've been using can be found below:
data_raw1=csvread('thru-plane (results) - Test48_Left_Reslice.csv',2,3);
data_raw2=csvread('thru-plane (results) - Test51_Left_Reslice.csv',2,3);
data_raw3=csvread('thru-plane (results) - Test54_Left_Reslice.csv',2,3);
% Uncomment data_raw4 read .csv file
%data_raw4=csvread('thru-plane (results) - Test56_Left_Reslice.csv',2,3);
p1=plot(data_raw1,'c');
hold on
p2=plot(data_raw2,'b');
p3=plot(data_raw3,'r');
% Uncomment to to plot
%p4=plot(data_raw4,'k');
%xlim([0 500]);
ylim([0 50]);
xlabel('Through-Thickness [\mum]');
ylabel('Oxygen Content');
hold off
legend
0 个评论
回答(1 个)
Walter Roberson
2020-2-7
p1=plot(data_raw1,'c');
Your data_raw1 has multiple columns. plot() will produce one line for each column.
Solution:
legend([p1(1), p2(1), p3(3)], {'48_Left', '51_Left', '54_Left'})
Note: if you have enough lines in the plot then it would start using different line styles, so you might want to specify the line styles yourself, such as '-c'
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!