所以基本上我有一个X数组和一个NumPy数组,它们代表了一个谱图的相同数据。以下代码用于绘制非常清晰的Xarrray (它将频谱图剪切到最大值以上)
plt.figure(figsize=(3,5))
data_slice = data['__xarray_dataarray_variable__'].sel(slices=41625.0)
max_value = np.log(data.sel(slices=slice(67.5, 5.999625e+05)).max(xr.ALL_DIMS)['__xarray_dataarray_variable__'].values)
xr.ufuncs.log(data_slice).plot(cmap='magma', vmin=0, vmax = max_value*.7)在这里,我们有Xarray的->数据,我们选择其中的一部分,然后使用xf.plot绘制它。类似地,我有一个形状为( 256,12333)的Numpy数组,其中12333表示时间戳的数量,256表示频率段。我如何告诉我的绘图数据,直到我需要绘图的东西中的最大值?我想这样做是为了得到一个放大的频谱图图像,这样我就可以清楚地看到声音。到目前为止,我一直在绘制我的numpy数组,如下所示-
plt.imshow(data[:, 30:100])发布于 2020-07-03 05:05:44
为什么不直接把它转换成DataArray呢?
然后您将利用xarray的绘图实用程序。
特别是,您将能够使用robust=True kwarg,它将自动从动态颜色范围中删除潜在的异常值。
还可以使用"long_name"属性进行自动标记。
freq_count, time_count = 256, 12333
data = np.random.randn(freq_count, time_count)
da = xr.DataArray(
dims=("frequency", "time"),
data=data,
coords=dict(
frequency=np.arange(freq_count),
time=np.arange(time_count),
),
attrs=dict(long_name="Spectral intensity over time")
)绘图:
fig, axes = plt.subplots(ncols=2)
da.plot.imshow(robust=False, ax=axes[0])
da.plot.imshow(robust=True, ax=axes[1])
plt.show()robust=False图和robust=True图的比较:

https://stackoverflow.com/questions/62459356
复制相似问题