Skip to content
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

added optional background color for darkmode #745

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lime/explanation.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def show_in_notebook(self,
labels=None,
predict_proba=True,
show_predicted_value=True,
col_b = "#ffffff",
**kwargs):
"""Shows html explanation in ipython notebook.

Expand All @@ -196,13 +197,15 @@ def show_in_notebook(self,
display(HTML(self.as_html(labels=labels,
predict_proba=predict_proba,
show_predicted_value=show_predicted_value,
col_b=col_b,
**kwargs)))

def save_to_file(self,
file_path,
labels=None,
predict_proba=True,
show_predicted_value=True,
col_b = "#ffffff",
**kwargs):
"""Saves html explanation to file. .

Expand All @@ -216,13 +219,15 @@ def save_to_file(self,
file_.write(self.as_html(labels=labels,
predict_proba=predict_proba,
show_predicted_value=show_predicted_value,
col_b=col_b,
**kwargs))
file_.close()

def as_html(self,
labels=None,
predict_proba=True,
show_predicted_value=True,
col_b='#ffffff',
**kwargs):
"""Returns the explanation as an html page.

Expand All @@ -235,6 +240,7 @@ def as_html(self,
for the top classes. (only used for classification)
show_predicted_value: if true, add barchart with expected value
(only used for regression)
col_b: background color for the plot
kwargs: keyword arguments, passed to domain_mapper

Returns:
Expand All @@ -251,9 +257,18 @@ def jsonize(x):
bundle = open(os.path.join(this_dir, 'bundle.js'),
encoding="utf8").read()

out = u'''<html>
out = u'''<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF8">
<head><script>%s </script></head><body>''' % bundle
<style>
.lime {{
background-color: {0} !important; /* Change this to your preferred color */
}}
</style>
<script>{1} </script>
</head>
<body>'''.format(col_b, bundle)
random_id = id_generator(size=15, random_state=check_random_state(self.random_state))
out += u'''
<div class="lime top_div" id="top_div%s"></div>
Expand Down