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:
polar contourf plot: how to avoid the edge effects?

Subject: polar contourf plot: how to avoid the edge effects?

From: Kristoffer

Date: 20 Jul, 2012 05:24:11

Message: 1 of 8

Folks,

I did a search on this message board, but did not find this problem represented. Google also didn't help. I started with the Mathworks website on how to create a polar plot using:

    dir=90-dir; % angle vector in deg
    [DIR,FREQ]=meshgrid(dir.*pi/180,freq); % dir,freq converstion to matrices
    [X,Y]=pol2cart(DIR,FREQ); % generate cartesian matrices
    h = polar([0 2*pi], [0 0.4]);
    hold on
    delete(h)
    %contourf(X,Y,log10(sqrt(spec*df))); % THIS CREATES EDGE EFFECTS WHERE ANGLE WRAPS AROUND
    contour(X,Y,log10(spec2),20); % NO EDGE EFFECTS

So my problem is that I would like to have a polar, filled contour plot without the edge effect. Can someone point me in the right direction?

Thank you,
Kris Walker

Subject: polar contourf plot: how to avoid the edge effects?

From: Bruno Luong

Date: 20 Jul, 2012 05:45:34

Message: 2 of 8

"Kristoffer " <kwalker@ucsd.edu> wrote in message <juaq1r$nm7$1@newscl01ah.mathworks.com>...

>
> So my problem is that I would like to have a polar, filled contour plot without the edge effect. Can someone point me in the right direction?
>

Your code can't run, we don't have the data. So it's anyone's guess to understand "edge effects".

Bruno

Subject: polar contourf plot: how to avoid the edge effects?

From: Kristoffer

Date: 20 Jul, 2012 06:12:09

Message: 3 of 8

I don't see a data upload option on this newsgroup interface, so I posted these two files:

http://sail.ucsd.edu/~walker/contourf/stuff.mat
http://sail.ucsd.edu/~walker/contourf/test.m

Running test shows the edge effect that I'm referring to. It is occurring where the angle vector wraps from 2pi back to 0.

Thanks for your help,
Kris


"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <juar9u$rj6$1@newscl01ah.mathworks.com>...
> "Kristoffer " <kwalker@ucsd.edu> wrote in message <juaq1r$nm7$1@newscl01ah.mathworks.com>...
>
> >
> > So my problem is that I would like to have a polar, filled contour plot without the edge effect. Can someone point me in the right direction?
> >
>
> Your code can't run, we don't have the data. So it's anyone's guess to understand "edge effects".
>
> Bruno

Subject: polar contourf plot: how to avoid the edge effects?

From: Bruno Luong

Date: 20 Jul, 2012 06:31:11

Message: 4 of 8

"Kristoffer " <kwalker@ucsd.edu> wrote in message <juasrp$3kk$1@newscl01ah.mathworks.com>...

>
> Running test shows the edge effect that I'm referring to. It is occurring where the angle vector wraps from 2pi back to 0.

Run fine to me (v. 2012B). May be you run on a buggy older MATLAB version.

Bruno

Subject: polar contourf plot: how to avoid the edge effects?

From: Kristoffer

Date: 20 Jul, 2012 07:13:13

Message: 5 of 8

I expect you aren't interpreting my "edge effect" correctly. Here is a pic showing the problem. There is a vertical line from the origin to "90 deg" label in the contourf plot. Ignore the angle labels, as they are meaningless. That "90 deg" label corresponds to the 0/2pi wrap boundary. I just shifted it to do north for plotting purposes.

http://sail.ucsd.edu/~walker/contourf/out.jpg

I was using version 2010b. I just tried it on 2011b. Same problem. I also just installed version 2012a--same problem. Is the problem really not there in 2012b?

Kris

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <juatvf$7c8$1@newscl01ah.mathworks.com>...
> "Kristoffer " <kwalker@ucsd.edu> wrote in message <juasrp$3kk$1@newscl01ah.mathworks.com>...
>
> >
> > Running test shows the edge effect that I'm referring to. It is occurring where the angle vector wraps from 2pi back to 0.
>
> Run fine to me (v. 2012B). May be you run on a buggy older MATLAB version.
>
> Bruno

Subject: polar contourf plot: how to avoid the edge effects?

From: TideMan

Date: 20 Jul, 2012 09:00:37

Message: 6 of 8

On Friday, July 20, 2012 7:13:13 PM UTC+12, Kristoffer wrote:
> I expect you aren't interpreting my "edge effect" correctly. Here is a pic showing the problem. There is a vertical line from the origin to "90 deg" label in the contourf plot. Ignore the angle labels, as they are meaningless. That "90 deg" label corresponds to the 0/2pi wrap boundary. I just shifted it to do north for plotting purposes.
>
> http://sail.ucsd.edu/~walker/contourf/out.jpg
>
> I was using version 2010b. I just tried it on 2011b. Same problem. I also just installed version 2012a--same problem. Is the problem really not there in 2012b?
>
> Kris
>
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <juatvf$7c8$1@newscl01ah.mathworks.com>...
> > "Kristoffer " <kwalker@ucsd.edu> wrote in message <juasrp$3kk$1@newscl01ah.mathworks.com>...
> >
> > >
> > > Running test shows the edge effect that I'm referring to. It is occurring where the angle vector wraps from 2pi back to 0.
> >
> > Run fine to me (v. 2012B). May be you run on a buggy older MATLAB version.
> >
> > Bruno

