diff --git a/src/maxplotlib/backends/tikzfigure/convert.py b/src/maxplotlib/backends/tikzfigure/convert.py index 3122f5e..9a1515f 100644 --- a/src/maxplotlib/backends/tikzfigure/convert.py +++ b/src/maxplotlib/backends/tikzfigure/convert.py @@ -1018,8 +1018,6 @@ def emit(): return emit def _text(self, text): - if not text.get_text().strip(): - return lambda: None if isinstance(text, Annotation): text.update_positions(self.figure._get_renderer()) arrow = ( @@ -1030,6 +1028,8 @@ def _text(self, text): arrow_emit = self._patch(arrow, clip=False) if arrow_emit is None: return None + if not text.get_text().strip(): # an arrow without text, or nothing at all + return arrow_emit or (lambda: None) display = _text_display_position(text) if not self.figure.bbox.contains(*display): return arrow_emit or (lambda: None) diff --git a/src/maxplotlib/tests/test_tikzfigure_backend.py b/src/maxplotlib/tests/test_tikzfigure_backend.py index a496fb8..1ccb674 100644 --- a/src/maxplotlib/tests/test_tikzfigure_backend.py +++ b/src/maxplotlib/tests/test_tikzfigure_backend.py @@ -107,6 +107,17 @@ def test_text_and_annotation_arrows_are_not_clipped(): assert re.search(r"\\draw\[.*\] \(axis cs:", tikz), "the arrow is a \\draw" +def test_an_annotation_arrow_without_text_is_kept(): + fig, ax = plt.subplots() + ax.set_xlim(0, 1) + ax.set_ylim(0, 1) + ax.annotate("", xy=(0.9, 0.5), xytext=(0.1, 0.5), arrowprops={"arrowstyle": "<->"}) + ax.text(0.5, 0.5, " ") # blank text draws nothing + tikz = figure_to_tikz(fig).generate_tikz() + assert re.search(r"\\draw\[.*\] \(axis cs:", tikz), "the arrow is a \\draw" + assert "\\node" not in tikz + + def test_far_away_geometry_is_clipped_and_text_outside_the_figure_left_out(): fig, ax = plt.subplots() ax.plot([0, 1e6], [0, 1])