使用mplot3d缩放Facecolor的颜色图 [英] Scaled colormap of facecolors with mplot3d

查看:95
本文介绍了使用mplot3d缩放Facecolor的颜色图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的任务,应该有一个简单的解决方案,但是我已经尝试了好几天了.我会说具体一点.

I have a simple task that should have a simple solution, but I have been trying for days now. I try to be specific.

  • 我尝试使用matplotlib的mplot3d和plot_surface绘制表面. 当我绘制数据集"z"的表面并尝试将颜色图缩放到某个最大值时,我将"vmax"属性更改为该值.效果很好.

  • I try to plot a surface using matplotlib's mplot3d and plot_surface. When I plot the surface of a dataset 'z' and try to scale the colormap to a certain maximum value I change the 'vmax' property to this value. That works great.

当我尝试绘制一个数据集(z)的表面并使用第二个数据集(fc)的面色时,这也很好用.

When I try to plot a surface of one dataset (z) and use the facecolors of a second dataset (fc), this also works fine.

当我要缩放facecolors的颜色图时,vmax属性被facecolors值所覆盖.因此,Vmax无效(attempt1).线条也消失了,但这是另一个问题.

When I want to scale the colormap of the facecolors, the vmax property is overruled by the facecolors values. Vmax therefore has no effect (attempt1). The lines also disappeared, but that's another issue.

尝试更改facecolor数据集(fc)的值也没有达到预期的效果(attempt2).

Also trying to change the values of the facecolor dataset (fc) did not have the desired effect (attempt2).

我尝试获得具有缩放的颜色图的图形(如下面的缩放"图所示),但缩放到的是面色,而不是z值.

I try to get a figure with a scaled colormap (as in the figure 'scaled' below) but scaled to the facecolors, and not the z-values.

下面的代码就是我现在拥有的,结果看起来像这样:

The code below is what I have now, and the results look like this:

有人知道我在这里想念的吗?任何想法都表示赞赏!

Does anyone know what I am missing here? Any thoughts are appreciated!

import pylab as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

plt.ion()

# creating dataset
profile = np.arange(20)**2
z = profile.repeat(20).reshape(20,20)
fc= np.rot90(z.copy())

x = np.arange(z.shape[0])
y = np.arange(z.shape[1])
X, Y = np.meshgrid(x,y)

# plotting
vmax = 100
fig = plt.figure()
ax = fig.add_subplot(1,4,1, projection='3d', azim=210)
ax.plot_surface(X,Y,z, cmap=plt.cm.jet, cstride=1, rstride=1)
ax.set_title('normal')

ax = fig.add_subplot(1,4,2, projection='3d', azim=210)
ax.plot_surface(X,Y,z, cmap=plt.cm.jet, cstride=1, rstride=1, vmax=vmax)
ax.set_title('scaled')

ax = fig.add_subplot(1,4,3, projection='3d', azim=210)
ax.plot_surface(X,Y,z, facecolors=plt.cm.jet(fc), cstride=1, rstride=1, vmax=vmax)
ax.set_title('rotated (attempt1)')

ax = fig.add_subplot(1,4,4, projection='3d', azim=210)
fc[fc> vmax] = vmax
ax.plot_surface(X,Y,z, facecolors=plt.cm.jet(fc), cstride=1, rstride=1)
ax.set_title('rotated (attempt2)')

推荐答案

一种-肮脏的-解决方案是重新缩放裁剪的脸色,使最大值等于高度图的最大值(除了基本上建议的值之外)尝试2):

One - dirty - solution would be to rescale the clipped facecolors such that the maximum is equal to the maximum of your height map (in addition to basically what you suggested as attempt 2):

ax.plot_surface(X,Y,z, facecolors=plt.cm.jet(np.clip(fc,0,vmax)*np.max(z)/vmax), cstride=1, rstride=1, vmax=vmax)

这是否能为您提供所需的结果?

Does this give the result you are looking for?

这篇关于使用mplot3d缩放Facecolor的颜色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