首页 > 解决方案 > 如何正确处理彩条?

问题描述

在阅读了文档后,我一直在为 matplotlib 理解何时使用 fig/ax/plt 而苦苦挣扎。现在,我只想给颜色条一个标题,但我总是不知道要在哪些对象中存储所有内容以及以后使用哪些对象。

我能得到一个一般性的解释来避免走这条路吗?有没有更合适的方法我应该将热图传递给 ax,这样我就不会再遇到这个麻烦了?

activity = 'Downstairs'
layer = 1

seg_x = create_segments_and_labels(df[df['ActivityEncoded']==mapping[activity]],TIME_PERIODS,STEP_DISTANCE,LABEL)[0]
get_layer_output = K.function([model_m.layers[0].input],[model_m.layers[layer].output])
layer_output = get_layer_output([seg_x])[0]

try: 
    ax = sns.heatmap(layer_output[0].transpose())
except:
    ax = sns.heatmap(layer_output.transpose())


ax.set_xlabel('Kernels',fontsize=30)
ax.set_yticks(range(0,len(layer_output[0][0])+1,10))
ax.set_yticklabels(range(0,len(layer_output[0][0])+1,10))
ax.set_xticks(range(0,len(layer_output[0])+1,5))
ax.set_xticklabels(range(0,len(layer_output[0])+1,5))
ax.set_ylabel('Filters',fontsize=30)
ax.xaxis.labelpad = 10
ax.set_title('Filters vs. Kernels\n (Layer=' + model_m.layers[layer].name + ')(Activity=' + activity + ')',fontsize=35)

#I'd like to add text to the colorbar but I don't know how to get it here. Fig/plt/ax.colorbar() don't work

clb = fig.colorbar()

错误:colorbar() 缺少 1 个必需的位置参数:'mappable'

标签: pythonmatplotlibcolorbar

解决方案


推荐阅读