I am trying to generate a contour plot with line numbers inside! I used plt.contourf to draw the contour plot and plt.clabel to draw the lines on my contour plot! The numbers in my plot are incorrect as shown in the figure!
Contour plot with lines and wrong numbers
Contour lines with correct numbers
X = Data3.iloc[:,0].drop_duplicates()
Y = Data3.iloc[:,1].drop_duplicates()
Z = Data3.pivot('Battery capacity (kWh)','Solar capacity (kW)', 'Diesel electricity generation
(kWh)')
plt.figure(figsize=(7, 5))
contours = plt.contourf(X, Y, Z, 10, cmap='viridis', alpha=0.8 )
plt.colorbar();
plt.clabel(contours, inline = True, fontsize=8, fmt='%d', colors = 'black')
plt.xlabel('Solar Capacity (kW)',fontsize = 13) # x-axis label with fontsize 12
plt.ylabel('Battery Capacity (kWh)',fontsize = 12) # y-axis label with fontsize 12
plt.title('Diesel Electricity Generation (% of total generation)',fontsize = 15)
plt.scatter(x=(233*1.83*0.16), y=250, color = 'r', marker='o')
I also used plt.contour and plt.clabel, the numbers were placed correctly! How can I draw lines on plt.contourf without mixing the line numbers?