简体   繁体   English

在 matplotlib 中绘制 numpy arrays 的内容

[英]Plotting the content of numpy arrays in matplotlib

I am trying to plot the content of the arrays x and lj in the following code.我正在尝试在以下代码中 plot arrays xlj的内容。 However, the point in the plots are not the one inside the arrays.但是,图中的点不是 arrays 内的点。 Can someone help me see the mistake I did?有人可以帮我看看我犯的错误吗? I am still new in python.我还是 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()

This is the content of the arrayys and the follwoiing one is the plot done with plt.plot()这是数组的内容,下面是使用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

在此处输入图像描述

Almost division by zero The plot is correct, lj[0] is almost equal to infinity, remove the first element, to get a better curve几乎被零除 plot 是正确的,lj[0] 几乎等于无穷大,去掉第一个元素,得到更好的曲线

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM