Skip to content

Commit

Permalink
Merge pull request #25 from BiAPoL/jo-mueller/fix-axis-limits
Browse files Browse the repository at this point in the history
Fix axis limits not set correctly upon redrawing
  • Loading branch information
zoccoler authored Jul 26, 2024
2 parents d1ebeb4 + 6b5e431 commit 41f58dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/biaplotter/_tests/test_artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def on_color_indices_changed(color_indices):
assert np.all(colors[0] == scatter.categorical_colormap(0))
assert np.all(colors[50] == scatter.categorical_colormap(2))

# Test axis limits
x_margin = 0.05 * (np.max(data[:, 0]) - np.min(data[:, 0]))
y_margin = 0.05 * (np.max(data[:, 1]) - np.min(data[:, 1]))
assert np.isclose(ax.get_xlim(), (np.min(data[:, 0]) - x_margin, np.max(data[:, 0]) + x_margin)).all()
assert np.isclose(ax.get_ylim(), (np.min(data[:, 1]) - y_margin, np.max(data[:, 1]) + y_margin)).all()

# Test size property
scatter.size = 5.0
assert scatter.size == 5.0
Expand Down
6 changes: 6 additions & 0 deletions src/biaplotter/artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ def data(self, value: np.ndarray):
color_indices[color_indices_size:] = 0
self.color_indices = color_indices
self.size = 50

x_margin = 0.05 * (np.max(value[:, 0]) - np.min(value[:, 0]))
y_margin = 0.05 * (np.max(value[:, 1]) - np.min(value[:, 1]))
self.ax.set_xlim(np.min(value[:, 0]) - x_margin, np.max(value[:, 0]) + x_margin)
self.ax.set_ylim(np.min(value[:, 1]) - y_margin, np.max(value[:, 1]) + y_margin)

self.draw()

@property
Expand Down

0 comments on commit 41f58dd

Please sign in to comment.