Skip to content
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
191e2d2
transfer common properties to the abstract artist class
zoccoler Apr 17, 2025
600b986
added list of mpl handles as properties to base class for `_scatter``
jo-mueller Apr 22, 2025
e5afe08
Replaced mpl handles in histogram by `_mpl_artists`
jo-mueller Apr 22, 2025
845ecce
moved plotting/modifying plot functionality for scatter in separate m…
jo-mueller Apr 22, 2025
da0351b
abstracted `data` setter and property into baseclass for scatter
jo-mueller Apr 22, 2025
c325a0d
made signals class signals
jo-mueller Apr 22, 2025
a5362ae
replaced function for statistical histogram with respective scipy fun…
jo-mueller Apr 22, 2025
25b8f95
imported scipy function for statistical histogram
jo-mueller Apr 22, 2025
1732574
modified `clear` function so that specific items can be removed from …
jo-mueller Apr 22, 2025
7739d75
pass x and y data specifically in scatter method
jo-mueller Apr 22, 2025
249c0ab
replaced margins by default value
jo-mueller Apr 22, 2025
5d2c451
made sure that key really exists when removing keys
jo-mueller Apr 22, 2025
cbd7213
introduced abstract color_indices setter method with `_draw_selection…
jo-mueller Apr 22, 2025
cc2c35f
simplified histogram to rgba conversion
jo-mueller Apr 22, 2025
294ceb2
moved data setter to abstract base
jo-mueller Apr 22, 2025
52c4e4b
overwrite plot margin for histogram
jo-mueller Apr 22, 2025
c12e304
introduce empty color_indices property to silence warning
jo-mueller Apr 22, 2025
5d167c2
replaced histogram `color_indices` property and setting by base class…
jo-mueller Apr 22, 2025
5e00095
moved base artist to separate file
jo-mueller Apr 22, 2025
513956f
reran notebooks
jo-mueller Apr 22, 2025
6daa68d
enforce `_draw_selection_on_plot` base class method
jo-mueller Apr 22, 2025
98289ea
moved normalization method dict to base class
jo-mueller Apr 22, 2025
4a9ea48
removed unused private method
jo-mueller Apr 22, 2025
93f6f7c
removed returned rgba values
jo-mueller Apr 22, 2025
aaf61a1
added base-class method `color_indices_to_rgba` method
jo-mueller Apr 22, 2025
9eeed91
fixed setting size property
jo-mueller Apr 22, 2025
06ec784
implemented `color_indices_to_rgba` method for histogram
jo-mueller Apr 22, 2025
0b5f11f
always pass color indices to rgba conversion function
jo-mueller Apr 23, 2025
b9a9c88
transpose histogram before conversion to rgba
jo-mueller Apr 23, 2025
571ce53
default overlay to True in color conversion function
jo-mueller Apr 23, 2025
d93cf3f
set axis aspect to equal
jo-mueller Apr 23, 2025
0f52e2a
made sure that scatter is in artists before setting alpha and size
jo-mueller Apr 23, 2025
5fa9717
also transpose base histogram and not just overlay
jo-mueller Apr 23, 2025
8d99958
fix scatter artist test
jo-mueller Apr 23, 2025
f3d79e4
removed statistical histogram calculation
jo-mueller Apr 23, 2025
8d68f78
reset color indices in histogram optionally (default True)
jo-mueller Apr 23, 2025
746cb48
do not force color indices reset on bin size change
jo-mueller Apr 23, 2025
31e7a32
fix histogram test assertion
jo-mueller Apr 23, 2025
9ad67f6
Merge branch 'main' into unify_properties
jo-mueller Apr 23, 2025
601eb28
Update src/biaplotter/artists_base.py
jo-mueller Apr 23, 2025
7692ab5
rename methods that set artist data and overlay with colors
zoccoler Apr 23, 2025
e23852a
Remove unused method
zoccoler Apr 23, 2025
c830735
update methods names and remove duplicated initialization of _overlay…
zoccoler Apr 23, 2025
86738c0
fix initializing internal variables and raise error on unknown normal…
zoccoler Apr 23, 2025
84b203d
Add reset method as a convenience to base artist and set categorical …
zoccoler Apr 23, 2025
748a34a
Add specific median method from numpy (lower by default)
zoccoler Apr 23, 2025
f7bdd83
renamed drawing functions to `refresh` and `colorize`
jo-mueller Apr 23, 2025
3038328
remove unused function `_get_rgba_colors`
jo-mueller Apr 23, 2025
c3884b4
moved normalization methods to base class and restructured usage in s…
jo-mueller Apr 23, 2025
2a86209
added default setting for linear norm working for categorical data
jo-mueller Apr 23, 2025
1eec23f
introduced `_get_normalization` function for histogram2d
jo-mueller Apr 23, 2025
7dc56f9
removed unused norm handling functions
jo-mueller Apr 23, 2025
9ef40f7
removed redundant function implementation
jo-mueller Apr 23, 2025
ca81404
escape norm/colormap missmatch
jo-mueller Apr 23, 2025
c314fc4
use refresh/colorize functions instead of property setters to trigger…
jo-mueller Apr 23, 2025
e5c3e5d
updated doc notebook
jo-mueller Apr 23, 2025
26ce100
fixed bad line break
jo-mueller Apr 23, 2025
04ffcc6
set aspect ratio to `auto` instead of `equal`
jo-mueller Apr 23, 2025
612e16a
pin minimal numpy version due to numpy.nanpercentile new syntax
zoccoler Apr 24, 2025
1af3402
Make histogram bins smaller than cmin transparent (keep previous beha…
zoccoler Apr 24, 2025
043c6cd
Add cmin as histogram property
zoccoler Apr 24, 2025
794f10a
Update histogram example notebook to show cmin and reset usage
zoccoler Apr 24, 2025
64e4b3d
Add cmin to docs
zoccoler Apr 24, 2025
43f7023
Update scatter example notebook to show reset method usage in the end
zoccoler Apr 24, 2025
3d411a9
Update plotter docs
zoccoler Apr 24, 2025
da39b00
bump version
zoccoler Apr 24, 2025
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
64 changes: 17 additions & 47 deletions docs/examples/histogram_artist_example.ipynb

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions docs/examples/scatter_artist_example.ipynb

Large diffs are not rendered by default.

58 changes: 9 additions & 49 deletions src/biaplotter/_tests/test_artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def on_color_indices_changed(color_indices):
assert scatter.color_indices.shape == (size,)

# Test scatter colors
colors = scatter._scatter.get_facecolors()
colors = scatter._mpl_artists['scatter'].get_facecolors()
assert np.all(colors[0] == scatter.overlay_colormap(0))
assert np.all(colors[50] == scatter.overlay_colormap(2))

Expand All @@ -69,27 +69,27 @@ def on_color_indices_changed(color_indices):
# Test size property
scatter.size = 5.0
assert scatter.size == 5.0
sizes = scatter._scatter.get_sizes()
sizes = scatter._mpl_artists['scatter'].get_sizes()
assert np.all(sizes == 5.0)

scatter.size = np.linspace(1, 10, size)
assert np.all(scatter.size == np.linspace(1, 10, size))
sizes = scatter._scatter.get_sizes()
sizes = scatter._mpl_artists['scatter'].get_sizes()
assert np.all(sizes == np.linspace(1, 10, size))

# Test size reset when new data is set
scatter.data = np.random.rand(size // 2, 2)
assert np.all(scatter.size == 50.0) # that's the default
sizes = scatter._scatter.get_sizes()
sizes = scatter._mpl_artists['scatter'].get_sizes()
assert np.all(sizes == 50.0)

# test alpha
scatter.alpha = 0.5
assert np.all(scatter._scatter.get_alpha() == 0.5)
assert np.all(scatter._mpl_artists['scatter'].get_alpha() == 0.5)

# test alpha reset when new data is set
scatter.data = np.random.rand(size, 2)
assert np.all(scatter._scatter.get_alpha() == 1.0)
assert np.all(scatter._mpl_artists['scatter'].get_alpha() == 1.0)

# Test changing overlay_colormap
assert scatter.overlay_colormap.name == "cat10_modified"
Expand All @@ -98,7 +98,7 @@ def on_color_indices_changed(color_indices):

# Test scatter color indices after continuous overlay_colormap
scatter.color_indices = np.linspace(0, 1, size)
colors = scatter._scatter.get_facecolors()
colors = scatter._mpl_artists['scatter'].get_facecolors()
assert np.all(colors[0] == plt.cm.viridis(0))

# Test scatter color_normalization_method
Expand Down Expand Up @@ -181,7 +181,7 @@ def on_color_indices_changed(color_indices):
assert histogram.cmin == 0

# Test overlay colors
overlay_array = histogram._overlay_histogram_image.get_array()
overlay_array = histogram._mpl_artists['overlay_histogram_image'].get_array()
assert overlay_array.shape == (bins, bins, 4)
# indices where overlay_array is not zero
indices = np.where(overlay_array[..., -1] != 0)
Expand Down Expand Up @@ -229,7 +229,7 @@ def on_color_indices_changed(color_indices):

# Don't draw overlay histogram if color_indices are nan
histogram.color_indices = np.nan
assert histogram._overlay_histogram_image is None
assert 'overlay_histogram_image' not in histogram._mpl_artists.keys()


# Test calculate_statistic_histogram_method for different statistics
Expand All @@ -245,43 +245,3 @@ def on_color_indices_changed(color_indices):
[[0.0, np.nan, np.nan], [np.nan, 3.0, np.nan], [np.nan, np.nan, 7.5]]
),
]


