-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #806 Whislt #806 was meant to address why no Matplotlib image was generated and tested/compared to a target image when plotting without axes or colorbar I discovered this was because the image is saved with `Images.save_array_figure()`. This in turn uses [`matplotlib.pyplot.imsave()`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imsave.html) to save the image and the test was using [`skimage.io.imread()`](https://scikit-image.org/docs/stable/api/skimage.io.html#skimage.io.imread) to read the image back as an array and test the `np.sum()` and `img.shape`. We no longer need to save arrays nor images as readable arrays (see #804 / #802) and so the need to save the image in this manner seemed redudant. The `Images.save_figure()` already has logic which excludes the axes and scale bars (see lines 321 of current changeset). Further the logic for deciding what to save within `Image.plot_and_save()` seemed overly complicated and if `Images.save_array_figure()` were being called `Images.plot_and_save()` did not return a `fig` (Matplotlib Image) that could be saved and tested using `pytest-mpl` extension. To this end I have... 1. Removed `Images.save_array_figure()`. 2. Tweaked the plotting options under `Images.savefig()` starting at line 321 to use a [tight layout](https://matplotlib.org/2.0.2/users/tight_layout_guide.html) which ensures there is no border (see note below). 3. Simplified the logic in `Images.plot_and_save()` controlling whether images are saved so that `ValueError` are raised if `Images.savefig == False` or `if Images.image_set in ["all", "core"] or self.core_set:` evaluates to `False`. Ensures images are explicitly closed to reduce memory usage. 4. Added tests for the raising of `ValueError` exceptions in `Images.plot_and_save()` 5. Tidied up some test names to be consistent (resulted in image name change). 6. Tidied up passing of `plotting_config` into these tests. 7. Added a `pytest-mpl` test for `test_plot_and_save_no_axes_no_colorbar()`, adding the target image as required by #806 Note on Borders The image generated by `pytest-mpl` against which comparisons are made _does_ have a border because it is saving the returned `fig` object itself. The actual generated image doesn't have a border (manual checks have been made).
- Loading branch information
Showing
4 changed files
with
47 additions
and
51 deletions.
There are no files selected for viewing
File renamed without changes
Binary file modified
BIN
-384 KB
(30%)
tests/resources/img/test_plot_and_save_no_axes_no_colorbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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