Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-onions-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@e2b/data-extractor': patch
---

Omit blank figures
10 changes: 9 additions & 1 deletion chart_data_extractor/e2b_charts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ def get_chart_from_ax(
return chart


def is_figure_blank(axes: List[Axes]) -> bool:
"""Check if a Matplotlib figure is blank (has no user-added artists)."""
for ax in axes:
if ax.has_data():
return False # The figure contains user-added data
return True # No data found, figure is blank


def chart_figure_to_chart(figure: Figure) -> Optional[Chart]:
"""
This method is used to extract data from the figure object to a dictionary
"""
# Get all Axes objects from the Figure
axes = figure.get_axes()

if not axes:
if not axes or is_figure_blank(axes):
return
elif len(axes) > 1:
return SuperChart(figure=figure)
Expand Down
10 changes: 10 additions & 0 deletions chart_data_extractor/tests/charts/test_blank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import matplotlib.pyplot as plt

from e2b_charts import chart_figure_to_chart
from e2b_charts.charts import BarChart, ChartType


def test_blank_chart():
figure, _ = plt.subplots()
chart = chart_figure_to_chart(figure)
assert chart is None