matplotlib的颜色图

编程入门 行业动态 更新时间:2024-10-28 04:29:33
本文介绍了matplotlib的颜色图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是python的新手,安装后,我已经完成了使用matplotlib绘制3d数据的工作.可悲的是,我唯一不知道如何完成的是颜色部分.我的图像仅显示表面,而根本不使用颜色条.这是我的代码.

I'm new to python and after installing it I've accomplished to plot my 3d data using matplotlib. Sadly the only thing I don't know how to get done is the color part. My image just shows the surface but doesn't use the color bar at all. Here is my code.

from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib.ticker import LinearLocator, FormatStrFormatter import matplotlib.pyplot as plt from matplotlib.mlab import griddata import numpy as np fig = plt.figure() ax = fig.gca(projection='3d') data = np.genfromtxt('Uizq.txt') x = data[:,0] y = data[:,1] z = data[:,2] xi = np.linspace(min(x), max(x)) yi = np.linspace(min(y), max(y)) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('U') X, Y = np.meshgrid(xi, yi) Z = griddata(x, y, z, xi, yi) ax.set_zlim3d(np.min(Z), np.max(Z)) surf = ax.plot_surface(X, Y, Z, rstride=2, cstride=2, cmap=cm.jet, linewidth=0.5, antialiased=False) fig.colorbar(surf, shrink=0.5, aspect=5) plt.show()

您显然可以看到它全是蓝色,我想使用完整的 cm.jet 光谱将颜色与"U"相关联.这可能是一个非常白痴的问题,如果您翻了个白眼,请对不起.

you can obviously see that it is all blue, and I want to relate the color with "U" using the full cm.jet spectrum. This might be a very noob question, so sorry if you rolled your eyes.

推荐答案

添加行

surf.set_clim([np.min(Z),np.max(Z)])

在添加颜色栏之前.

3D绘图似乎没有考虑遮罩,因此您在数据中包含了 NaN ,这会混淆自动颜色限制.

It seems that the 3D plotting does not take into account the masking, so you are including NaN in the data, which confuses the automatic color limits.

更多推荐

matplotlib的颜色图

本文发布于:2023-06-08 23:39:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/591050.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   matplotlib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!