从 matplotlib 中删除偏移量
Remove offset from matplotlib
我正在尝试绘制从 h5 文件中读取的一些基本数据。对于上下文,它是使用各种阈值在图像中检测到的变化特征区域。
我可以绘制数据,但 y 轴使用科学记数法显示值。我能够克服这个问题,但现在有了抵消。我尝试了很多事情,但没有成功。在格式化轴和处理细节方面,我不太熟悉 matplotlib。
我的代码如下:
infile = 'myH5file.h5'
f = h5py.File(file, 'r')
dset = f['/DATA/DATA']
sum = []
threshold = ['1','2','3']
Th1 = dest[...,0]
Th1 = numpy.sum(Th1)
sum.append(Th1)
Th2 = dest[...,0]
Th2 = numpy.sum(Th2)
sum.append(Th2)
Th3 = dest[...,0]
Th3 = numpy.sum(Th3)
sum.append(Th3)
x = threshold
y = numpy.array(sum)
ax = plt.gca()
plt.scatter(x, y)
plt.ticklabel_format(style='plain', axis='y')
ax = plt.gca()
ax.set_yticklabels(ax.get_yticks())
plt.show()
这给了我以下输出:
如您所见,-50000000 有一个负偏移量。
我想删除它以便轴从 0 开始。
非常感谢任何帮助!!!
您应该能够使用 ylimits
明确指定要显示的范围。
要设置 y 轴范围,您可以使用 ax.set_ylim(lower_bound, upper_bound)
。
我正在尝试绘制从 h5 文件中读取的一些基本数据。对于上下文,它是使用各种阈值在图像中检测到的变化特征区域。 我可以绘制数据,但 y 轴使用科学记数法显示值。我能够克服这个问题,但现在有了抵消。我尝试了很多事情,但没有成功。在格式化轴和处理细节方面,我不太熟悉 matplotlib。
我的代码如下:
infile = 'myH5file.h5'
f = h5py.File(file, 'r')
dset = f['/DATA/DATA']
sum = []
threshold = ['1','2','3']
Th1 = dest[...,0]
Th1 = numpy.sum(Th1)
sum.append(Th1)
Th2 = dest[...,0]
Th2 = numpy.sum(Th2)
sum.append(Th2)
Th3 = dest[...,0]
Th3 = numpy.sum(Th3)
sum.append(Th3)
x = threshold
y = numpy.array(sum)
ax = plt.gca()
plt.scatter(x, y)
plt.ticklabel_format(style='plain', axis='y')
ax = plt.gca()
ax.set_yticklabels(ax.get_yticks())
plt.show()
这给了我以下输出:
如您所见,-50000000 有一个负偏移量。
我想删除它以便轴从 0 开始。
非常感谢任何帮助!!!
您应该能够使用 ylimits
明确指定要显示的范围。
要设置 y 轴范围,您可以使用 ax.set_ylim(lower_bound, upper_bound)
。