Skip to content

Commit f2b2b2e

Browse files
Copilotcvanelteren
andauthored
Fix edgecolor not set on scatter plots with single-row DataFrame data (#325)
* Initial plan * Initial analysis of edgecolor issue - found root cause in _from_data function Co-authored-by: cvanelteren <[email protected]> * Fix edgecolor issue for scatter plots with single-row DataFrame data Co-authored-by: cvanelteren <[email protected]> * Add pytest.mark.mpl_image_compare decorator to test_scatter_edgecolor_single_row Co-authored-by: cvanelteren <[email protected]> * Format code with black Co-authored-by: cvanelteren <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: cvanelteren <[email protected]>
1 parent b99506d commit f2b2b2e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

ultraplot/internals/inputs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def _from_data(data, *args):
247247
if data is None:
248248
return
249249
args = list(args)
250+
found_in_data = False
250251
for i, arg in enumerate(args):
251252
if isinstance(arg, str):
252253
try:
@@ -255,6 +256,13 @@ def _from_data(data, *args):
255256
pass
256257
else:
257258
args[i] = array
259+
found_in_data = True
260+
261+
# If only one argument and it wasn't found in data, return the original scalar
262+
# This prevents scalar values like "none" from becoming ["none"]
263+
if len(args) == 1 and not found_in_data:
264+
return args[0]
265+
258266
return args
259267

260268

ultraplot/tests/test_1dplots.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,46 @@ def test_scatter_args(rng):
295295
return fig
296296

297297

298+
@pytest.mark.mpl_image_compare
299+
def test_scatter_edgecolor_single_row():
300+
"""
301+
Test that edgecolor is properly handled for single-row DataFrame input.
302+
This is a regression test for issue #324.
303+
"""
304+
import pandas as pd
305+
306+
# Create test data
307+
df_multi = pd.DataFrame({"x": [1, 2], "y": [1, 2], "sizes": [300, 300]})
308+
df_single = pd.DataFrame({"x": [2], "y": [2], "sizes": [300]})
309+
310+
fig, axs = uplt.subplots(ncols=3, share=0)
311+
312+
# Test multiple rows with alpha
313+
result1 = axs[0].scatter(
314+
"x", "y", s="sizes", data=df_multi, fc="red8", ec="none", alpha=1
315+
)
316+
317+
# Test single row with alpha (the problematic case)
318+
result2 = axs[1].scatter(
319+
"x", "y", s="sizes", data=df_single, fc="red8", ec="none", alpha=1
320+
)
321+
322+
# Test single row without alpha
323+
result3 = axs[2].scatter("x", "y", s="sizes", data=df_single, fc="red8", ec="none")
324+
325+
# Verify that edgecolors are correctly set to no edges for all cases
326+
# An empty array means no edges (which is what 'none' should produce)
327+
assert len(result1.get_edgecolors()) == 0, "Multiple rows should have no edges"
328+
assert (
329+
len(result2.get_edgecolors()) == 0
330+
), "Single row with alpha should have no edges"
331+
assert (
332+
len(result3.get_edgecolors()) == 0
333+
), "Single row without alpha should have no edges"
334+
335+
return fig
336+
337+
298338
@pytest.mark.mpl_image_compare
299339
def test_scatter_inbounds():
300340
"""

0 commit comments

Comments
 (0)