使用Matplotlib平滑轮廓图中的数据 [英] Smoothing Data in Contour Plot with Matplotlib

查看:110
本文介绍了使用Matplotlib平滑轮廓图中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Matplotlib创建轮廓图.我有所有数据 在多维数组中.它是12长,大约2000宽.就是这样 基本上是12个长度为2000的列表的列表.我有等高线图 工作正常,但我需要使数据平滑.我读了很多 例子.不幸的是,我没有数学背景来了解什么是 跟他们继续.

I am working on creating a contour plot using Matplotlib. I have all of the data in an array that is multidimensional. It is 12 long about 2000 wide. So it is basically a list of 12 lists that are 2000 in length. I have the contour plot working fine, but I need to smooth the data. I have read a lot of examples. Unfortunately, I don't have the math background to understand what is going on with them.

那么,我该如何平滑这些数据?我有一个例子,说明我的图形是什么样的 以及我希望它看起来像什么.

So, how can I smooth this data? I have an example of what my graph looks like and what I want it to look more like.

这是我的图

我也希望它看起来更相似:

What I want it to look more similar too:

我必须像第二幅图中那样平滑轮廓图吗?

What means do I have to smooth the contour plot like in second plot?

我正在使用的数据是从XML文件中提取的.但是,我将显示 数组的一部分.由于数组中每个元素的长度约为2000个项目,因此我 只会显示摘录.

The data I am using is pulled from an XML file. But, I will show the output of part of the array. Since each element in the array is around 2000 items long, I will only show an excerpt.

以下是示例:

[27.899999999999999, 27.899999999999999, 27.899999999999999, 27.899999999999999,
 28.0, 27.899999999999999, 27.899999999999999, 28.100000000000001, 28.100000000000001,
 28.100000000000001, 28.100000000000001, 28.100000000000001, 28.100000000000001,
 28.100000000000001, 28.100000000000001, 28.0, 28.100000000000001, 28.100000000000001,
 28.0, 28.100000000000001, 28.100000000000001, 28.100000000000001, 28.100000000000001,
 28.100000000000001, 28.100000000000001, 28.100000000000001, 28.100000000000001,
 28.100000000000001, 28.100000000000001, 28.100000000000001, 28.100000000000001,
 28.100000000000001, 28.100000000000001, 28.100000000000001, 28.100000000000001,
 28.100000000000001, 28.100000000000001, 28.0, 27.899999999999999, 28.0,
 27.899999999999999, 27.800000000000001, 27.899999999999999, 27.800000000000001,
 27.800000000000001, 27.800000000000001, 27.899999999999999, 27.899999999999999, 28.0,
 27.800000000000001, 27.800000000000001, 27.800000000000001, 27.899999999999999,
 27.899999999999999, 27.899999999999999, 27.899999999999999, 28.0, 28.0, 28.0, 28.0,
 28.0, 28.0, 28.0, 28.0, 27.899999999999999, 28.0, 28.0, 28.0, 28.0, 28.0,
 28.100000000000001, 28.0, 28.0, 28.100000000000001, 28.199999999999999,
 28.300000000000001, 28.300000000000001, 28.300000000000001, 28.300000000000001,
 28.300000000000001, 28.399999999999999, 28.300000000000001, 28.300000000000001,
 28.300000000000001, 28.300000000000001, 28.300000000000001, 28.300000000000001,
 28.399999999999999, 28.399999999999999, 28.399999999999999, 28.399999999999999,
 28.399999999999999, 28.300000000000001, 28.399999999999999, 28.5, 28.399999999999999,
 28.399999999999999, 28.399999999999999, 28.399999999999999]

请记住,这只是摘录.数据的维度为12行 1959年专栏.列的更改取决于从XML导入的数据 文件.使用Gaussian_filter后,我可以查看这些值,并且它们可以 改变.但是,这些变化不足以影响等高线图.

Keep in mind this is only an excerpt. The dimension of the data is 12 rows by 1959 columns. The columns change depending on the data imported from the XML file. I can look at the values after I use the Gaussian_filter and they do change. But, the changes are not great enough to affect the contour plot.

推荐答案

您可以使用

左侧显示原始数据,高斯滤波后的右侧显示

The left-side shows the original data, the right-side after gaussian filtering.

以上大部分代码摘自 Scipy Cookbook ,该书演示了使用手工制作的高斯核.由于scipy具有相同的内置功能,因此我选择使用gaussian_filter.

Much of the above code was taken from the Scipy Cookbook, which demonstrates gaussian smoothing using a hand-made gauss kernel. Since scipy comes with the same built in, I chose to use gaussian_filter.

这篇关于使用Matplotlib平滑轮廓图中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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