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

we are closing the issue 8 and 25 #92

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions amep/plot.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please simplify the example?
for example:

  1. plot a linear function from 0 to 10.
  2. add one annotation arrow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please modify the first example to a minimum working example.

  1. import amep
  2. as specified before, plot a linear function from 0 to 10.
  3. add one annotation arrow.

Original file line number Diff line number Diff line change
Expand Up @@ -1829,3 +1829,56 @@ def voronoi(axs: mpl.axes.Axes, vor: Voronoi, **kwargs):
else:
raise Exception("amep.plot.voronoi: Cannot plot 3d data.")
plt.show()

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

This function uses the `FancyArrow` class to draw an arrow on a Matplotlib figure
at a specified position, with a given displacement. The arrow is added directly
to the figure's artist list.

Parameters
----------
fig : matplotlib.figure.Figure
The Matplotlib figure object on which the arrow will be drawn.
x : float
The starting x-coordinate of the arrow, in figure coordinates (0 to 1).
y : float
The starting y-coordinate of the arrow, in figure coordinates (0 to 1).
dx : float
The horizontal displacement (change in x) of the arrow, in figure coordinates.
dy : float
The vertical displacement (change in y) of the arrow, in figure coordinates.
**kwargs : dict, optional
Additional keyword arguments passed to `matplotlib.patches.FancyArrow`,
such as `color`, `width`, `head_width`, and `head_length`.

Returns
-------
None
This function modifies the figure in-place by adding the arrow as an artist.

Notes
-----
The arrow's position and size are specified in figure coordinates. Figure
coordinates range from 0 to 1, where (0, 0) represents the bottom-left corner
and (1, 1) represents the top-right corner of the figure.

Examples
--------
>>> 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))
>>> 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)
>>> plt.show()

See Also
--------
matplotlib.patches.FancyArrow : Used to create the arrow object.
"""

arrow = FancyArrow(x, y, dx, dy, transform=fig.transFigure, length_includes_head=True, **kwargs)
fig.add_artist(arrow)
5 changes: 5 additions & 0 deletions amep/utils.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Notes are for the users to read. Not internal development-comments. Could you please adapt the notes?
secondly, please add an appropriate comment to the sqiso function for the qmin.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the qmin is not set to this default value in domain_length. please correct the comment. (it is expected that the q values are "correct" already)

Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,11 @@ def domain_length(
l: float
Domain length as inverse expectation value of q.

Notes
-------
Here, qmin=2*np.pi/boxsize, therefore we do not need to modify anything within this function.
In the future, it would be interesting to set a qmin where we are calculating the structure factor itself.

Examples
--------
>>> import amep
Expand Down
Loading