Я пытаюсь сделать эту тепловую карту, используя следующий код:
breast_cancer = load_breast_cancer()
data = breast_cancer.data
features = breast_cancer.feature_names
df = pd.DataFrame(data, columns = features)
df_small = df.iloc[:,:6]
correlation_mat = df_small.corr()
#Create color pallete:
def NonLinCdict(steps, hexcol_array):
cdict = {'red': (), 'green': (), 'blue': ()}
for s, hexcol in zip(steps, hexcol_array):
rgb =matplotlib.colors.hex2color(hexcol)
cdict['red'] = cdict['red'] + ((s, rgb[0], rgb[0]),)
cdict['green'] = cdict['green'] + ((s, rgb[1], rgb[1]),)
cdict['blue'] = cdict['blue'] + ((s, rgb[2], rgb[2]),)
return cdict
#https://www.december.com/html/spec/colorshades.html
hc = ['#e5e5ff', '#acacdf', '#7272bf', '#39399f', '#000080','#344152']
th = [0, 0.2, 0.4, 0.6, 0.8,1]
cdict = NonLinCdict(th, hc)
cm = matplotlib.colors.LinearSegmentedColormap('test', cdict)
#plot correlation matrix:
plt.figure(figsize = (12,10))
ax=sns.heatmap(correlation_mat,center=0, linewidths=.2, annot = True,cmap=cm , vmin=-1, vmax=1,cbar=True)
plt.title("title", y=-1.5,fontsize = 18)
plt.xlabel("X_parameters",fontsize = 18)
plt.ylabel("Y_paramaters",fontsize = 18)
ax.tick_params(axis='both', which='both', length=0)
#choose colors
#change ticks size and remove colorbar ticks
#ad saving option
#change to 5 portions instead of four (0.2,0.4,0.6,0.8)
plt.show()
У меня есть две нерешенных проблемы: 1- Как убрать отметки шкалы палитры? 2- Как установить интервалы цвета и цветовой полосы на (-1, -0,8, -0,6, -0,4, -0,2,0,0,2,0,6,0,8,1), если vmax = 1 и v min = - 1).
вот мой текущий результат на прилагаемой фотографии. Результат