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:
How to set the aspect ratio of quiver plot

Subject: How to set the aspect ratio of quiver plot

From: Hermano Cappa

Date: 6 Dec, 2011 22:57:08

Message: 1 of 3

Hi,

How can you change the aspect ratio of a quiver plot? For a simple figure made with the plot function, you can easily do this with:

set(gca,'DataAspectRatio',[dr/dx 1 1]);

However, it seems that this is not the case for a quiver plot.

Subject: How to set the aspect ratio of quiver plot

From: Greg

Date: 13 Jan, 2012 16:47:07

Message: 2 of 3

you can use the annotation function. It puts an arrow on the plot but instead of using data values for the position it uses fractions of the plot window, you will have to extract the limits of the plot space in the figure window using get(gca,'xlim') and 'ylim' and get(gca,'Position') for the size and start of the plot space within the window.
its a bit of a faff but i ended up with something like this for placing on a contour plot;

 lims = [get(gca,'xlim') get(gca,'ylim')];
    framelim = get(gca,'Position');
    lfac = [lims(2)-lims(1) lims(4)-lims(3)];
    for pos =1:10:maxp
        for z = 1:z_tot
            spos = [points2d(1,pos,z)/lfac(1) points2d(3,pos,z)/lfac(2)].*framelim(3:4)+framelim(1:2);
            epos = spos(1:2)+0.02*([vel2d(1,pos,z,1) vel2d(3,pos,z,1)].*framelim(3:4));
            if epos(1)<0;epos(1)=0;end;if(epos(2))<0;epos(2)=0;end;
            if epos(1)>1;epos(1)=1;end;if(epos(2))>1;epos(2)=1;end;
            if epos==spos; epos=spos+[0.02 0];end %no velocity make it parallel looking
            annotation(figure(51),'arrow',[spos(1) epos(1)],[spos(2) epos(2)])
        end
    end

goodluck

Greg

"Hermano Cappa" wrote in message <jbm6k4$5nb$1@newscl01ah.mathworks.com>...
> Hi,
>
> How can you change the aspect ratio of a quiver plot? For a simple figure made with the plot function, you can easily do this with:
>
> set(gca,'DataAspectRatio',[dr/dx 1 1]);
>
> However, it seems that this is not the case for a quiver plot.

Subject: How to set the aspect ratio of quiver plot

From: bill

Date: 19 Jan, 2012 17:54:10

Message: 3 of 3

Greg, could you provide more of your code below. I have been trying to figure out how to add the quivers to a contour but can't follow everything you are doing.
thanks, bill


"Greg" wrote in message <jepn6b$d9b$1@newscl01ah.mathworks.com>...
> you can use the annotation function. It puts an arrow on the plot but instead of using data values for the position it uses fractions of the plot window, you will have to extract the limits of the plot space in the figure window using get(gca,'xlim') and 'ylim' and get(gca,'Position') for the size and start of the plot space within the window.
> its a bit of a faff but i ended up with something like this for placing on a contour plot;
>
> lims = [get(gca,'xlim') get(gca,'ylim')];
> framelim = get(gca,'Position');
> lfac = [lims(2)-lims(1) lims(4)-lims(3)];
> for pos =1:10:maxp
> for z = 1:z_tot
> spos = [points2d(1,pos,z)/lfac(1) points2d(3,pos,z)/lfac(2)].*framelim(3:4)+framelim(1:2);
> epos = spos(1:2)+0.02*([vel2d(1,pos,z,1) vel2d(3,pos,z,1)].*framelim(3:4));
> if epos(1)<0;epos(1)=0;end;if(epos(2))<0;epos(2)=0;end;
> if epos(1)>1;epos(1)=1;end;if(epos(2))>1;epos(2)=1;end;
> if epos==spos; epos=spos+[0.02 0];end %no velocity make it parallel looking
> annotation(figure(51),'arrow',[spos(1) epos(1)],[spos(2) epos(2)])
> end
> end
>
> goodluck
>
> Greg
>
> "Hermano Cappa" wrote in message <jbm6k4$5nb$1@newscl01ah.mathworks.com>...
> > Hi,
> >
> > How can you change the aspect ratio of a quiver plot? For a simple figure made with the plot function, you can easily do this with:
> >
> > set(gca,'DataAspectRatio',[dr/dx 1 1]);
> >
> > However, it seems that this is not the case for a quiver plot.

Tags for 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