Gerardo,
I think the approach used in this code should do what you want. Dorry I
don't have time for more explanation...
-Chris
Gerardo Rivera wrote:
Hi,
I'm trying to draw a line given an angle, magnitude, x0 and y0
location on a 2d line plot. I use the "cosine" and "sine" to find
the x1 and y1 locations so that I can draw a line segment from x0, y0
to x1, y1. This works fine on a 200 x 200 (Width x Height) pixel
graph. However, I have an input form where the user can change the
plot size, for example 200x800 or 800x200.
The "magnitude" is along the y-axis and "time" is along the x-axis.
At a particular point in time the magnitude and angle is given and I
have to calculate the x1 and y1 values. The max magnitude along the
y-axis (height) is always the same whether it is 200 pixels in height
or 800 pixels in height.
The scientist I'm working with wants to see the magnitude (x1,y1) of
each plot look correct if the graph is 800 pixels or 200 pixels in
height. He also wants the correct angle if you stretch the graph
from 200 pixels wide to 800 pixels wide and then down to 100 pixels
wide.
I've been trying to use a ratio of the graph size to maintain the
correct sizing but with no luck. Basically, the scientist want to
maintain the same angle and reduce or increase the magnitude in the
y-axis if the graph height is reduced or increased.
Does anyone have an answer to this solution? Maintaining the same
angle and varying the magnitude based on the y-axis height.
Since, I have a lot of points I started to use a LineCollection to
speed the rendering speed.
Gerardo
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
[EMAIL PROTECTED]
#!/usr/bin/env python2.4
import matplotlib
from matplotlib import transforms
from matplotlib.collections import LineCollection
import pylab
import matplotlib.numerix as N
class VectorLineCollection(LineCollection):
def __init__(self, Points, Angles, fig, axis):
self.Points = Points
self.Angles = Angles
self.ArrowLength = 0.3 # should be inches
self.ArrowHeadSize = 0.08 # should be inches
self.ArrowHeadAngle = 45. # degrees
self.CalcArrowPoints()
self.CalcArrows()
LineCollection.__init__(self,
self.Arrows,
offsets=self.Points,
transOffset=axis.transData, # transforms the x,y offsets
)
trans = transforms.scale_transform(fig.dpi, fig.dpi)
self.set_transform(trans) # the points to pixels transform
return None
def CalcArrowPoints(self):
L = self.ArrowLength
S = self.ArrowHeadSize
phi = self.ArrowHeadAngle * N.pi / 360
#print "phi:", phi
#print "S", S
self.ArrowPoints = N.array( ( (0, L, L - S*N.cos(phi), L, L - S*N.cos(phi) ),
(0, 0, S*N.sin(phi), 0, -S*N.sin(phi) ) ),
N.Float )
return None
def CalcArrows(self):
ArrowPoints = self.ArrowPoints
self.Arrows = N.zeros((self.Angles.shape[0],5,2), N.Float)
for i, theta in enumerate(self.Angles):
RotationMatrix = N.array( ( ( N.cos(theta), -N.sin(theta) ),
( N.sin(theta), N.cos(theta) ) ),
N.Float
)
Pts = N.transpose(N.matrixmultiply(RotationMatrix, ArrowPoints))
self.Arrows[i] = Pts
return None
if __name__ == "__main__":
## create a little data to plot
x = N.arange(0, 2*N.pi, 0.05)
y = N.sin(x)
theta = x * 1# totally fake angle data!
x.shape = (-1,1)
y.shape = (-1,1)
xy = N.concatenate((x,y),1)
## Now plot it
Fig = pylab.figure()
ax = Fig.add_subplot(111)
VLC = VectorLineCollection(xy, theta, Fig, ax)
ax.add_collection(VLC)
ax.plot(xy[:,0], xy[:,1], 'o')
ax.set_xlim(-1., 7)
ax.set_ylim(-1.2, 1.2)
ax.grid(True)
pylab.show()
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users