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
Plot overlay images #2599
Plot overlay images #2599
Conversation
I've added a basic test for plotting but I can't seem to get pytest to create the plot when running with --mpl-generate-path (it is creating others but not the one I've added). Perhaps someone could help me with this? |
Codecov Report
@@ Coverage Diff @@
## RELEASE_next_minor #2599 +/- ##
======================================================
+ Coverage 75.89% 76.48% +0.58%
======================================================
Files 202 202
Lines 29656 29802 +146
Branches 6455 6517 +62
======================================================
+ Hits 22507 22793 +286
+ Misses 5330 5197 -133
+ Partials 1819 1812 -7
Continue to review full report at Codecov.
|
I am wondering if it would make sense to incorporate it in
Please check that your version of matplotlib and freetype match the one defined in |
It can be useful to create a testing evironment in the same way that @ericpre's nice github actions do it: From the base hyperspy path, create and update a conda environment like this: conda env create -f conda_environment.yml # install hyperspy dependencies
conda env update -f conda_environment_dev.yml # install hyperspy testing dependencies
conda activate test_env # test_env is the name set in the yml file
pip install -e . # install hyperspy as a develop install @ericpre would it be a good idea to add the above to the docs? As an alternative to the first code block in the "Running Tests" section? |
I'm happy to incorporate it in to I'll have another go setting up a testing environment. |
Maybe a link to https://hyperspy.readthedocs.io/en/latest/user_guide/install.html#installation-in-a-anaconda-minconda-distribution? |
Here is an example: A few suggestions:
|
Encompassed the overlay utility in to the plot_images function and removed plot_overlay_images. Added the ability to click on the legend to turn off/on different images. Updated the cmap so the background is always black. Updated to take the legend names from the function's label input.
I think I've covered almost all of these now, thanks for suggestions @ericpre ! It's incorporated in to I'm not quite sure how to get rid of whitespace around the image, I think it may work in some cases but not all now. If anyone has any suggestions that would be very helpful. |
One way to do it would be: import numpy as np
import matplotlib.pyplot as plt
pixel_number = 500
data = np.arange(pixel_number**2).reshape(pixel_number, pixel_number)
shape = data.shape
dpi = 100
sampling_factor = 10 # adjust the width of single pixel
fig = plt.figure(figsize=[sampling_factor*v/dpi for v in shape], dpi=dpi)
ax = fig.add_axes([0, 0, 1, 1])
ax.axis('off')
ax.imshow(data, cmap='gray')
plt.savefig('test.png') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in good shape, I made suggestions to simplify the code.
Added vmin and vmax use. Removed use of legend argument. Changed figure generation so will have no whitespace. Changed default alphas and colors arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is getting very nice! I have left a few minor comments. The vmax
works well but not the vmin
because of the transparency applied to the minimum value.
Added pixsize_factor argument. Removed use of rcParams['image.cmap']. Changed colormap definition for overlays. Removed overlay_title argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few last details in comments.
What do you want to do for the vmin
issue? The simplest would be to ignore it and add a warning to the logger that vmin
is ignored.
The test failures should be fixed in #2603. |
I think you're right. I've just ignored it. In most cases where this is used (elemental maps), it's probably not going to be an issue. All else should be sorted now. |
Description of the change
This PR implements a function to provide overlayed images of different colours (for example, for elemental maps). It aims to resolve issue #1812 .
Further improvements could be made by using ipywidgets to select colours and alpha values but this just adds initial functionality.
Progress of the PR
CHANGES.rst
(if appropriate),Minimal example of the bug fix or the new feature