How do I change the default line style of plots generated using yyaxis?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Eugene Cho
am 23 Apr. 2018
Kommentiert: Ameer Hamza
am 24 Apr. 2018
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
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 23 Apr. 2018
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 Kommentare
Ameer Hamza
am 24 Apr. 2018
By default this property is none. Good, if this explicit assignment wirked for you.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!