Skip to content

Commit

Permalink
Add plot_field function that shows effect of a linear transformation on
Browse files Browse the repository at this point in the history
a square field of points
  • Loading branch information
jmshea committed Dec 20, 2023
1 parent a3a693d commit f7399e4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
4 changes: 3 additions & 1 deletion plotvec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
All files in the package are distributed under the MIT License
'''

__version__ = '1.5.1'
__version__ = '1.6.0'

from .plotvec import plotvec, plotvecR
from .transforms import plot_field
52 changes: 52 additions & 0 deletions plotvec/transforms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

def plot_field (matrix=np.eye(2), field_width=3, point_spacing=0.5,
preserve_axes=True, colormap='plasma'):

''' Plot the outputs of a linear transform on a square field of points
Generates a uniformly spaced field of points in a 2-D square,
applies the linear transform to the points, and plots the
field of output points
Parameters
----------
matrix : ndarray
2D matrix that specifies the linear transform
field_width: number
size of input point field in each dimension
point_spacing: number
spacing between field points in each dimension
preserve_axes: boolean
keep limits of output axes same as input space
colormap: string
Matplotlib colormap
'''


cmap = mpl.colormaps[colormap]

xs = np.arange(-field_width, field_width + point_spacing,
point_spacing)
ys = xs

for x in xs:
for y in ys:
angle = np.arctan2(y, x)
if angle < 0:
angle += 2*np.pi
rgba = cmap(angle / (2 * np.pi) )
out = matrix @ np.array([x, y])
plt.scatter(out[0], out[1], 2, color=rgba)

ax = plt.gca()
ax.axis('equal')
if preserve_axes:
plt.xlim(-field_width, field_width)
plt.ylim(-field_width, field_width)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["flit_core >=3.2,<4"]
requires = ["flit_core >=3.2,<4", "matplotlib>3", "numpy>1"]
build-backend = "flit_core.buildapi"

[tool.flit.metadata]
Expand Down

0 comments on commit f7399e4

Please sign in to comment.