yyaxis plots ignoring plotting commands or even changes the command unprompted
3 ビュー (過去 30 日間)
古いコメントを表示
The following script plots 2 curves on the left axis and 1 curve on the right axis as shown below. Each curve has its own error curves with the middle region filled in. I would expect the bounding curves to be green, have thickness of 2, and be solid curves, but they are only 0.5 thickness, black, and most strangely, the lower bound of temperature is plotted as dash. Any ideas why this might happen?
x2 = [time; flipud(time)];
f = figure;
f.Position = [616 601 1006 645];
hold on;
ax = gca;
ax.FontSize = 16;
ax.YColor = 'k';
plot(time,alpha_phase_UB,'g-','LineWidth',2,'HandleVisibility','off');
plot(time,alpha_phase_LB,'g-','LineWidth',2,'HandleVisibility','off');
inBetween = [alpha_phase_UB;flipud(alpha_phase)];
inBetween2 = [alpha_phase_LB;flipud(alpha_phase)];
fill(x2,inBetween,'g','FaceAlpha',0.5,'HandleVisibility','off');
fill(x2,inBetween2,'g','FaceAlpha',0.5,'HandleVisibility','off');
plot(time,alpha_phase,'r-','LineWidth',3);
plot(time,beta_phase_UB,'g-','LineWidth',2,'HandleVisibility','off');
plot(time,beta_phase_LB,'g-','LineWidth',2,'HandleVisibility','off');
inBetween = [beta_phase_UB;flipud(beta_phase)];
inBetween2 = [beta_phase;flipud(beta_phase_LB)];
fill(x2,inBetween,'g','FaceAlpha',0.5,'HandleVisibility','off');
fill(x2,inBetween2,'g','FaceAlpha',0.5,'HandleVisibility','off');
plot(time,beta_phase,'b-','LineWidth',3);
xlabel('Time (s)','FontSize',18);
ylabel('Phase fraction','FontSize',18);
ylim([0 1]);
% figure;
% hold on;
yyaxis right;
ax = gca;
ax.FontSize = 16;
ax.YColor = 'k';
colororder('default');
plot(time,temperature_UB,'g-','LineWidth',2,'HandleVisibility','off');
plot(time,temperature_LB,'g-','LineWidth',2,'HandleVisibility','off');
inBetween = [temperature_UB;flipud(temperature)];
inBetween2 = [temperature;flipud(temperature_LB)];
fill(x2,inBetween,'g','FaceAlpha',0.5,'HandleVisibility','off');
fill(x2,inBetween2,'g','FaceAlpha',0.5,'HandleVisibility','off');
plot(time,temperature,'k-','LineWidth',3);
ylabel('Temperature (^oC)','FontSize',18);
ylim([0 1200]);
legend('Alpha','Beta','Temperature','Location','northeast','FontSize',16);
legend boxoff;
1 件のコメント
the cyclist
2023 年 7 月 24 日
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar.
採用された回答
Voss
2023 年 7 月 24 日
Because fill is called after the UB/LB bounding curves are plotted, the patches created by fill are on top of the bounding curves and the patches' edges obscure (or partially obscure) the bounding curves.
Since the patch edges coincide with the bounding curves, you can avoid plotting the bounding curves at all, and instead set the patch edge properties to get the desired effect.
Also, the calls to plot and fill that are in pairs can be combined into single calls.
I'm not sure why the lower bound of temperature got a dotted line.
% some made-up data:
time = (1:4000).';
alpha_phase = 0.5*sin(time/800)+0.5;
alpha_phase_UB = alpha_phase+0.1;
alpha_phase_LB = alpha_phase-0.1;
beta_phase = 0.5*cos(time/800)+0.5;
beta_phase_UB = beta_phase+0.1;
beta_phase_LB = beta_phase-0.1;
temperature = 1000*(cos(time/800).*sin(time/800));
temperature_UB = temperature+100;
temperature_LB = temperature-100;
% plotting:
x2 = [time; flipud(time)];
f = figure;
f.Position = [616 601 1006 645];
hold on;
ax = gca;
ax.FontSize = 16;
ax.YColor = 'k';
inBetween = [alpha_phase_UB;flipud(alpha_phase_LB)];
fill(x2,inBetween,'g','FaceAlpha',0.5,'HandleVisibility','off','EdgeColor',[0 0.6 0],'LineWidth',2);
plot(time,alpha_phase,'r-','LineWidth',3);
inBetween = [beta_phase_UB;flipud(beta_phase_LB)];
fill(x2,inBetween,'g','FaceAlpha',0.5,'HandleVisibility','off','EdgeColor',[0 0.6 0],'LineWidth',2);
plot(time,beta_phase,'b-','LineWidth',3);
xlabel('Time (s)','FontSize',18);
ylabel('Phase fraction','FontSize',18);
ylim([0 1]);
yyaxis right;
ax = gca;
ax.FontSize = 16;
ax.YColor = 'k';
colororder('default');
inBetween = [temperature_UB;flipud(temperature_LB)];
fill(x2,inBetween,'g','FaceAlpha',0.5,'HandleVisibility','off','EdgeColor',[0 0.6 0],'LineWidth',2);
plot(time,temperature,'k-','LineWidth',3);
ylabel('Temperature (^oC)','FontSize',18);
ylim([0 1200]);
legend('Alpha','Beta','Temperature','Location','northeast','FontSize',16);
legend boxoff;
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!