Python matplotlib.plot由于图片大小,pointe搞砸了?

时间:2017-12-08 07:26:52

标签: 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', '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()

它给了我这个 check this

我的意思是,根据x y列表,它应该是增加曲线。
那么,有人可以协助吗? 如果你提出任何建议,我将不胜感激:)

1 个答案:

答案 0 :(得分:0)

这是因为您使用的列表包含字符串。你真正想要的是x的整数和y的浮点数。为此,您可以使用列表推导将列表内容强制转换为intfloat

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()

产生:

enter image description here