1

(我问过在 MATLAB 中也问过同样的问题

我想覆盖例如seismic-cmapped contourf-plot (或pcolor)与grayscale contour-plot,但是当我添加后者时,它也会更改以前的颜色图。如何解决这个问题?

4

1 回答 1

4

这个答案几乎完全取自轮廓演示示例

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()

你最终会得到这个情节:

两个色标

于 2014-12-11T12:35:03.577 回答