Transparent background for identification of 0 and 1 in a MATLAB figure [duplicate]

こ雲淡風輕ζ 提交于 2019-12-25 00:15:21

问题


I've sunlight and eclipse detection in my code. I'd like to highlight sunlight and eclipse detection in every plot I'm generating.

Suppose

sun_avail = 0; % means spacecraft is in eclipse
sun_avail = 1; % means spacecraft is in sunlit

I've set of variables (vectors (X,Y,Z)) needed to be plot in matlab figure which I'd do like this

fig = figure();
set(fig, 'name', 'Quaternions', 'NumberTitle', 'off');
subplot(4,1,1);
plot(t,Qp(:,1),'b','linewidth',2);
title('Quaternions wrt ref frame selected','fontweight','b')
hold on;plot(t,q_dp(:,1),'-.m','linewidth',2);
grid;zoom;
legend('Gyro Q Attitude (Actual Gyro)','Body Q Attitude (Ideal Gyro)');
xlabel('time in secs','fontweight','b')
ylabel('q1','fontweight','b')

subplot(4,1,2);
plot(t,Qp(:,2),'b','linewidth',2);
hold on;plot(t,q_dp(:,2),'-.m','linewidth',2);
grid;zoom;
xlabel('time in secs','fontweight','b'); 
ylabel('q2','fontweight','b')

subplot(4,1,3);
plot(t,Qp(:,3),'b','linewidth',2);
hold on;plot(t,q_dp(:,3),'-.m','linewidth',2);
grid;zoom;
xlabel('time in secs','fontweight','b');
ylabel('q3','fontweight','b')

subplot(4,1,4);
plot(t,Qp(:,4),'b','linewidth',2);
hold on;plot(t,q_dp(:,4),'-.m','linewidth',2);
grid;zoom;
xlabel('time in secs','fontweight','b');
ylabel('q4','fontweight','b')

Figure looks like this

Is there any way to highlight like some transparent color in the background to identify the sunlit and eclipse portions in the above matlab figure.


回答1:


You can use patch for this purpose. Adjust the loop according to your data.

plot(randperm(100));   hold on;    plot(randperm(100));  %plotting some random data      
%if sunlight remains for 20 units and 40 is the interval from which it repeats and
%100-20=80 is the last occurence then
for k=0:40:80  
    patch([k 20+k 20+k k], [0 0 100 100],'y','EdgeColor','none','FaceAlpha',0.3);
end  



来源:https://stackoverflow.com/questions/46527808/transparent-background-for-identification-of-0-and-1-in-a-matlab-figure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!