On Sun, Nov 13, 2011 at 7:52 AM, asd dasdas <a.lwt...@googlemail.com> wrote:
> Hi everyone,
>
> can someone please help me how to make a plot like this:
> http://tutorial.math.lamar.edu/Classes/DE/PhasePlane_files/image002.gif
>
> The main issue with it is in the (black) trajectories. As far as i know
> there is no function in matplotlib to plot trajectories with arrows
> pointing in a direction.
>
> But I think a good workaround is: plotting the trajectories with plot(..)
> and use quiver(..) at certain points to get an arrows.
>
> A minimal example would be:
>
> import matplotlib.pyplot as plt
> import numpy as np
> import scipy.integrate as integrate
>
> if __name__=="__main__":
> t = np.linspace(0, 20, 1000)
> l = 3
> # some starting points
> X0s = [[-3.0, 0],
> [-3.0, -1],
> [-3.0, -2],
> [-2, -3.0],
> [-1, -3.0],
> [0, -3.0],
> [1, -3.0],
> [2, -3.0],
> [3.0, -2],
> [3.0, -1],
> [3.0, 0.0],
> [3.0, 1],
> [3.0, 2],
> [2, 3.0],
> [1, 3.0],
> [0, 3.0],
> [-1, 3.0],
> [-2, 3.0],
> [-3.0, 2],
> [-3.0, 1],
> [0, 0.01],
> [0, -0.01],
> [0.01, 0],
> [-0.01, 0]]
> sattel = lambda x,t=0: [-x[0], x[1]]
> plt.axis([-l,l,-l,l])
>
> for X0 in X0s:
> state = integrate.odeint(sattel, X0, t).T
> plt.plot(*state, color="k", linewidth=1)
> xs = state[:,::10]
> x_ds = np.asarray(sattel(xs))
> M = np.hypot(x_ds[0],x_ds[1])
> plt.quiver(xs[0],xs[1],x_ds[0]/M,x_ds[1]/M,
> pivot="mid")#,scale=100, scale_units="width",linewidth=5)
>
> plt.axis([-l,l,-l,l])
> plt.show()
>
> That is pretty much what I was looking for except the shafts of the arrows
> that I can't get rid off.
> You can see what I tried to get this done by uncomment the quiver
> parameter.
> Doing this, you can see, the shafts are (nearly) gone, but the arrows look
> horrible. I wonder if there is anyway to tell quiver(..) to only plot the
> heads of the arrow, without the shaft.
>
> Can you please give me a hint how to do this?
>
>
You can increase both the "headlength" and "headaxislength" parameters.
It's admittedly pretty hacky, but I think it'll do what you want.
Also, this is related to a previous discussion on streamlines. A couple of
users were kind enough to post code in this
thread<http://old.nabble.com/Any-update-on-streamline-plot-td30902670.html>.
(And there was talk of integrating one or both of these into matplotlib.)
I've actually been using a modified version of Tom Flannaghan's code. Tom's
code <http://www.atm.damtp.cam.ac.uk/people/tjf37/streamplot.py> uses a
FancyArrowPatch to draw the arrow heads, which may be an alternative
approach to using quiver. Note that neither streamline function allows you
to specify starting points (you specify the streamline density and the
algorithms pick their own starting points).
Best,
-Tony
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users