同一图中的几个等高线图 [英] several contour plots in the same figures

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

问题描述

我有几个 3d 功能.我想要两个在同一个图中绘制它们的等高线图以查看它们之间的差异.我希望在两个函数的轮廓之间看到一些交叉点.这是我的代码:

I have several 3d functions. I would like two plot the contour plots of them in the same figure to see the difference between them. I expect to see some crossings between contours of two functions. Here is my code:

plt.contour(xi, yi, F)
plt.contour(xi, yi, F1)        
plt.show()

但是,似乎第一个在最后被删除了,因为我只看到一个函数而没有任何轮廓交叉.有可能以某种方式解决这个问题吗?

But, it seems that the first one is erased at the end, since I see only one function without any crossing of contours. Is it possible to figure this out somehow?

推荐答案

我做了一个快速测试,我看到了两个轮廓.它们使用通用颜色的事实可能会引起误解.试试这个:

I did a quick test and I see both contours. The fact that they use common colors can be misleading. Try this :

plt.contour(xi, yi, F, colors='red')
plt.contour(xi, yi, F1, colors='blue')
plt.show()

一个独立的示例:

import matplotlib.pyplot as plt
import numpy as np

X = np.linspace(0, 1, 10)
Y = np.linspace(0, 1, 10)

x,y = np.meshgrid(X,Y)

f1 = np.cos(x*y)
f2 = x-y

plt.contour(x,y,f2,colors='red')
plt.contour(x,y,f1,colors='blue')
plt.show()

这篇关于同一图中的几个等高线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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