From 42b3f6ffbcaf54b9b2ad870005dc3f70f4e7377e Mon Sep 17 00:00:00 2001 From: suvendu266 Date: Fri, 6 Dec 2024 12:59:59 +0100 Subject: [PATCH 1/2] we are closing the issue 8 and 25 --- amep/plot.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ amep/utils.py | 5 +++++ 2 files changed, 58 insertions(+) diff --git a/amep/plot.py b/amep/plot.py index 1e01628..13036df 100644 --- a/amep/plot.py +++ b/amep/plot.py @@ -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) diff --git a/amep/utils.py b/amep/utils.py index 2e4b33b..2cc57c0 100644 --- a/amep/utils.py +++ b/amep/utils.py @@ -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 From 782c6d31046448842dec5783e241e5ba5c2095c7 Mon Sep 17 00:00:00 2001 From: suvendu266 Date: Fri, 6 Dec 2024 15:45:49 +0100 Subject: [PATCH 2/2] a simple example added for the draw_arrow and qmin comments --- amep/plot.py | 11 +++++++++++ amep/spatialcor.py | 2 ++ amep/utils.py | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/amep/plot.py b/amep/plot.py index 13036df..cf53177 100644 --- a/amep/plot.py +++ b/amep/plot.py @@ -1866,6 +1866,17 @@ def draw_arrow(fig, x: float, y: float, dx: float, dy: float, **kwargs): Examples -------- + 1) simple example + >>> fig, axs = amep.plot.new(figsize=(3, 3)) + >>> x=0.2 + >>> y=0.2 + >>> dx=0.5 + >>> dy=0.5 + >>> amep.plot.draw_arrow(fig, x, y, dx, dy, color="blue", alpha=0.8, width=0.05, head_width=0.1, head_length=0.03) + + + + 2) advanced example >>> import amep >>> import numpy as np >>> start_points = [(0.2, 0.2), (0.4, 0.4), (0.6, 0.6), (0.8, 0.8)] diff --git a/amep/spatialcor.py b/amep/spatialcor.py index b75a19f..ef23a90 100644 --- a/amep/spatialcor.py +++ b/amep/spatialcor.py @@ -1379,6 +1379,8 @@ def sfiso( where :math:`N` is the number of particles [1]_. Mode 'fft' only works in 2D!!! + + Here, qmin is set to the default value 2*np.pi/boxsize. References ---------- diff --git a/amep/utils.py b/amep/utils.py index 2cc57c0..d9234a2 100644 --- a/amep/utils.py +++ b/amep/utils.py @@ -1346,8 +1346,8 @@ def domain_length( 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. + Here, qmin is set to the default value 2*np.pi/boxsize. Please check also the 2D isotropic static structure factor (amep.spatialcor.sfiso). + Examples --------