制作散点图 [英] Make contour of scatter

查看:72
本文介绍了制作散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中,如果我有一组数据

In python, If I have a set of data

x, y, z

我可以散布

import matplotlib.pyplot as plt
plt.scatter(x,y,c=z)

如何获得散点图的plt.contourf(x,y,z)?

推荐答案

您可以使用b.所建议>另一个答案:

You can use tricontourf as suggested in case b. of this other answer:

import matplotlib.tri as tri
import matplotlib.pyplot as plt

plt.tricontour(x, y, z, 15, linewidths=0.5, colors='k')
plt.tricontourf(x, y, z, 15)

旧回复:

使用以下函数转换为轮廓f所需的格式:

Old reply:

Use the following function to convert to the format required by contourf:

from numpy import linspace, meshgrid
from matplotlib.mlab import griddata

def grid(x, y, z, resX=100, resY=100):
    "Convert 3 column data to matplotlib grid"
    xi = linspace(min(x), max(x), resX)
    yi = linspace(min(y), max(y), resY)
    Z = griddata(x, y, z, xi, yi)
    X, Y = meshgrid(xi, yi)
    return X, Y, Z

现在您可以这样做:

X, Y, Z = grid(x, y, z)
plt.contourf(X, Y, Z)

这篇关于制作散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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