我想将该图中的小数位从 3 减少到 1。我找不到任何方法来做到这一点。我尝试将列表中的级别定义为整数,但需要浮点数,并且似乎会自动出现小数点后 3 位。帮助。
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(1, 1, 1, aspect='equal')
plt.yticks(fontsize=16)
plt.xticks(fontsize=16)
modelmap = flopy.plot.ModelMap(model=mf)
quadmesh = modelmap.plot_ibound()
linecollection = modelmap.plot_grid(alpha=0.01)
#set up array to show wetland location
if alt_coords!=None: #plot the wetland if altcoords provided
wl_arr=np.zeros([mf.nrow,mf.ncol])
for coord in alt_coords:
wl_arr[coord[1],coord[2]]=1.0
quadmesh=modelmap.plot_array(wl_arr, color='w', alpha=0.1)
riv = modelmap.plot_bc('RIV', color='b', plotAll=True)
quadmesh = modelmap.plot_bc('WEL', kper=1, plotAll=True)
levels=np.arange(40, 100, 3)
contour_set = modelmap.contour_array(hds, levels, colors='b')
plt.clabel(contour_set, inline=1, fontsize=14)
Run Code Online (Sandbox Code Playgroud)
matplotlib.pyplot.clabel接受一个fmt参数。该参数允许您设置标签格式。因此,您可以指定此参数并查看它是否有效:plt.clabel(contour_set, inline=1, fmt='%1.1f', fontsize=14)