Matplotlib:等高线图的数据三次插值(或FIT)

时间:2013-08-23 12:02:44

标签: python matplotlib scipy interpolation cubic

我有一系列来自设备的数据。 如何为该图绘制立方插值或FIT?

import matplotlib.pyplot as plt

a = [[1,1,1],[2,2,2],[3,3,3]]
b = [[1,2,3],[1,2,3],[1,2,3]]
c = [[3,2,1],[1,4,2],[4,5,1]]

fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
fig1.set_size_inches(3.54,3.54)
#Create Contour plot
contour=ax1.contour(a,b,c)

plt.show()

1 个答案:

答案 0 :(得分:2)

你可以adapt @Joe Kington's suggestion使用scipy.ndimage.zoom,对于你的立方插值情况完全适合:

import matplotlib.pyplot as plt
import numpy as np

from scipy.ndimage import zoom
from mpl_toolkits.mplot3d import axes3d

# Receive standard Matplotlib data for 3d plot
X, Y, Z = axes3d.get_test_data(1) # '1' is a step requested data

#Calculate smooth data
pw = 10 #power of the smooth
Xsm = zoom(X, pw)
Ysm = zoom(Y, pw)
Zsm = zoom(Z, pw)

# Create blank plot
fig = plt.figure()
#Create subplots
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)
# Plotting
ax1.contour(X, Y, Z)
ax2.contour(Xsm, Ysm, Zsm)

plt.show()

给出了:

enter image description here