python bar3d color_使用matplotlib对3D颤抖函数进行颜色映射

I have created a lovely 3D displacement vector field in python using Matplotlib and I am happy with the results. However, visually it is not very east to see the magnitude of the displacements only the direction. Is there a way in python that I could use a colour scale for the arrows so that the magnitude of the displacements is clearer/more visible.

This is what I have so far

#%% Import Libraries

from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plt

import numpy as np

#%% Import tsv file of results

path = 'W:/Scott/Continuous_DIC_Results/A35_L7-8_500x500x1000/'

name = 'Z=-5,200,-20,20,spm100'

results = np.loadtxt(path+name+'.tsv', dtype=float, comments='#', delimiter=None, converters=None, skiprows=1, usecols=(1,2,3,4,5,6), unpack=False, ndmin=0)

Z,Y,X = results[:,0], results[:,1],results[:,2]

dz,dy,dx = results[:,3],results[:,4],results[:,5]

#%% Plot Displacement Field

fig = plt.figure()

ax = fig.gca(projection='3d')

ax.quiver(X, Y, Z, dx, dy, dz, # data

length=20, # arrow length

color='Tomato' # arrow colour

)

ax.set_title('3D Vector Field') # title

ax.view_init(elev=18, azim=30) # camera elevation and angle

ax.dist=8 # camera distance

plt.show()

解决方案

You have to calculate wind speed (or another array which you use as magnitude) then add this array to quiver function:

import matplotlib as mpl

import matplotlib.pyplot as plt

from numpy import arange,meshgrid,sqrt

u,v = arange(-50,51,10),arange(-50,51,10)

u,v = meshgrid(u,v)

M = sqrt(u*u+v*v) # magnitude

x,y = u,v

qq=plt.quiver(x,y,u,v,M,cmap=plt.cm.jet)

plt.colorbar(qq, cmap=plt.cm.jet)

plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值