我有氧气的网格 netcdf 文件(时间、深度、经度、纬度)。我需要如下所示的剖面图。我想做的是平均一系列纬度和经度,然后将大量时间与氧气深度(在给定范围内)作为填充图。使用下面的命令,我绘制了填充图。
fig, ax = plt.subplots(figsize=(12, 8))
time_sub = var_sel.sel(time=slice('2000-01-01 00:00', '2018-12-31 12:00'))
oxy_boxmean_3 = time_sub.sel(depth=slice(0,800),longitude=slice(75.4,76.5),
latitude=slice(8,9)).mean(dim=['longitude','latitude'])
oxy_boxmean_3.T.plot()
plt.gca().invert_yaxis()
结果图附在下面。
但现在我想自定义颜色条位置和距绘图的距离(图形和颜色条之间有一些空白,我需要减少它)。我尝试了 imshow()
和 plt.colorbar()
,但它不起作用(可能是由于我使用上述代码对数据进行子集化的方式所致)。
谁能帮我做到这一点?我是Python初学者。非常感谢任何帮助。
I have gridded netcdf file (time, depth, lon, lat) of oxygen. I need a profile plot as shown below. What I'm trying to do is average a range of latitudes and longitudes, then lot time vs. oxygen depth (at a given range) as a fill plot. Using the commands below, I plotted a fill plot.
fig, ax = plt.subplots(figsize=(12, 8))
time_sub = var_sel.sel(time=slice('2000-01-01 00:00', '2018-12-31 12:00'))
oxy_boxmean_3 = time_sub.sel(depth=slice(0,800),longitude=slice(75.4,76.5),
latitude=slice(8,9)).mean(dim=['longitude','latitude'])
oxy_boxmean_3.T.plot()
plt.gca().invert_yaxis()
The resultant figure is attached below.
But now I want to customize the colorbar position and distance from plot (there is some white space between the figure and colorbar, I need to reduce it). I tried imshow()
and plt.colorbar()
, but it is not working (probably due to the way I subsetted my data using the above code).
Can anyone help me to do that?. I am beginner in python. Any help is much appreciated.
发布评论