SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Gordon H. <go...@rf...> - 2012年05月25日 16:18:01
I am a matplotlib noob, but I have searched the documentation, lists etc 
and cannot find a simple way to stop a curve being drawn once it crosses 
another curve. In the attached example, I am trying to draw the solid 
curve only until it intersects the dashed one. I have tried using the 
numpy.where() method, but it does not seem to be the right way to go 
about it- I end up having to write FOR loops and so on, and that does 
not make use of the vectorization advantages of numpy. Seems like there 
ought to be a simple way to do this.
Gordon
mport numpy as np
import matplotlib.pyplot as plt
def ig_CRM(vg,V,L,Ts):
 return ((Ts*vg/(2*L))*(1-(vg/V)))
def ig_CCM(vg,V,L,Ts,d):
 return (Ts*vg*d**2/(2*L))/(1-vg/V)
L= 110*10**-6
Ts= 10**-5
V= 400
vg= np.arange(0.0,400.0,1.0)
ig_bdry= ig_CRM(vg,V,L,Ts)
plt.plot(vg,ig_bdry,'--')
ig_d2=ig_CCM(vg,V,L,Ts,0.2)
plt.plot(vg,ig_d2)
plt.axis([0, 400, 0, 20])
plt.show()
From: Jerzy K. <jer...@un...> - 2012年05月27日 16:56:34
Gordon Hardmant :
> I ...cannot find a simple way to stop a curve being drawn once it crosses
> another curve. In the attached example, I am trying to draw the solid
> curve only until it intersects the dashed one. I have tried using the
> numpy.where() method, but it does not seem to be the right way to go
> about it- I end up having to write FOR loops and so on, and that does
> not make use of the vectorization advantages of numpy.
Try to insert just before plot(...) the following two lines:
igc=np.sign(ig_bdry-ig_d2)
ig_d2[igc!=igc[1] ]=np.nan
This [1] is a place which discriminates where the difference sign is 
"good". Of course this will produce
some bedlam if there are many intersections.
You didn't say whether you want to plot the dashed curve entirely. If 
not, just truncate all three, the solid, the dashed
and the abscissa, where the sign is OK.
Good luck.
Jerzy Karczmarczuk
Caen, France
From: Stan W. <sta...@nr...> - 2012年05月31日 18:26:11
> From: Jerzy Karczmarczuk [mailto:jer...@un...] 
> Sent: Sunday, May 27, 2012 12:56
> 
> Gordon Hardmant :
> > I ...cannot find a simple way to stop a curve being drawn once it crosses
> > another curve. In the attached example, I am trying to draw the solid
> > curve only until it intersects the dashed one. I have tried using the
> > numpy.where() method, but it does not seem to be the right way to go
> > about it- I end up having to write FOR loops and so on, and that does
> > not make use of the vectorization advantages of numpy.
> Try to insert just before plot(...) the following two lines:
> 
> igc=np.sign(ig_bdry-ig_d2)
> ig_d2[igc!=igc[1] ]=np.nan
Or, if you want to preserve the original data, index it with a boolean array:
 under = (ig_d2 <= ig_bdry)
 plt.plot(vg[under], ig_d2[under])
If you need to determine the intersection more precisely, you could define a
function of vg, V, L, Ts, and d that returns the difference between ig_CRM and
ig_CCM for those parameters, then use a root-finding routine [1] to
numerically find the vg for which that function returns essentially zero.
[1] http://docs.scipy.org/doc/scipy/reference/optimize.html#root-finding
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /