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

improve plot #284

Merged
merged 1 commit into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions chainer_chemistry/saliency/visualizer/image_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def __init__(self, logger=None):

def visualize(self, saliency, image=None, save_filepath=None,
scaler=abs_max_scaler, title='Image saliency map',
cmap=cm.jet, alpha=0.5, show_colorbar=False):
cmap=cm.jet, alpha=0.5, show_colorbar=False,
bbox_inches='tight'):
"""Visualize or save `saliency` of image.

Args:
Expand All @@ -41,7 +42,7 @@ def visualize(self, saliency, image=None, save_filepath=None,
alpha (float): alpha value of fore ground saliency. This option is
used only when `image` is set.
show_colorbar (bool): show colorbar in plot or not.

bbox_inches (str or Bbox or None): used for `plt.savefig` option.
"""
# --- type check ---
if saliency.ndim == 3:
Expand Down Expand Up @@ -95,6 +96,6 @@ def visualize(self, saliency, image=None, save_filepath=None,
if show_colorbar:
fig.colorbar(im)
if save_filepath:
plt.savefig(save_filepath)
plt.savefig(save_filepath, bbox_inches=bbox_inches)
else:
plt.show()
5 changes: 3 additions & 2 deletions chainer_chemistry/saliency/visualizer/table_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TableVisualizer(BaseVisualizer):
def visualize(self, saliency, feature_names=None, save_filepath=None,
num_visualize=-1, scaler=abs_max_scaler,
sort='descending', title='Feature Importance', color='b',
xlabel='Importance'):
xlabel='Importance', bbox_inches='tight'):
"""Visualize or save `saliency` in bar plot.

Args:
Expand All @@ -30,6 +30,7 @@ def visualize(self, saliency, feature_names=None, save_filepath=None,
title (str or None): title of plot
color (str): color of bar in plot
xlabel (str): x label legend
bbox_inches (str or Bbox or None): used for `plt.savefig` option.

"""
# --- type check ---
Expand Down Expand Up @@ -78,6 +79,6 @@ def visualize(self, saliency, feature_names=None, save_filepath=None,
plt.yticks(range(num_visualize), feature_names)
plt.xlabel(xlabel)
if save_filepath:
plt.savefig(save_filepath)
plt.savefig(save_filepath, bbox_inches=bbox_inches)
else:
plt.show()