错误如下:AttributeError: 'str' object has no attribute 'items'
代码如下:
import numpy as np
import matplotlib.pyplot as plt
import xlrd
import math
path = r'C:\Users\chuchao\Desktop\test\math\data.xls'
sheetname = 'Sheet1'
workbook = xlrd.open_workbook(path)
sheet = workbook.sheet_by_name(sheetname)
#print(sheet.nrows, ' ', sheet.ncols)
data = []
for i in range(sheet.nrows):
data.append(sheet.row_values(i))
print(data)
x = np.linspace(0, math.ceil(sheet.ncols), sheet.ncols)
y = np.linspace(0, math.ceil(sheet.nrows), sheet.nrows)
X, Y = np.meshgrid(x, y)
Height = data
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
cir1 = plt.Circle((30.3 * 1000 / 38.2, 89.8 * 1000 / 38.2), radius = 10000 / 38.2) #第一个参数为圆心坐标,第二个为半径 #第三个为透明度(0-1)
cir2 = plt.Circle((66.0 * 1000 / 38.2, 84.7 * 1000 / 38.2), radius = 10000 / 38.2)
cir3 = plt.Circle((98.4 * 1000 / 38.2, 76.7 * 1000 / 38.2), radius = 10000 / 38.2)
cir4 = plt.Circle((73.7 * 1000 / 38.2, 61.0 * 1000 / 38.2), radius = 10000 / 38.2)
cir5 = plt.Circle((57.9 * 1000 / 38.2, 47.6 * 1000 / 38.2), radius = 10000 / 38.2)
cir6 = plt.Circle((86.8 * 1000 / 38.2, 22.0 * 1000 / 38.2), radius = 10000 / 38.2)
cir7 = plt.Circle((93.6 * 1000 / 38.2, 48.8 * 1000 / 38.2), radius = 10000 / 38.2)
plt.contourf(X, Y, Height, 10, alpha = 0.6, cmap = plt.cm.hot)
plt.contour(X, Y, Height, 10, colors = 'black', linewidth = 0.5)
plt.clabel(plt.contour(X, Y, Height, 10, colors = 'black', linewidth = 0.5), inline = True, fontsize = 10)
ax.add_patch(cir1)
ax.add_patch(cir2)
ax.add_patch(cir3)
ax.add_patch(cir4)
ax.add_patch(cir5)
ax.add_patch(cir6)
ax.add_patch(cir7)
plt.axis('scaled')
plt.axis('equal')
plt.show()