Skip to content

Commit

Permalink
Merge pull request #284 from corochann/bbox_inches_option
Browse files Browse the repository at this point in the history
improve plot
  • Loading branch information
mottodora committed Dec 12, 2018
2 parents 8e1a578 + 8b8eaf0 commit 2962246
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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()

0 comments on commit 2962246

Please sign in to comment.