如何减少matplotlib轮廓p中的小数位数

2024-09-28 16:19:11 发布

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

我想把这个图中的小数位数从3减到1。我找不到任何方法来做这个。我尝试过将列表中的级别定义为int,但浮点值是必需的,并且似乎自动升到小数点后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)

Tags: alphaplotfigpltarraycontourmfarr
1条回答
网友
1楼 · 发布于 2024-09-28 16:19:11

matplotlib.pyplot.clabel接受fmt参数。此参数允许您设置标签格式。所以,您可以指定这个参数,看看它是否有效:plt.clabel(contour_set, inline=1, fmt='%1.1f, fontsize=14)

相关问题 更多 >