在子图之间共享等高线图属性

发布于 2024-08-08 19:42:11 字数 467 浏览 2 评论 0原文

我正在并排绘制几个等高线图,以可视化某些函数的时间演变。我希望每个轮廓的值和颜色在所有子图之间共享,但是每次添加新的子图时,都会重新计算轮廓值(如下图所示),因此它们之间的任何比较都是没有意义的。

带颜色条的等高线图 http ://www.inf.utfsm.cl/~rbonvall/colorbar-and-contour-plots.png

我尝试过手动设置 cmapcolorbar< 的不同组合每个子图实例上的 /code> 和 axes 属性,但没有成功。如何在所有子图之间共享等高线图属性?换句话说,如何为所有子图获得相同的颜色条?

I'm plotting several contour plots side by side for visualizing the time evolution of certain function. I want each contour's value and color to be shared between all subplots, but each time I add a new subplot, the contour values are recomputed (as shown in the image below), so any comparison between them is meaningless.

Contour plots with colorbars http://www.inf.utfsm.cl/~rbonvall/colorbar-and-contour-plots.png

I've tried setting manually different combinations of cmap, colorbar and axes attributes on each subplot instance, without success. How can I share the contour plot attributes between all the subplots? In other words, how to get the same colorbar for all subplots?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

徒留西风 2024-08-15 19:42:11

您可以直接指定等值线图中要使用的等值线值。这是一个示例:

“替代文本”

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-1.2, 1.2, .025)
y = np.arange(-1.2, 1.2, .025)
X, Y = np.meshgrid(x, y)
Z = np.cos(X)*np.cos(Y)
Z = Z*Z

plt.subplot(1,2,1)
CS = plt.contour(X, Y, Z)   # set levels automatically
plt.clabel(CS, inline=1, fontsize=10)
plt.subplot(1,2,2)
CS = plt.contour(X, Y, Z-.1, CS.levels)  # set levels as previous levels
plt.clabel(CS, inline=1, fontsize=10)
plt.show()

You can directly specify the contour values to be used in the contour plot. Here's an example:

alt text

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-1.2, 1.2, .025)
y = np.arange(-1.2, 1.2, .025)
X, Y = np.meshgrid(x, y)
Z = np.cos(X)*np.cos(Y)
Z = Z*Z

plt.subplot(1,2,1)
CS = plt.contour(X, Y, Z)   # set levels automatically
plt.clabel(CS, inline=1, fontsize=10)
plt.subplot(1,2,2)
CS = plt.contour(X, Y, Z-.1, CS.levels)  # set levels as previous levels
plt.clabel(CS, inline=1, fontsize=10)
plt.show()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文