You have come upon a problem that has stumped many of us for a decade or more. It happens all the time in cotidal charts, where the tide amplitude is plotted using contourf and the phase lines are over-plotted using contour. The problem is that there is a vertical cliff of phase lines between 2pi and zero.

So far, in more than a decade using Matlab for this, I have not found a solution to the problem anywhere.

Subject: polar contourf plot: how to avoid the edge effects?

From: Bjorn Gustavsson

Date: 20 Jul, 2012 10:14:18

Message: 7 of 8

TideMan <mulgor@gmail.com> wrote in message <4bd368b3-cf32-4fd6-a762-c4161ca68199@googlegroups.com>...
> On Friday, July 20, 2012 7:13:13 PM UTC+12, Kristoffer wrote:
> > I expect you aren't interpreting my "edge effect" correctly. Here is a pic showing the problem. There is a vertical line from the origin to "90 deg" label in the contourf plot. Ignore the angle labels, as they are meaningless. That "90 deg" label corresponds to the 0/2pi wrap boundary. I just shifted it to do north for plotting purposes.
> >
> > http://sail.ucsd.edu/~walker/contourf/out.jpg
> >
> > I was using version 2010b. I just tried it on 2011b. Same problem. I also just installed version 2012a--same problem. Is the problem really not there in 2012b?
> >
> > Kris
> >
> > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <juatvf$7c8$1@newscl01ah.mathworks.com>...
> > > "Kristoffer " <kwalker@ucsd.edu> wrote in message <juasrp$3kk$1@newscl01ah.mathworks.com>...
> > >
> > > >
> > > > Running test shows the edge effect that I'm referring to. It is occurring where the angle vector wraps from 2pi back to 0.
> > >
> > > Run fine to me (v. 2012B). May be you run on a buggy older MATLAB version.
> > >
> > > Bruno
>
> You have come upon a problem that has stumped many of us for a decade or more. It happens all the time in cotidal charts, where the tide amplitude is plotted using contourf and the phase lines are over-plotted using contour. The problem is that there is a vertical cliff of phase lines between 2pi and zero.
>
> So far, in more than a decade using Matlab for this, I have not found a solution to the problem anywhere.

Maybe not the most elegant of solutions:

shading flat takes away the edges of the patches - then if you guys want it back you might do it with contour(....,'k').

Seems to work for this case for me.

HTH,
Bjeorn

Subject: polar contourf plot: how to avoid the edge effects?

From: Kristoffer

Date: 20 Jul, 2012 19:10:27

Message: 8 of 8

"Bjorn Gustavsson" <bjonr@irf.se> wrote in message <jubb1q$k2g$1@newscl01ah.mathworks.com>...
> TideMan <mulgor@gmail.com> wrote in message <4bd368b3-cf32-4fd6-a762-c4161ca68199@googlegroups.com>...
> > On Friday, July 20, 2012 7:13:13 PM UTC+12, Kristoffer wrote:
> > > I expect you aren't interpreting my "edge effect" correctly. Here is a pic showing the problem. There is a vertical line from the origin to "90 deg" label in the contourf plot. Ignore the angle labels, as they are meaningless. That "90 deg" label corresponds to the 0/2pi wrap boundary. I just shifted it to do north for plotting purposes.
> > >
> > > http://sail.ucsd.edu/~walker/contourf/out.jpg
> > >
> > > I was using version 2010b. I just tried it on 2011b. Same problem. I also just installed version 2012a--same problem. Is the problem really not there in 2012b?
> > >
> > > Kris
> > >
> > > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <juatvf$7c8$1@newscl01ah.mathworks.com>...
> > > > "Kristoffer " <kwalker@ucsd.edu> wrote in message <juasrp$3kk$1@newscl01ah.mathworks.com>...
> > > >
> > > > >
> > > > > Running test shows the edge effect that I'm referring to. It is occurring where the angle vector wraps from 2pi back to 0.
> > > >
> > > > Run fine to me (v. 2012B). May be you run on a buggy older MATLAB version.
> > > >
> > > > Bruno
> >
> > You have come upon a problem that has stumped many of us for a decade or more. It happens all the time in cotidal charts, where the tide amplitude is plotted using contourf and the phase lines are over-plotted using contour. The problem is that there is a vertical cliff of phase lines between 2pi and zero.
> >
> > So far, in more than a decade using Matlab for this, I have not found a solution to the problem anywhere.
>
> Maybe not the most elegant of solutions:
>
> shading flat takes away the edges of the patches - then if you guys want it back you might do it with contour(....,'k').
>
> Seems to work for this case for me.
>
> HTH,
> Bjeorn

Thanks to all for your help.

Bjeorn, this has to be the best approach so far. I was using surf and contour together since last night, but your approach produces a nicer result.

Kris

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