绘图中的标记区域

时间:2019-08-07 18:27:03

标签: python-3.x matplotlib

您是否知道如何在生成的绘图中清楚地在绘图上显示每个区域的名称(“区域1”,“参考2”等)?

import numpy as np
from matplotlib import pyplot as plt

y = np.arange(0,15,.01)
x = np.arange(0,10,.01)

Y,X = np.meshgrid(y,x) 

maxf = np.zeros(shape = Y.shape)
maxf.fill(-9999.99) 


for i,x_ in enumerate(x):
    for j, y_ in enumerate(y):
        if y_<x_<5 or y_<5<x_:
            maxf[i,j] =3
        elif x_<5<=y_<(x_+5) or 5<=y_<x_:
            maxf[i,j] =1
        elif 5<x_<=y_<(x_+5) or x_<=y_<5:
            maxf[i,j] =2
        elif x_ == 5 and y_<5:
            maxf[i,j]=3
        elif x_ == 5 and y_>=5:
            maxf[i,j]=1
        elif y_ >= (5+x_):
            maxf[i,j]=4


plt.contourf(X,Y,maxf,[0,1,2,3,4])
plt.colorbar()
plt.show()

现在的结果如下图所示:

enter image description here

但是我需要这样的情节:

enter image description here

1 个答案:

答案 0 :(得分:0)

我能够通过使用ax.text来做到这一点。