平滑轮廓图已完全填充

问题描述 投票:0回答:1

我具有(X,Y,Z)值的数据。我试图用Z值绘制强度密度图。但是,我得到的图不平滑,并且具有多面体,即未完全填充。

以下是带有Data的代码

但是我想获得平滑且完全填充的图


import numpy as np
from scipy.interpolate import griddata
import matplotlib.pyplot as plt
import xlrd
location = "~/Desktop/Data.xlsx"
data = xlrd.open_workbook(location)
sheet = data.sheet_by_index(0)
sample=2000

x=np.array(sheet.col_values(0))[0:sample]
y=np.array(sheet.col_values(1))[0:sample]
z=np.hamming(9000)[0:sample]
print z
def plot_contour(x,y,z,resolution = 500,contour_method='cubic'):
    resolution = str(resolution)+'j'
    X,Y = np.mgrid[min(x):max(x):complex(resolution),   min(y):max(y):complex(resolution)]
    points = [[a,b] for a,b in zip(x,y)]
    Z = griddata(points, z, (X, Y), method=contour_method)
    return X,Y,Z

X,Y,Z = plot_contour(x,y,z,resolution = 500,contour_method='linear')

plt.style.context("seaborn-deep")

plt.contourf(X,Y,Z)
plt.colorbar()
plt.show()

这是输出:

enter image description here

这是我要使用contourplotf实现的目标:

enter image description here

python matplotlib contourf
1个回答
1
投票

plt.contourf()并不是这里的主要问题,它只是处理它拥有的数据。问题是scipy.interpolate.griddata()中的线性插值。

我建议不要使用griddata,而应使用以下方法之一:

所有这些方法都将填入网格。如果使用verde来绘制结果,则将得到问题中显示的图的类型-不是sklearn.gaussian_process图。

[sklearn.gaussian_process显示所有这些方法(包括plt.imshow())。

© www.soinside.com 2019 - 2024. All rights reserved.