My test excel file hai 3 columns: x, y, z
x,y,z
0,0,1
0,1,1
0,2,1
0,3,1
0,4,1
0,5,1
0,6,1
0,7,1
0,8,1
0,9,1
1,0,1
1,1,1
1,2,1
1,3,1
1,4,1
1,5,1
1,6,1
1,7,1
1,8,1
1,9,1
2,0,1
2,1,1
2,2,1
2,3,1
2,4,1
2,5,1
2,6,1
2,7,1
2,8,1
2,9,1
3,0,1
3,1,1
3,2,1
3,3,1
3,4,1
3,5,1
3,6,1
3,7,1
3,8,1
3,9,1
4,0,1
4,1,1
4,2,1
4,3,1
4,4,1
4,5,1
4,6,1
4,7,1
4,8,1
4,9,1
5,0,1
5,1,1
5,2,1
5,3,1
5,4,1
5,5,9
5,6,1
5,7,1
5,8,1
5,9,1
6,0,1
The code used for this heatmap is :
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import interp2d
import pandas as pd
import matplotlib as mpl
excel_data_df = pd.read_excel('test.xlsx')
X= excel_data_df['x'].tolist()
Y= excel_data_df['y'].tolist()
Z= excel_data_df['z'].tolist()
x_list = np.array(X)
y_list = np.array(Y)
z_list = np.array(Z)
f = interp2d(x_list,y_list,z_list,kind="linear")
x_coords = np.arange(min(x_list),max(x_list)+1)
y_coords = np.arange(min(y_list),max(y_list)+1)
z = f(x_coords,y_coords)
fig = plt.imshow(z,
extent=[min(x_list),max(x_list),min(y_list),max(y_list)],
origin="lower", interpolation='bicubic', cmap= 'jet')
fig.axes.set_autoscale_on(False)
plt.scatter(x_list,y_list,400, facecolors='none')
plt.xlabel('X Values', fontsize = 15)
plt.ylabel('Y Values', fontsize = 15)
plt.title('Heatmap', fontsize = 20)
plt.tight_layout()
plt.show()
Run Error Message:
RuntimeWarning: No more knots can be added because the additional knot would coincide with an old one. Probable cause: s too small or too large a weight to an inaccurate data point. (fp>s) kx,ky=1,1 nx,ny=11,11 m=100 fp=46.439909 s=0.000000 warnings.warn(RuntimeWarning(_iermess2[ierm][0] + _mess))
The above code works perfectly fine if I use random values of z
. But when I consider all the values of z
as 1 except at (5,5)
which is considered 9
. The plot gives false alarms as you can see in the figure below.
It shows dark blue areas which indicate 0
values.
I want to keep this code executable. It should only take input of an excel file. Kindly suggest changes accordingly.