删除Python图中的杂散垂直线

时间:2014-01-08 05:16:29

标签: python algorithm math

如何删除Python图形中的杂散垂直线?

以下是两个例子。

示例1:http://www.flickr.com/photos/113142397@N03/11696015694/

示例2:http://www.flickr.com/photos/113142397@N03/11696895026/in/photostream/

示例1中的代码:

from functools import partial
import mpmath as mp
import numpy as np
import scipy.optimize as so
import matplotlib.pyplot as plt
from pylab import *
from operator import itemgetter

def boundarycondition(m, B, l):
    return mp.whitm(0.5*(m+l/B), 0.5*m, 0.5*B)

B_window = 0.01, 30                          
l_window = 0.01, 30                          
maxm = 11
numberofpoints = 300
Blist=np.linspace(*B_window,num=numberofpoints)                 
minimumlist=[1000]*numberofpoints

for m in range(1,maxm+1):                                                   
    Bs = []                                     
    ls = []                                    
    j = 0                                       
    for B in Blist:                             
      try:                                            
        l = so.brentq(partial(boundarycondition, m, B), 0, 3*B)
      except ValueError:                                      
        pass
      else:                                          
        Bs.append(B)
        ls.append(l)

        minimumlist[j]=min(minimumlist[j],l)
      j = j + 1

    plt.plot(Bs, ls, color='black', linestyle="--")

    minindex=min(enumerate(ls), key=itemgetter(1))[0] 
    plt.plot([Bs[minindex]], [ls[minindex]],'k^')

plt.plot(Blist, minimumlist, color='black', linestyle="-", linewidth = 2)

X=np.linspace(*B_window, num=numberofpoints)
plt.plot(X,X, color="black", linewidth=2, linestyle="--")                    
plt.plot(X, 0.59*X, color="black", linewidth=2, linestyle="--")
plt.xlim(*B_window)
plt.ylim(*l_window)                                        
plt.xlabel(r"$B$", fontsize=15)
plt.ylabel(r"$\lambda_D$", fontsize=15)

plt.show()

0 个答案:

没有答案