[英]Plotting the content of numpy arrays in matplotlib
我正在嘗試在以下代碼中 plot arrays x
和lj
的內容。 但是,圖中的點不是 arrays 內的點。 有人可以幫我看看我犯的錯誤嗎? 我還是 python 的新手。
from matplotlib import pyplot as plt
import numpy as np
import math
lj=np.arange(10, dtype=np.float).reshape(10,1)
x=np.arange(10, dtype=np.float).reshape(10,1)
lj.fill(0)
x.fill(0)
for i in range(len(x)):
x[i,0]=i*0.1
lj[i,0]=4.0*( (1.0/(x[i,0]+0.0000001) )**12 - ( 1.0/(x[i,0]+0.0000001) )**6 )
for i in range(len(x)):
print(x[i,0],"\t\t\t",lj[i,0])
plt.plot(x,lj,"o")
plt.show()
這是數組的內容,下面是使用plt.plot()
完成的 plot
0.0 4e+84
0.1 3999948000335.996
0.2 976494140.831542
0.30000000000000004 7521188.628402116
0.4 237441.3028118298
0.5 16127.960985650918
0.6000000000000001 1751.8371605495026
0.7000000000000001 254.9905579573781
0.8 42.94879598363375
0.9 6.636105087302215
幾乎被零除 plot 是正確的,lj[0] 幾乎等於無窮大,去掉第一個元素,得到更好的曲線
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.