繁体   English   中英

如何在 matplotlib quadmesh 中更改 colorbar label

[英]How to change colorbar label in matplotlib quadmesh

我有一个 xarray DataArray,其坐标间隔不均匀,如下所示:

print(da)

<xarray.DataArray 'Sa' (y: 679, x: 87)>
array([[1.      , 0.677667, 0.658552, ..., 0.583562, 0.443248, 0.366353],
       [0.799933, 0.929478, 1.      , ..., 0.386675, 0.316399, 0.284364],
       [0.952748, 0.844993, 0.793359, ..., 0.724242, 0.554958, 0.295785],
       ...,
       [0.983343, 0.98983 , 1.      , ..., 0.601416, 0.592084, 0.586747],
       [0.997548, 1.      , 0.99682 , ..., 0.596712, 0.591876, 0.58533 ],
       [0.995427, 1.      , 0.990861, ..., 0.581317, 0.588433, 0.585797]])
Coordinates:
  * y        (y) float64 -0.1274 -0.1224 -0.1174 -0.1124 ... 3.253 3.258 3.263
  * x        (x) float64 4.002 3.971 3.961 3.95 3.94 ... 3.407 3.401 3.396 3.39

我可以使用DataArray.plot方法对其进行 plot 并获得 matplotlib QuadMesh object:

da.plot()

在此处输入图像描述

我不知道如何更改自动设置为 DataAray 名称"Sa"的颜色栏 label。

作为二维数据的 plot 在 xarray 中使用pcolormesh启动绘图,您可以设置颜色条 label 提供传给 matplotlib 的cbar_kwargs字典:

da.plot(cbar_kwargs={'label': "This is the new label"})

有关可能的 arguments 的完整列表,请参阅matplotlib 文档中的关键字

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM