0

我正在尝试将高斯滤波器应用于 2 直方图,但是当我使用输入数据时 y 比例不合适。

如果我运行一个示例数据集,它工作正常。这是一个使用随机数据的例子。

import matplotlib.pyplot as plt
import random
import numpy as np

x = random.sample(range(80), 10)
y = random.sample(range(80), 10)

fig, ax = plt.subplots()
plt.scatter(x,y)
z,x,y,p = plt.hist2d(x,y, bins = 40, range = np.array([(0, 80), (0, 80)]))
plt.imshow(z.T, interpolation = 'gaussian', origin = 'lower', cmap = 'jet', extent = [0,80,0,80])

输出:在此处输入图像描述

但是,当我尝试从输入数据生成相同的图时,它不起作用。见下文。

x = [29160, 30420, 30840, 31680, 31920, 32040, 33000, 33300, 33480, 34200]
y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

fig, ax = plt.subplots()
plt.scatter(x,y)
z,x,y,p = plt.hist2d(x,y, bins = 40, range = np.array([(29000, 35000), (0, 10)]))
plt.imshow(z.T, interpolation = 'gaussian', origin = 'lower', cmap = 'jet', extent = [29000,35000,0,10])

在此处输入图像描述

4

1 回答 1

0

查看文档。https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imshow.html

在您的函数中使用aspect='auto'和适当的插值。plt.imshow()由于您的图像方面非常倾斜,您希望将其重新缩放到轴大小。

于 2018-05-16T04:09:34.273 回答