我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用matplotlib.cm.bwr()。
def plot(self, loc, dataX, dataY): delta = 0.01 x_min, x_max = dataX[:, 0].min() - .5, dataX[:, 0].max() + .5 y_min, y_max = dataX[:, 1].min() - .5, dataX[:, 1].max() + .5 xx, yy = np.meshgrid(np.linspace(x_min, x_max, 20), np.linspace(y_min, y_max, 20)) xxFlat = xx.ravel() yyFlat = yy.ravel() gridX = np.vstack((xxFlat, yyFlat)).T y0 = np.full(gridX.shape[0], 0.5).reshape((-1, 1)) yn, = self.sess.run([self.yn_], feed_dict={self.x_: gridX, self.y0_: y0}) yn = np.clip(yn, 0., 1.) zz = 1.-yn.reshape(xx.shape) fig, ax = plt.subplots(1, 1, figsize=(5,5)) plt.axis([x_min, x_max, y_min, y_max]) fig.tight_layout() fig.subplots_adjust(bottom=0,top=1,left=0,right=1) ax.set_autoscale_on(False) ax.grid(False) v = np.linspace(0.0, 1.0, 10, endpoint=True) plt.contourf(xx, yy, zz, v, alpha=0.5, cmap=cm.bwr) # plt.colorbar() yFlat = dataY.ravel() plt.scatter(dataX[yFlat == 0, 0], dataX[yFlat == 0, 1], color='red') plt.scatter(dataX[yFlat == 1, 0], dataX[yFlat == 1, 1], color='blue') for ext in ['png', 'pdf']: plt.savefig('{}.{}'.format(loc, ext)) plt.close()