我试图绘制这个简单的列表energy_list
,如下所示
energy_list = [-31.996423234368955, -32.00000000000772, -32.000000000000014, -31.99500000000001,
-31.999999999999982, -32.0, -32.000000000000014, -32.00000000000001,
-32.00000000000002, -32.00000000000001, -32.0, -31.99500000000002,
-32.000000000000014, -32.0, -32.000000000000036, -32.00000000000001, -32.0,
-32.00000000000001, -32.000000000023576, -32.000000000000014, -32.00000000000007,
-31.999999999999996, -32.0, -32.00000000000002, -32.0, -31.999999999999993,
-32.00000000000001, -32.000000000000014, -31.995000000000005, -32.000000000429914,
-32.0, -32.0, -31.99999999999999, -31.999999999999996, -31.99999999999999, -32.0,
-31.999999999999996, -32.0, -32.00000000000001, -32.00000000000007,
-32.00000000000001, -31.999999999999996, -32.000000000000014, -31.995000000000005,
-32.00000000000001, -32.000000000000014, -32.00000000000001, -32.00000000000001,
-32.000000000000014, -32.00000000000565]
这个图应该是一个常数函数,但是当我用plt.plot(energy_list)
绘制它时,我得到了这个烦人的图:
到底发生了什么?
1条答案
按热度按时间7vux5j2d1#
注意到坐标轴左上角的小数字
-3.199e1
了吗?这告诉你线的y
值是由视y坐标指定的值加上-31.99
。因为你没有指定y轴的界限,matplotlib会自动从数据中计算出来,并放大到这个水平,所以你的数据 * 不是 * 常数。指定y限制后,数据看起来像一条常量线:
如果您不想硬编码这些限制,您可以只对数据的最大值/最小值加上/减去一个设定值: