Вопрос

I am trying to understand, how scale works in quiver plot. I have found an explanation here , but I want to double check, that I understand what the author says.

When he says

Setting the angles keyword to 'xy' means that the vector components are scaled according to the physical axis units rather than geometrical units on the page.

Does he mean that, let's say, if I have some movement which is 1 pixel (to make it simple, let's say per 1 second) and this happens on a 232x232 image (actual thing I have), will the 1px/s movement show up scaled 232 times ? That is 1/232 ? Or will the 1px/s appear as representing 1 px (no matter the angle to the axis), that is it will take 1px, however that pixel appears on the image with 232 x 232 pixel size image ?

The actual scaling factor which multiplicatively converts vector component units to physical axis units is width/scale where width is the width of the plot in physical units and scale is the number specified by the scale keyword argument of quiver.

Does that mean that if say, I choose my scale to be 10, a vector that is actually 10px/s will appear as 1px/s ? (I know these are very basic questions but I am confused with the "physical axis" and the "geometrical units on the page").

I think I will test this by simply having two images, one sized, say 40x40 and the other 160x160, with same 1px movement and see how that affects the plot.

What I would like to do is to actually have 1px/s representing a 1px length, whatever that length is as represented by the plot (using matplotlib.pyplot).

Это было полезно?

Решение

OK, so I played around with synthetic data and using either " angles = 'xy' " or just leaving it out (i.e. having something like

q = pl.quiver(a[valid,0],a[valid,1],a[valid,2],a[valid,3], color='r',**kw), where one of the kwargs is your scale factor.

It seems to scale with the width of the plot. I used

pl.draw() pl.xticks(np.arange(0,120,32)) pl.yticks(np.arange(0,100,32)) pl.grid(color = 'y') pl.savefig(new_file, bbox = "tight") to save my figure (the actual images were 120x100 (in this case) , 120x120 and 64x64.

What I did to test it: I created one pixel shifts in the horizontal and vertical, then on some other images, a diagonal shift of 5px (3 right and 4 down).

To get 1px/s vector to take the length of 1px as in your image, you have to set the scale to the width of your plot i.e. in my case it was either 64 or 120. I wanted to see if having a non-square image will affect the scale, so I cropped the image to 100px height. From the few tests I have done, it does not seem to have any effect. It would be worth testing with different pixel shifts, but since the horizontal/vertical shifts were not scaled differently using different side length image, I think it is safe to assume it behaves as expected.

I wonder what is the reason for such scaling of vectors...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top