Backlogged question: Drawing vector fields with same scaling in New Graphics [message #92230] |
Mon, 02 November 2015 18:02  |
tianhuachengyue
Messages: 7 Registered: November 2015
|
Junior Member |
|
|
This is an unsolved problem about the vector() function in IDL. Gordon used to post this question on the site:
http://compgroups.net/comp.lang.idl-pvwave/drawing-vector-fi elds-with-new-graphics/2090071
But actually it wasn't quite solved:
Is there a way to plot (using New Graphics) two different vector fields on the same set of axes such that the vector fields have the same scaling? Below is a minimal working program. What I want (and sort of expect) is that the v2 vectors be proportionally scaled with respect to the v1 vectors. What I get is that the v2 vectors appear smaller than the v1 vectors, even though they are clearly the same in magnitude.
I followed the suggestions to set v1.length_scale = 2 and
vmag = mean(sqrt(vx^2 + vy^2)),
then set v2.length_scale = 2. / vmag to try to let v2 have the same scale as v1. But clearly it didn't help... Please see my codes below.
Anyone can help me out? Thanks!
PRO test_vector
x = [0.,1.,2.]
y = [0.,0.,0.]
vx = [1.,1.,1.]
vy = [1.,1.,1.]
vmag = mean(sqrt(vx^2 + vy^2))
v1 = vector(vx, vy, x, y, $
XTITLE='X', YTITLE='Y', $
XRANGE=[-1.,4.], YRANGE=[-1.,4.])
v1.arrow_thick = 2
v1.length_scale = 2
x = [1.,2.]
y = [1.,1.]
vx = [-1.0,-1.0]
vy = [-1.0,-1.0]
v2 = vector(vx, vy, x, y, $
/OVERPLOT, XRANGE=[-1.,4.], YRANGE=[-1.,4.])
v2.arrow_thick = 2
v2.length_scale = 2. / vmag
END
Huazeng
|
|
|
Re: Backlogged question: Drawing vector fields with same scaling in New Graphics [message #92274 is a reply to message #92230] |
Mon, 09 November 2015 09:20   |
chris_torrence@NOSPAM
Messages: 528 Registered: March 2007
|
Senior Member |
|
|
On Monday, November 2, 2015 at 7:02:11 PM UTC-7, tianhuachengyue wrote:
> This is an unsolved problem about the vector() function in IDL. Gordon used to post this question on the site:
> http://compgroups.net/comp.lang.idl-pvwave/drawing-vector-fi elds-with-new-graphics/2090071
>
> But actually it wasn't quite solved:
> Is there a way to plot (using New Graphics) two different vector fields on the same set of axes such that the vector fields have the same scaling? Below is a minimal working program. What I want (and sort of expect) is that the v2 vectors be proportionally scaled with respect to the v1 vectors. What I get is that the v2 vectors appear smaller than the v1 vectors, even though they are clearly the same in magnitude.
>
> I followed the suggestions to set v1.length_scale = 2 and
> vmag = mean(sqrt(vx^2 + vy^2)),
> then set v2.length_scale = 2. / vmag to try to let v2 have the same scale as v1. But clearly it didn't help... Please see my codes below.
> Anyone can help me out? Thanks!
>
> PRO test_vector
>
> x = [0.,1.,2.]
> y = [0.,0.,0.]
>
> vx = [1.,1.,1.]
> vy = [1.,1.,1.]
> vmag = mean(sqrt(vx^2 + vy^2))
>
> v1 = vector(vx, vy, x, y, $
> XTITLE='X', YTITLE='Y', $
> XRANGE=[-1.,4.], YRANGE=[-1.,4.])
> v1.arrow_thick = 2
> v1.length_scale = 2
>
> x = [1.,2.]
> y = [1.,1.]
> vx = [-1.0,-1.0]
> vy = [-1.0,-1.0]
>
> v2 = vector(vx, vy, x, y, $
> /OVERPLOT, XRANGE=[-1.,4.], YRANGE=[-1.,4.])
> v2.arrow_thick = 2
> v2.length_scale = 2. / vmag
>
> END
>
> Huazeng
Hi Huazeng,
I think you need to scale the second vector by the ratio of the magnitudes. Try this example:
x1 = [0.,1.,2.]
y1 = [0.,0.,0.]
vx1 = [3.,1.,1.]
vy1 = [3.,1.,1.]
vmag1 = max(sqrt(vx1^2 + vy1^2))
x2 = [0.5,1.5]
y2 = [0.,0.]
vx2 = [2.0,1.0]
vy2 = [2.0,1.0]
vmag2 = max(sqrt(vx2^2 + vy2^2))
print, vmag1, vmag2
v1 = vector(vx1, vy1, x1, y1, $
XTITLE='X', YTITLE='Y', $
XRANGE=[-1.,4.], YRANGE=[-1.,4.])
v1.arrow_thick = 2
v1.length_scale = 4
v2 = vector(vx2, vy2, x2, y2, color='red', $
/OVERPLOT, XRANGE=[-1.,4.], YRANGE=[-1.,4.])
v2.arrow_thick = 2
v2.length_scale = 4*vmag2/vmag1
Cheers,
Chris
|
|
|
|
|
Re: Backlogged question: Drawing vector fields with same scaling in New Graphics [message #92293 is a reply to message #92292] |
Thu, 12 November 2015 08:29  |
chris_torrence@NOSPAM
Messages: 528 Registered: March 2007
|
Senior Member |
|
|
On Wednesday, November 11, 2015 at 3:41:43 PM UTC-7, tianhuachengyue wrote:
> Hi Chris,
>
> I tried setting v2.length_scale = const*vmag2/vmag1 and now the plots are working perfectly. Thanks for the solution!
>
> BTW, I also tried vmag = mean(sqrt(vx^2+vy^2)) but this didn't work correctly. Any trick behind using vmag = max(sqrt(vx^2+vy^2)) instead using mean(sqrt(vx^2+vy^2))? It seemed to me the vector plot setting is related to the maximum value of vector magnitude.
>
> Cheers,
> Huazeng
Hi Huazeng,
Yes, you are correct - it is using the maximum magnitude. Using the mean would be a bad idea, as your maximum vectors might be huge but still have a reasonable mean. You can actually see a lot of this code yourself, in idlitvisvector__define.pro.
Cheers,
Chris
|
|
|