如何在matplotlib 3d轴ax.plot_surface()中设置颜色?

时间:2019-09-26 18:38:31

标签: matplotlib

如何在3d曲面图中设置颜色?默认情况下,Z值用于创建颜色,但是对相同的信息进行两次编码,因此是冗余的。我想在颜色维度中嵌入其他信息。

%matplotlib notebook

import seaborn as sns
sns.set_context('paper')
from mpl_toolkits.mplot3d import Axes3D  # noqa: F401 unused import

import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np


fig = plt.figure(figsize=(8,8), dpi=300)
ax = fig.gca(projection='3d')

# Make data.
X = peaks2d.index
Y = peaks2d.columns
X, Y = np.meshgrid(X, Y)
Z = peaks2d.fillna(0).values.T

# Plot the surface.
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
                       linewidth=0, antialiased=False)
xlabel('Retention Time')
ylabel('m/z')
title('Peak Selection')

enter image description here

我尝试使用color=(Z==0).astype(int),但是没有用。它返回

  

ValueError:无效的RGBA参数:array([[0,0,0,...,0,0,0],          [0,0,0,...,0,0,0],          [0,0,0,...,0,0,0],          ...,          [0,0,0,...,0,0,0],          [0,0,0,...,0,0,0],          [0,0,0,...,0,0,0]])

如果定义了颜色图,该函数应该能够将整数映射到颜色,但是显然这没有实现?

0 个答案:

没有答案