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

FRQ: Plot arrows for annotations. #25

Open
hechtprojects opened this issue May 7, 2024 · 2 comments · May be fixed by #92
Open

FRQ: Plot arrows for annotations. #25

hechtprojects opened this issue May 7, 2024 · 2 comments · May be fixed by #92
Assignees
Labels
good first issue Good for newcomers module: plot new feature New feature release: minor Issues that need to be addressed in a minor release status: to do Issues that someone needs to work on

Comments

@hechtprojects
Copy link
Member

Proposed new feature or change:

Add the following method (+ docstring + example) to amep.plot:

def draw_arrow(fig, x, y, dx, dy, **kwargs):
    arrow = FancyArrow(x, y, dx, dy, transform=fig.transFigure, length_includes_head=True, **kwargs)
    fig.add_artist(arrow)

This allows to draw an arrow that points from (x, y) to (x+dx, y+dy), which is useful for annotation purposes.

@hechtprojects hechtprojects added new feature New feature good first issue Good for newcomers release: minor Issues that need to be addressed in a minor release status: to do Issues that someone needs to work on module: plot labels May 7, 2024
@hechtprojects hechtprojects added this to the release v1.1.0 milestone Jun 4, 2024
@suvendu266 suvendu266 self-assigned this Dec 2, 2024
@suvendu266
Copy link

suvendu266 commented Dec 5, 2024

I have tested this issue using a simple script
import amep
import numpy as np
start_points = [(0.2, 0.2), (0.4, 0.4), (0.6, 0.6), (0.8, 0.8)]
displacements = [(0.1, 0.05), (-0.05, 0.1), (0.05, -0.05), (-0.1, -0.1)]

fig, axs = amep.plot.new(figsize=(3, 3))

Draw arrows for each starting point and displacement

for (x, y), (dx, dy) in zip(start_points, displacements):
amep.plot.draw_arrow(fig, x, y, dx, dy, color="blue", alpha=0.8, width=0.005, head_width=0.02, head_length=0.03)

#I have add the following code inside the plot.py

Define the draw_arrow function

def draw_arrow(fig, x, y, dx, dy, **kwargs):
"""
Draws an arrow on a Matplotlib figure.

Parameters:
    fig (Figure): Matplotlib figure object.
    x (float): Starting x-coordinate of the arrow (in figure coordinates).
    y (float): Starting y-coordinate of the arrow (in figure coordinates).
    dx (float): Displacement along x-axis.
    dy (float): Displacement along y-axis.
    **kwargs: Additional arguments passed to FancyArrow.
"""
arrow = FancyArrow(x, y, dx, dy, transform=fig.transFigure, length_includes_head=True, **kwargs)
fig.add_artist(arrow)  

@suvendu266
Copy link

I think that this issue is completed.

@hechtprojects hechtprojects linked a pull request Dec 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers module: plot new feature New feature release: minor Issues that need to be addressed in a minor release status: to do Issues that someone needs to work on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants