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

[FIX] Grid2D plot when step is a tuple #446

Merged
merged 1 commit into from Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions pulse2percept/utils/geometry.py
Expand Up @@ -169,6 +169,13 @@ def plot(self, transform=None, style='hull', autoscale=True,
zorder = ZORDER['background']

x, y = self.x, self.y
try:
# Step might be a tuple:
x_step, y_step = self.step
except TypeError:
x_step = self.step
y_step = self.step

if style.lower() == 'cell':
# Show a polygon for every grid cell that we are simulating:
if self.type == 'hexagonal':
Expand All @@ -177,10 +184,10 @@ def plot(self, transform=None, style='hull', autoscale=True,
for xret, yret in zip(x.ravel(), y.ravel()):
# Outlines of the cell are given by (x,y) and the step size:
vertices = np.array([
[xret - self.step / 2, yret - self.step / 2],
[xret - self.step / 2, yret + self.step / 2],
[xret + self.step / 2, yret + self.step / 2],
[xret + self.step / 2, yret - self.step / 2],
[xret - x_step / 2, yret - y_step / 2],
[xret - x_step / 2, yret + y_step / 2],
[xret + x_step / 2, yret + y_step / 2],
[xret + x_step / 2, yret - y_step / 2],
])
if transform is not None:
vertices = np.array(transform(*vertices.T)).T
Expand Down
3 changes: 3 additions & 0 deletions pulse2percept/utils/tests/test_geometry.py
Expand Up @@ -97,6 +97,9 @@ def test_Grid2D_plot():
ax = grid.plot(style='cell')
ax = grid.plot(style='scatter')

# Step might be a tuple (smoke test):
Grid2D((-5, 5), (-5, 5), step=(0.5, 1)).plot(style='cell')


class ValidCoordTransform(VisualFieldMap):

Expand Down