我在画曲线图。我希望在图"U_velocity“和"U_shear_velocity”的颜色条上的值范围从-0.3到0.3。此外,我试图使x x的范围在小时内从0到12.5,对于U和V剪切速度图,但都不起作用,取而代之的是我有速度的含义。我该怎么做,请帮帮我。
from netCDF4 import *
import matplotlib as mp
import numpy as np
#import matplotlib.pyplot as plt
import pylab as plt
#%%
file = "/home/vlad/Desktop/task/Untitled Folder/result.nc"
ncdata = Dataset(file, 'r')
u = np.squeeze(ncdata.variables['u'][:])
v = np.squeeze(ncdata.variables['v'][:])
z = np.squeeze(ncdata.variables['z'][:])
time = ncdata.variables['time'][:]/3600
ncdata.close()
u_mean = np.mean(u[0:100,:],0)
z_mean = np.mean(z[0:100,:],0)
v_mean = np.mean(v[0:100,:],0)
u_mean_10 = u[900:1000,:]
v_mean_10 = v[900:1000,:]
z_10 = np.mean(z[900:1000,:],0)
time_10 = time[900:1000] - time[900]
T = len(time_10)
L = len(z_10)
fig = plt.figure(6)
plt.pcolormesh(time_10,z_10,u_mean_10.T)
plt.xlim([0, time_10[-1]])
fig.suptitle('U_velocity', fontsize=25)
plt.xlabel('time', fontsize=20)
plt.ylabel('depth(m)', fontsize=20)
plt.colorbar()
plt.show()
shear_u_mean_10 = np.zeros([T,L])
for t in range(T):
for i in range(L-1):
tmp=(u_mean_10[t, i+1]-u_mean_10[t, i])/(z_10[i+1]-z_10[i])
tmp_depth = 0.5 * (z_10[i+1]+z_10[i])
shear_u_mean_10[t,i] = tmp
fig = plt.figure(10)
plt.pcolormesh(time_10/3600,z_10, shear_u_mean_10.T)
plt.xlim([0, time_10[-1]/3600])
plt.colorbar()
#plt.ylim([-30, -25])
fig.suptitle('U_shear velocity', fontsize=25)
plt.xlabel('time', fontsize=20)
plt.ylabel('depth(m)', fontsize=20)
plt.show()
shear_v_mean_10 = np.zeros([T,L])
for t in range(T):
for i in range(L-1):
tmp=(v_mean_10[t, i+1]-v_mean_10[t, i])/(z_10[i+1]-z_10[i])
tmp_depth = 0.5 * (z_10[i+1]+z_10[i])
shear_v_mean_10[t,i] = tmp
fig = plt.figure(11)
plt.pcolormesh(time_10/3600,z_10, shear_v_mean_10.T)
plt.xlim([0, time_10[-1]/3600])
plt.colorbar()
#plt.ylim([-30, -25])
fig.suptitle('V_shear velocity', fontsize=25)
plt.xlabel('time', fontsize=20)
plt.ylabel('depth(m)', fontsize=20)
plt.show()
fig = plt.figure(7)
plt.pcolormesh(time_10,z_10,v_mean_10.T)
plt.xlim([0, time_10[-1]])
fig.suptitle('V_velocity', fontsize=25)
plt.xlabel('time', fontsize=20)
plt.ylabel('depth(m)', fontsize=20)
plt.colorbar()
plt.show()发布于 2016-09-06 00:23:42
这不是一个容易回答的问题,因为有一堵墙的代码,引用未知的文件result.nc和几个不相关的和相当具体的问题。以下内容可能会有所帮助:
可以通过将vmin=-0.3和vmax=0.3传递给pcolormesh来设置色带范围。
要限制时间范围,可以使用数组切片(例如time[time<12.5], u[time<12.5])。
对于你的数据来说,速度当然就是speed = np.sqrt(np.power(u,2) + np.power(v,2)
如果您需要进一步的帮助,请提供一个最小的、完整的和可验证的示例。
https://stackoverflow.com/questions/39332868
复制相似问题