@pytest.mark.parametrize(
"statistic,expected_array",
zip(statistics, expected_results),
ids=statistics,
)
def test_calculate_statistic_histogram_method(statistic, expected_array):
input_xy_data = np.array(
[
[1, 2],
[3, 4],
[3, 5],
[4, 5],
[5, 6],
[6, 7],
]
)
bins = 3
input_features = np.array([0, 1, 2, 6, 7, 8])

expected_histogram_array = np.array(
[[1.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 2.0]]
)

histogram = Histogram2D(data=input_xy_data, bins=bins)
histogram_array, x_edges, y_edges = histogram.histogram
assert np.all(histogram_array == expected_histogram_array)
# Get the bin index for each x value ( -1 to start from index 0 and clip to handle edge cases)
x_bin_indices = (
np.digitize(input_xy_data[:, 0], x_edges, right=False) - 1
).clip(0, len(x_edges) - 2)
# Get the bin index for each y value ( -1 to start from index 0 and clip to handle edge cases)
y_bin_indices = (
np.digitize(input_xy_data[:, 1], y_edges, right=False) - 1
).clip(0, len(y_edges) - 2)
result = histogram._calculate_statistic_histogram(
x_bin_indices, y_bin_indices, input_features, statistic=statistic
)
assert np.array_equal(result, expected_array, equal_nan=True)
Loading