Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib.plot由于图片大小而导致的点混乱?_Python_Matplotlib - Fatal编程技术网

Python matplotlib.plot由于图片大小而导致的点混乱?

Python matplotlib.plot由于图片大小而导致的点混乱?,python,matplotlib,Python,Matplotlib,大家好!我使用python matplotlib.plot来绘制一条线 这是我的数据 x = ['1000', '5950', '10900', '15850', '20800', '25750', '30700', '35650', '40600', '45550', '50500', '55450', '60400', '65350', '70300', '75250', '80200', '85150', '90100', '95050', '100000'] y = ['0.003383

大家好!我使用python matplotlib.plot来绘制一条线 这是我的数据

x = ['1000', '5950', '10900', '15850', '20800', '25750', '30700', '35650', '40600', '45550', '50500', '55450', '60400', '65350', '70300', '75250', '80200', '85150', '90100', '95050', '100000']
y = ['0.003383', '0.16341', '0.543723', '1.19463', '2.12827', '3.33978', '4.70849', '6.46607', '8.52736', '11.2711', '14.3101', '18.176', '26.1123', '32.0252', '31.692', '43.1399', '48.2962', '48.2436', '52.6464', '61.8072', '68.8354']
我用IPython写的

import matplotlib.pyplot as plt
plt.plot(x,y)
plt.show()
它给了我这个

我的意思是,根据
x
y
列表,它应该是一条递增的曲线。
那么,有人能帮忙吗?
如果您能提供任何建议,我将不胜感激:)

这是因为您使用的列表包含字符串。实际需要的是
x
的整数,以及
y
的浮点。为此,您可以使用列表理解将列表的内容强制转换为
int
float

import matplotlib.pyplot as plt

x = ['1000', '5950', '10900', '15850', '20800', '25750', '30700', '35650', '40600', '45550',
     '50500', '55450', '60400', '65350', '70300', '75250', '80200', '85150', '90100', '95050', '100000']
y = ['0.003383', '0.16341', '0.543723', '1.19463', '2.12827', '3.33978', '4.70849', '6.46607',
     '8.52736', '11.2711', '14.3101', '18.176', '26.1123', '32.0252', '31.692', '43.1399', '48.2962', '48.2436',
     '52.6464', '61.8072', '68.8354']

# Convert contents of lists
new_x = [int(i) for i in x]
new_y = [float(j) for j in y]

fig, (ax1, ax2) = plt.subplots(1,2)
ax1.plot(x,y)
ax1.set_title("List of strings")

ax2.plot(new_x,new_y)
ax2.set_title("Lists have been converted")

plt.show()
产生:


发生这种情况是因为列表中包含字符串。