Open CSSFrancis opened 9 months ago
I started working on adding point and text markers: https://github.com/viljarjf/pyxem/commit/819b477a529a51aa62d2ccd6597bf72090999c26
Something like MarkerCombinations
would be nice for annotated reflections, my current implementation just re-uses the coordinates for point and text markers.
One issue I ran into is the fact that the width of the text markers, (and as such their positions, since they are centered) is calculated before latex is compiled. This means that negative miller indices make the annotations completely miss the reflection, as $\bar{1}$
is much wider than the compiled $\bar{1}$.
@viljarjf Have you tried setting usetex =True
? Basically the TextsColletion
will go through and predict the bounding box and then center based on that. I think I tried to test this when I wrote it but honestly it's been a bit so I'm not sure.
One issue I ran into is the fact that the width of the text markers, (and as such their positions, since they are centered) is calculated before latex is compiled. This means that negative miller indices make the annotations completely miss the reflection, as
$\bar{1}$
is much wider than the compiled 1¯.
@viljarjf: can you provide a minimum example?
@ericpre Certainly!
from hyperspy import api as hs
import numpy as np
data = np.arange(100).reshape((2, 2, 5, 5))
signal = hs.signals.Signal2D(data)
signal.plot()
offset = [[3, 3], ]
raw_text = "$\\bar{1}$"
point_marker = hs.plot.markers.Points(offset)
text_marker = hs.plot.markers.Texts(offset, texts=[raw_text,], color="red")
signal.add_marker([point_marker, text_marker])
As @CSSFrancis pointed out, I just needed usetex=True
. It took much longer to display, but the position is correct:
Thank you @viljarjf for the clear example! I opened https://github.com/hyperspy/hyperspy/issues/3315 to track the issue/not forget about it.
Is your feature request related to a problem? Please describe. I think that the orientation mapping code could use some really nice plotting improvements. The new markers in HyperSpy really allow us to do some fun (and slightly crazy) things because of how responsive they now are.
The easiest example is something like plotting the fit match lazily. Using the new class defined in #1018 it is easy to make some function like:
A bit more wild of an example would be to embed something like this into a plot.
You could do something like:
Describe the solution you'd like @viljarjf I wonder if this is something that you would be comfortable trying to do? I can provide more guidance on how I would accomplish this but for the most part it shouldn't be terribly difficult/ I think it would be useful.
@ericpre It might also be a good idea to add something like this as an example in hyperspy. It's a bit ridiculous of a use of markers but we might want to think about making things like
MarkerCombinations
to handle some case where you want to combine two markers. At least inmatplotlib
an example of this is with the stream plot function