Repository navigation
Simplify and fix colour personalization - #830
Merged
milton-minervino merged 13 commits intoNov 16, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #830 +/- ##
===========================================
+ Coverage 86.18% 86.37% +0.18%
===========================================
Files 115 115
Lines 11859 11958 +99
Branches 2161 2176 +15
===========================================
+ Hits 10221 10329 +108
+ Misses 997 996 -1
+ Partials 641 633 -8
🚀 New features to boost your workflow:
|
milton-minervino
marked this pull request as ready for review
November 6, 2026 16:56
milton-minervino
requested review from
guerinclement and
guillaume-vignal
and removed request for
guillaume-vignal
November 6, 2026 16:56
guerinclement
approved these changes
Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #654.
Customising colours in the classical path had several bugs, and the accepted formats were narrow and inconsistent. This PR fixes the bugs and lets
colors_dicttake common colour formats, plotly scale names and partial overrides. The NLP plots go through the same resolver, and the report now follows the explainer's colours everywhere.The other request in #654, descriptive names instead of numeric keys such as
featureimp_bar: {"1": ...}, breaks existingcolors_dicts. It will come in a separate PR, with a deprecation period for the old keys.Bug fixes
define_stylelost state. It did not updatepalette_name, and each call dropped earlier overrides. Overrides now accumulate on the current colours. Passingpalette_namestarts again from that palette, and an unknown palette name leaves the current state unchanged.KeyError. Overriding one entry of a nested key, such as{"featureimp_bar": {"1": ...}}, replaced the whole dict. Nested dicts are now merged key by key.bluesor custom colours, it kept thedefaultscale and title colour.defaultpalette. They now get the explainer's resolved style.pred/truecolours ofreport_feature_distribution.interaction_discrete) in turn, the same on every call."viridis"was split into characters. Both are now handled.New
colors_dict:rgb(...),rgba(...), a hex code or a colour name, normalised torgb/rgbastrings.contrib_colorscale,confusion_matrix_colorscale,interaction_scale,feature_contributions_cumulative): a plotly scale name such as"RdBu"or"viridis_r". The name is sampled to the same number of stops as the default scale.interaction_discrete,compare_plot): a plotly qualitative palette name such as"Plotly"or"Set2".clusteringpalette key (active_fill,active_line,inactive_fill,inactive_line) replaces the colours hard-coded in the clustering plot. Its default values are the old ones, so the plot looks the same.Consistency(colors_dict=...)takes the same overrides asSmartExplainer.plot_distribution(hue_colors=...)sets the colour of each series.colors_dictnow only carries the style; a label → colour map passed throughcolors_dictstill works.Behaviour changes to note
ValueErrornaming the key and the accepted formats. Before, the value failed later inside plotly, or was ignored.Did you mean 'contrib_colorscale'?).report_confusion_matrixwarns. No plot reads this key, so setting it warns and points toconfusion_matrix_colorscale. It will be removed with the key renaming.contrib_colorscalealso colours the correlation plots, so a non-diverging scale there triggers a warning that the sign of correlations will no longer be visible.default, predictions turn gold and true values blue-grey, the other way round from before and the same as test/train in the other report blocks. Withblues, they are orange and blue.blues: it now uses thebluesscale.Implementation
shapash/style/style_utils.py: newmerge_palette,normalize_colors,resolve_colors,to_rgb_stringandparse_rgb.resolve_nlp_themenow usesresolve_colors.SmartExplainer.__init__,define_styleandConsistency: they all resolve colours through the same helper.shapash/report/blocks.py:plot._style_dict;_title_belowreplaces the two copies of the caption layout.plot_sentence_highlightandplot_backend_comparisonuse the sharedparse_rgbinstead of their own parser.sample_colorscale,plotly.colors.qualitative/diverging) exist in plotly 5.12.0, the current lower bound. Colour names are parsed by matplotlib, already a core dependency.Tests and docs
define_style, the report blocks, the distribution and clustering plots,Consistencyand the NLP plots;tests/unit_tests/explainer/test_smart_explainer_colors.py;developand on this branch withdefault,bluesand custom colours. Titles, axes, series colours and captions now follow the explainer's colours, and nothing is clipped.tuto-common02-colors.ipynblists the accepted formats, shows a partial override, and adds an Option 4 that uses a plotly scale name. The colour tutorials (common02,plot07) run without errors.