Search code examples
matplotlibplotdeep-learningcustomizationshap

How to customize matplotlib plots using gcf() or gca()?


I am using a package called shap which has a integrated plot function. However i want to adjust some things like the labels, legend, coloring, size etc.

apparently due to the developer thats possible via using plt.gcf().

I call the plot like this, this will give a figure object but i am not sure how to use it:

fig = shap.summary_plot(shap_values_DT, data_train,color=plt.get_cmap("tab10"), show=False)
ax = plt.subplot()

enter image description here

UPDATE / SOLUTION Finally i got everything adjusted as i wanted it by doing the following:

shap.summary_plot(shap_values_DT, data_train, color=plt.get_cmap("tab10"), show=False)
fig = plt.gcf()
fig.set_figheight(12)
fig.set_figwidth(14)
ax = plt.gca()
ax.set_xlabel(r'durchschnittliche SHAP Werte $\vert\sigma_{ij}\vert$', fontsize=16)
ax.set_ylabel('Inputparameter', fontsize=16)
ylabels = string_latexer([tick.get_text() for tick in ax.get_yticklabels()])
ax.set_yticklabels(ylabels)
leg = ax.legend()
for l in leg.get_texts(): l.set_text(l.get_text().replace('Class', 'Klasse'))
plt.show()

enter image description here


Solution

  • Finally i got everything adjusted as i wanted it by doing the following:

    shap.summary_plot(shap_values_DT, data_train, color=plt.get_cmap("tab10"), show=False)
    fig = plt.gcf()
    fig.set_figheight(12)
    fig.set_figwidth(14)
    ax = plt.gca()
    ax.set_xlabel(r'durchschnittliche SHAP Werte $\vert\sigma_{ij}\vert$', fontsize=16)
    ax.set_ylabel('Inputparameter', fontsize=16)
    ylabels = string_latexer([tick.get_text() for tick in ax.get_yticklabels()])
    ax.set_yticklabels(ylabels)
    leg = ax.legend()
    for l in leg.get_texts(): l.set_text(l.get_text().replace('Class', 'Klasse'))
    plt.show()
    

    enter image description here