Matplotlib: Data cubic interpolation (or FIT) for Contour plot

浪子不回头ぞ 提交于 2019-12-04 19:45:33
Saullo G. P. Castro

You can adapt @Joe Kington's suggestion and use scipy.ndimage.zoom which for your case of a cubic interpolation fits perfectly:

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()

Which gives:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!