本文介绍了如何用不同颜色的轮廓图覆盖controuf图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(我问过)
例如,我想叠加一个地震
限制的 contourf
-图(或 pcolor
)和灰色
比例尺轮廓
-图,但是当我添加后者还会更改以前的颜色图。
I'd like to overlay for example a seismic
-cmapped contourf
-plot (or pcolor
) with a gray
scale contour
-plot, but when I add the latter it also changes the previous colormap. How can this be fixed?
推荐答案
此答案几乎完全取自:
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab # for setting up the data
import matplotlib.pyplot as plt
# set up example data:
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)
levels = 10
# plot the filled contour
# using a colormap (jet)
CF = plt.contourf(Z, levels,
extent=(-3,3,-2,2),cmap=cm.jet)
# plot the contour lines
# using gray scale
CL = plt.contour(Z, levels,
linewidths=2,
extent=(-3,3,-2,2),cmap=cm.gray)
# plot color bars for both contours (filled and lines)
CB = plt.colorbar(CL, extend='both')
CBI = plt.colorbar(CF, orientation='horizontal')
# Plotting the second colorbar makes
# the original colorbar look a bit out of place,
# so let's improve its position.
l,b,w,h = plt.gca().get_position().bounds
ll,bb,ww,hh = CB.ax.get_position().bounds
CB.ax.set_position([ll, b, ww, h])
plt.show()
您将得到以下情节:
这篇关于如何用不同颜色的轮廓图覆盖controuf图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!