简体   繁体   English

int()参数必须是字符串,类似字节的对象或数字,而不是“列表”

[英]int() argument must be a string, a bytes-like object or a number, not 'list'

I am trying to plot a graph using matplotlib.pyplot in Python but getting an error: 我试图在Python中使用matplotlib.pyplot绘制图形,但出现错误:

int() argument must be a string, a bytes-like object or a number, not 'list' int()参数必须是字符串,类似字节的对象或数字,而不是“列表”

in the second-to-last line. 在倒数第二行。

Here is the code: 这是代码:

import numpy as np
import random
import matplotlib.pyplot as plt

#constants
mUn0 = 1350
Vcat = 18000000
n = 2 * pow(10,16)
e = 1.6 * pow(10,-19)

#variable
E = 1000
d = []
f = []

for i in range(1,E):
    j = log(n*e*mUn0) + log(i) - 0.5 * log(1+pow((mUn0*i/Vcat),2))
    f.append(j)
    d.append(log(i))
plt.xlabel('E')
plt.ylabel('V')
plt.subplot(2,1,2)
plt.subplot(f,d,'bo')
plt.show()

Thank you 谢谢

pyplot.subplot() requires subplot(nrows, ncols, plot_number) , all three options are integers. pyplot.subplot()需要pyplot.subplot() subplot(nrows, ncols, plot_number) ,所有三个选项都是整数。

Matplotlib is trying to cast your f and d lists to integer type and failing. Matplotlib试图将fd列表强制转换为整数类型并失败。

Just a couple of small issues. 只是几个小问题。 You have to use plt.plot() to plot, and you can't just use log , you need np.log() or to import the math module and then use math.log() . 您必须使用plt.plot()进行绘制,而不能仅使用log ,您需要np.log()或导入math模块,然后使用math.log() I noted the lines I changed with #FIXED 我注意到我用#FIXED更改的行

import numpy as np
import random
import matplotlib.pyplot as plt

#constants
mUn0 = 1350
Vcat = 18000000
n = 2 * pow(10,16)
e = 1.6 * pow(10,-19)

#variable
E = 1000
d = []
f = []

for i in range(1,E):
    j = np.log(n*e*mUn0) + np.log(i) - 0.5 * np.log(1+pow((mUn0*i/Vcat),2))  #FIXED
    f.append(j)
    d.append(np.log(i)) #FIXED
plt.xlabel('E')
plt.ylabel('V')
plt.subplot(2,1,2) #not needed, but maybe a holdover from full code
plt.plot(f,d,'bo') #FIXED
plt.show()

That takes care of the syntax errors. 这样可以解决语法错误。 Using a subplot works with one plot but you don't need it, so I don't know what type of logic error that is (do you want two plots?) 使用子图可以处理一个图,但是您不需要它,所以我不知道这是什么类型的逻辑错误(您要两个图吗?)

暂无
暂无

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

相关问题 int()参数必须是字符串,类似字节的对象或数字,而不是“元组” - int() argument must be a string, a bytes-like object or a number, not 'tuple' int() 参数必须是字符串、类似字节的对象或数字,而不是 'QueryDict' - int() argument must be a string, a bytes-like object or a number, not 'QueryDict' int() 参数必须是字符串、类似字节的对象或数字,而不是“QuerySet” - int() argument must be a string, a bytes-like object or a number, not 'QuerySet' int() 参数必须是字符串、类似字节的对象或数字,而不是“NoneType” - int() argument must be a string, a bytes-like object or a number, not 'NoneType' 命令行 - int()参数必须是字符串,类似字节的对象或数字,而不是'list' - command line - int() argument must be a string, a bytes-like object or a number, not 'list' int()参数必须是字符串,类似字节的对象或数字,而不是'list'代码错误 - int() argument must be a string, a bytes-like object or a number, not 'list' Error in code Django TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是'list' - Django TypeError: int() argument must be a string, a bytes-like object or a number, not 'list' 错误:装饰器@action中的“int()参数必须是一个字符串,一个类似字节的object或一个数字,而不是'list'” - error: “int() argument must be a string, a bytes-like object or a number, not 'list'” in decorator @action 类型错误:int() 参数必须是字符串、类似字节的对象或数字,而不是“列表” - TypeError: int() argument must be a string, a bytes-like object or a number, not 'list' int()参数必须是字符串,类似字节的对象或数字,而不是“列出” Python python-tcod Roguelike - int() argument must be a string, a bytes-like object or a number, not 'list' Python python-tcod Roguelike
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM