如何平滑matplotlib等高线图? [英] How to smooth matplotlib contour plot?

查看:377
本文介绍了如何平滑matplotlib等高线图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下形状的numpy数组:(33,10).当我绘制轮廓时,会得到如下丑陋的图像:

I have numpy array with this shape: (33,10). When I plot contour I get ugly image like this:

contour()似乎没有关于平滑或某种插值功能的任何论据.

while contour() doesn't seem to have any argument about smoothing or some sort of interpolation feature.

我以某种方式期望提供轮廓图的工具也应该提供平滑处理.
在MPL中有直接的方法吗?

I somehow expected that tool which offers contour plot should offer smoothing too.
Is there straight forward way to do it in MPL?

推荐答案

正如其他人已经指出的那样,您需要对数据进行插值.

As others have already pointed out, you need to interpolate your data.

有很多不同的方法可以做到这一点,但是对于初学者来说,请考虑scipy.ndimage.zoom.

There are a number of different ways to do this, but for starters, consider scipy.ndimage.zoom.

作为一个简短的例子:

import numpy as np
import scipy.ndimage
import matplotlib.pyplot as plt

data = np.loadtxt('data.txt')

# Resample your data grid by a factor of 3 using cubic spline interpolation.
data = scipy.ndimage.zoom(data, 3)

plt.contour(data)
plt.show()

这篇关于如何平滑matplotlib等高线图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