【问题标题】:Oceanographic plotting in PythonPython中的海洋学绘图
【发布时间】:2016-09-05 14:34:40
【问题描述】:

我正在绘制图表。而且我希望图“U_velocity”和“U_shear_velocity”的颜色条上的值范围从-0.3到0.3。此外,对于 U 和 V 剪切速度图,我试图以小时为单位将 x ax 的范围从 0 到 12.5,但没有任何效果,取而代之的是我对速度的含义。我该怎么做,请帮助我。

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()

【问题讨论】:

  • 你能不能试试minimal reproducible example?我们可以尝试运行一些东西吗?或者告诉我们您收到的错误信息。我们无法绘制您的图表,因为我们没有您的数据文件。另外,请在您的问题中包含您当前绘图输出的图片
  • @Praveen 我试图下载这个数据文件,但我找不到如何直接下载。然后我尝试通过链接下载它,但该网站不允许我引用链接,因为它可能是垃圾邮件。

标签: python python-2.7 python-3.x numpy matplotlib


【解决方案1】:

这不是一个用一堵代码墙来回答的简单问题,参考未知文件result.nc 和几个不相关且相当具体的问题。以下可能会有所帮助:

可以通过将vmin=-0.3vmax=0.3 传递给pcolormesh 来设置颜色条范围。

要限制时间范围,您可以使用数组切片(例如time[time<12.5], u[time<12.5])。

对于您的数据,速度肯定只是speed = np.sqrt(np.power(u,2) + np.power(v,2)

如果您需要进一步的帮助,请提供一个最小、完整且可验证的示例。

【讨论】:

  • 非常感谢您的大力帮助。我会尽力做你写的。在另一种情况下,我尝试下载此数据文件,但我找不到如何直接执行此操作。然后我尝试通过链接下载它,但该网站不允许我引用链接,因为它可能是垃圾邮件。
猜你喜欢
  • 1970-01-01
  • 2019-04-16
  • 2013-07-05
  • 2020-05-08
  • 2022-09-26
  • 1970-01-01
  • 2018-03-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多