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

Question: Get value from scalebar object? #60

Open
jazzlw opened this issue Feb 21, 2024 · 1 comment
Open

Question: Get value from scalebar object? #60

jazzlw opened this issue Feb 21, 2024 · 1 comment

Comments

@jazzlw
Copy link

jazzlw commented Feb 21, 2024

First, thanks for the great package!

I just ran into a use case that I hadn't before, and I'm wondering if there's a way to deal with it. I'm trying to get the scalebar value from a scalebar object created with length_fraction (and thus an automatically chosen value) so that I can use it in another place. Eg, in the below plot, I want to get the value of 25 or 25 m out so that I can use it. Is there a way to do this?

import matplotlib_scalebar.scalebar as scalebar
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot(np.arange(100))
scale_bar = mpu.add_traj_scalebar(ax, dx=1, length_fraction=0.3, location="lower right")

# How can I do this?
# scale_bar_value = scale_bar.
@habi
Copy link

habi commented Sep 6, 2024

I'd also like to do that, because I'm drawing arrows onto images with something like the code below.
The arrows are drawn onto images with highly different size, but all with a scale bar.

plt.gca().annotate('', xy=(x, y),
                       xytext=(x + horizontaldisplacement, y + verticaldisplacement),
                       arrowprops=dict(arrowstyle = '->',
                                       linestyle=linestyle,
                                       connectionstyle = 'arc3',
                                       color=color))

It would be cool if I could use the length_fraction chosen by matplotlib-scalebar to scale the horizontal and vertical displacement of the drawn arrow, making them all approximately the same length, independent of the wildly varying image size...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants