0
votes

I have a cell fit1, which is of dimension 50x1.

Every entry of the cell is a matrix 52x50.

When I plot it:

for ii=1:k
    hold On
    plot(fit1{ii},'b')
    xlim([-1100,5000])
    ylim([-5,20])
    legend('hide')
end

I get:

pic1

Now I want to do 2 things:

  1. First of all I want to mark certain areas of the plot: for example in the between x=-1000 and x=0 the background color should be yellow, between x=0 and x=100 it should be red etc.

  2. I want to draw some vertical lines - for example at x=189.

  3. Is there a possibility to mark the x-axis in certain colors instead of the background?

when I use the suggestion I get:

pic2

1
Please limit each post to a single question. Each of your three questions has been answered here before, please use Google to search for answers before asking. - Cris Luengo
@MichaelTr7 please see the edit - Voeslauer123

1 Answers

0
votes

Using the patch() function might suffice to change the appearance of the background. The patch() function takes two arrays describing the coordinate pairs of the polygon to be drawn/filled. To draw the vertical lines the line() function can be used. The line() function also takes two arrays representing the coordinate pairs that describe were the line begins and ends. Here is a question/answer going over your third point: How can I assign multiple colors to tick labels in plots in MATLAB?.

Plot Background Color Change

clf;
xlim([-1100,5000]);
ylim([-5,20]);
hold on

%Yellow background%
X_Minimum = -1100; X_Maximum = 0;
patch([X_Minimum X_Maximum X_Maximum X_Minimum], [min(ylim) min(ylim) max(ylim) max(ylim)],'y','EdgeColor','none')

%Red background%
X_Minimum = 0; X_Maximum = 100;
patch([X_Minimum X_Maximum X_Maximum X_Minimum], [min(ylim) min(ylim) max(ylim) max(ylim)],'r','EdgeColor','none')

%Vertical line%
X_Value = 189;
line([X_Value X_Value],[min(ylim) max(ylim)],'color','k');