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
4 changes: 2 additions & 2 deletions src/maxplotlib/backends/tikzfigure/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/maxplotlib/tests/test_tikzfigure_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Loading