matplotlib.pyplot没有正确设置散点图的对数轴范围

时间:2016-08-10 01:04:52

标签: python matplotlib logarithm

我试图在具有对数y轴的2D散点图上绘制5个点(x,y)。生成绘图但是没有很好地选择y轴的范围,因此仅显示一个点。当我移除第一个点(0.38,0.005)时,问题就消失了。

这是matplotlib中的错误吗?

有人可以尝试复制吗?

import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline
emissions_abs_pts = np.array([
    [0.38, 0.005], # without this point it scales appropriately
    [0.42, 0.05],
    [0.67, 0.5],
    [0.96, 5.0],
    [1.0, 50.0]
])
fig, ax = plt.subplots(1, 1)
ax.scatter(emissions_abs_pts[:,0], emissions_abs_pts[:,1])
ax.set_yscale('log')

以下是包含所有五个点的情节: enter image description here

注意y轴范围是 10 ^ 1 10 ^ 2

这是第一点注释掉的情节: enter image description here

我使用%matplotlib inline和运行Python 2.7的jupyter笔记本。

1 个答案:

答案 0 :(得分:2)

编辑:我得到了相同的缩放错误。

将其添加到代码的末尾

ax.set_ylim([0.001, 100])

它将强制轴行为。

这可能是一个愚蠢的事情? 当我从命令行将代码作为脚本运行时(将其改为" inline"),轴可以正确缩放而无需强制它们。