-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support custom colors in plots #62
Comments
Custom colors are available in force plots already #37 . For summary plots, there's a color argument, but it doesn't appear to be doing much. In the code it looks like it's for coloring the scatter plots in summary plots, but I tinkered with some values and it didn't change the plot. This could be a great addition, since in business work, often plots are colored with the business' colors in mind. |
Great point. The summary plots need to be updated to support other color scales. |
Aside from custom colors/maps, it was brought up in #58 that supporting these per feature might be a requirement. Easy to do - just nailing down the API is important. |
I was going to open a new issue related to this, but I'll just add it in a comment. I see that force_plot accepts the arg plot_cmap, which can be used to change the colors. My suggestion is to put that in the shap docs as an option, or since it's implemented in iml, document it there, then put a link to the details in the shap readme. I've shown the shap plots to a few people and they were a bit confused because the default magenta in summary_plot (meaning high value for the actual feature) is the same as the magenta bars in the single-instance force_plot (meaning positive shap value for that feature). They definitely look pretty but maybe the force plot should use a different default. :) |
@vaughnkoch Thanks for the suggestion! I have been slowly working on getting read-the-docs working for shap, so I'll try and work this into that. |
Yeah it would be good to have a plot_cmap option for the summary plot as well. I can't promise when I can get to that though. |
from here you can choose the color pallet you want |
@ferdous150439 Yes, this was added in 0.26.0 release, I believe. |
Here's an example if you want to specify a color per class: from matplotlib import colors as plt_colors
import numpy as np
import shap
# class names
classes = ['r', 'g', 'b']
# set RGB tuple per class
colors = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
# get class ordering from shap values
class_inds = np.argsort([-np.abs(shap_values[i]).mean() for i in range(len(shap_values))])
# create listed colormap
cmap = plt_colors.ListedColormap(np.array(colors)[class_inds])
# plot
shap.summary_plot(shap_values, features, feature_names, color=cmap, class_names=classes) I suggest allowing users to use a dictionary like |
@JamesTownend sounds like it would be a nice feature! PRs are welcome :) |
Hi guy, still not working for me, any ideas? this is the data set i am playing with: https://www.kaggle.com/dansbecker/hospital-readmissions
|
@ra161 I see that your list of two colors has one same tuple of RGB code: |
@ibuda yea just saw that also. The issue is the colors don't seem to change no matter the cmap:
Only trying to plot this for 1 class hence slicing into shap_values[1]. Would love a way to get the colors changeing with a cmap |
I have been trying to create my 2 gradient color map doing the following, but nothing has changed:
Any ideas ? |
I've been needing a custom colormap for shap.summary_plot() for a while now and came up with this workaround solution using the set_cmap() function of figure's artists:
|
Still not working for me:
|
Addresses shap#62 for summary plots.
Any recent update on this ? |
I'm doing classification and I'm still not able to change the colors, here is my code :
seems like the argument color in method |
@slundberg We want to compare different XAI methods for image classification and want to have similar color scales for all of them. Your feedback would be highly appreciated! |
In case somebody wondered how to use import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.colors import ListedColormap
my_cmap = ListedColormap(sns.color_palette('rocket').as_hex()[:5])
shap.summary_plot(shap_values, features=features, color=my_cmap, class_names=['1', '2', '3', '4', '5'])
plt.show() |
|
* port the 1e-8 fix to waterfall_legacy * update baseline waterfall plots
this worked for me! 💯 |
Red and blue are nice, but it's generally a requirement in business work to be able to change the color (including specific to a client).
This definitely applies to the summary_plot, and may apply to others. Easy fixes, if anyone's interested.
The text was updated successfully, but these errors were encountered: