Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
alternating background plot color

Subject: alternating background plot color

From: Marc Sean

Date: 23 Mar, 2011 02:23:05

Message: 1 of 4

Hi.

Is there a way to have a background color to be alternating?
e.g.
along the x-axis, first 50 is green background, next 50 is blue background and this keeps alternating to the end of the x-axis.
I need to plot on such background so I could see the changing patterns.

Any help is much appreciated.

Thank you.
Marc

Subject: alternating background plot color

From: Sadik

Date: 23 Mar, 2011 02:29:04

Message: 2 of 4

Hi Marc,

How about using patch?

An example:

patch([1 2 2 1],[1 1 5 5],'g')
patch([3 4 4 3],[1 1 5 5],'g')
hold on
plot(1:4,'k')

Best.

Subject: alternating background plot color

From: Marc Sean

Date: 23 Mar, 2011 02:59:06

Message: 3 of 4

"Sadik " <sadik.hava@gmail.com> wrote in message <imbltg$i2c$1@fred.mathworks.com>...
> Hi Marc,
>
> How about using patch?
>
> An example:
>
> patch([1 2 2 1],[1 1 5 5],'g')
> patch([3 4 4 3],[1 1 5 5],'g')
> hold on
> plot(1:4,'k')
>
> Best.

It looks good. But patch seems to cover the grid lines?

Subject: alternating background plot color

From: Sadik

Date: 23 Mar, 2011 03:19:04

Message: 4 of 4

Then you could do:

h = patch( ...
 set(h,'FaceAlpha',0.5);

to make it a bit transparent. Now you should be able to see the grid lines.

Best.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us