matplotlib:为什么等高线和contou的结果不一致

2024-10-02 22:31:38 发布

您现在位置:Python中文网/ 问答频道 /正文

为什么matplotlib的contour和{}会产生不一致的结果?在

我有一些数据想用matplotlib basemap工具箱的赤平投影绘制在地图上。当我用填充轮廓绘制数据时,contourf,我看到了下面的第一张图片。注意北美大部分地区的红色(正值)。当我将contourf更改为contour时,我看到了下面的第二张图片。注意北美中部的蓝色条纹(负值)。在

带蓝色的contour结果是数据中的实际内容,因此我期望看到的是什么。结果并不是我所期望的。是什么原因造成的?在

{a2}

下面复制python代码。这里data是一个大小为(73144)的float32ndarray,lon是一个大小为(144,)的float32ndarray,lat是一个大小为(73,)的float32ndarray。data是在经纬度为2.5度的网格上计算的NCEP温度异常数据。在

import numpy as np
import matplotlib.pyplot as plt

# ...read data, lon, and lat from file here...

m = Basemap(width=10000000,height=6000000,
        resolution='l',projection='stere',\
        lat_ts=50,lat_0=50,lon_0=253)
m.drawcoastlines()
lon2d, lat2d = np.meshgrid(lon,lat)
x, y = m(lon2d,lat2d)
mymap = plt.contourf(x,y,data,levels=np.arange(17)-8,cmap=plt.cm.bwr)
plt.colorbar(mymap,orientation='vertical',shrink=0.75)
plt.show()

更新:柱面图生成填充轮廓所需的结果: enter image description here


Tags: 数据importdatamatplotlibnp绘制图片plt