How do I change the default line style of plots generated using yyaxis?

조회 수: 8 (최근 30일)
I am plotting two sets of data with each set containing a 6 by 100 matrix. I would like the final plot to have 6 solid lines colored using the default color order. And 6 dashed lines colored using the default color order. However, when I use the command yyaxis left and yyaxis right, the default color and linestyles are changed. I've figured out how to override the colors by manually changing them using the plot command. I've tried to override the line style for the yyaxis right plot using 'LineStyle','--' in the plot command. Lines 1 through 4 come out the way I want, but lines 5 and 6 are dashed with the default line marker circle and triangle. How do I get rid of these default markers? Thank you in advance.
MATLAB version: R2017a OS: Windows 10 x64
figure(4) hold on
% colorVec = {'k', 'b', 'r', 'm', 'g', 'c'}; % linVec = {'--', '--','--', '--','--', '--'}; ,'Color', colorVec{i},'LineStyle',linVec{i} % delete( findobj(gca, 'type', 'marker') ); % yyaxis left %plot on left Y axis ax = gca;
co = [0 0.4470 0.7410; 0.8500 0.3250 0.0980; 0.9290 0.6940 0.1250; 0.4940 0.1840 0.5560; 0.4660 0.6740 0.1880; 0.3010 0.7450 0.9330; 0.6350 0.0780 0.1840]; set(groot,'DefaultAxesColorOrder',co)
for i = 1:nmat ax.ColorOrderIndex % plot(tvar,Ts1(i,:),'Color', co(i,:),'LineWidth',2) plot(tvar,Ts1(i,:),'Color', ax.ColorOrder(ax.ColorOrderIndex,:),'LineWidth',2) % hold on %hold commnd retains the current color order % plot(tvar,Ts2(:,:),'--','LineWidth',2,'MarkerSize',5) end
xlim([0 60]) grid on y_label = ylabel('Surface Temp [C]'); ax = gca; % current axes % ax.YAxis(1).TickLabelFormat = '%.2f'; ax.YAxis(1).Color = 'k'; %axis color
% figure(4) % ax.ColorOrderIndex = 1; %restarts the color order index before each plotting command
yyaxis right %plot on right Y axis for i = 1:nmat plot(tvar,driftT2(i,:),'Color', co(i,:),'LineStyle','--','LineWidth',2) end
y_label = ylabel('Thermal Drift [mrad]'); ax.YAxis(2).Color = 'b'; %axis color % ax.YAxis(2).TickLabelFormat = '%,d'; % ax.YAxis(2).Exponent = 0; hold off

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 4월 23일
You can do this using GUI inside of MATLAB commands. In the figure window go to, View > Property Editor. Then click on the line to want to modify. Although it is possible to do it through the code but if you only want to edit one figure, then this is a good option for you. Still, if you want to see the MATLAB code, you can go to File > Generate Code... and MATLAB will automatically generate the required code to create the figure with proper formatting.
  댓글 수: 5
Eugene Cho
Eugene Cho 2018년 4월 23일

Ameer trying what you had suggested I saw in the Plot Property Editor a Marker style 'none'. So I explicitly added this marker style to the plot command the phantom markers disappeared.

    plot(tvar,Ts1(i,:),'Color', co(i,:),'LineStyle','-','Marker','none',...
        'LineWidth',2,'Parent',axes1)
Ameer Hamza
Ameer Hamza 2018년 4월 24일

By default this property is none. Good, if this explicit assignment wirked for you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by