ignore all matplotlib PathPatch() errors, fixes
@@ -12,6 +12,7 @@ from typing import (
)
from collections import defaultdict
from functools import lru_cache
+import logging
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
@@ -38,6 +39,7 @@ from .line_renderer import AbstractLineRenderer
if TYPE_CHECKING:
from ezdxf.eztypes import Layout
+logger = logging.getLogger("ezdxf")
# matplotlib docs: https://matplotlib.org/index.html
# line style:
@@ -161,7 +163,7 @@ class MatplotlibBackend(Backend):
v1, c1 = _get_path_patch_data(hole)
vertices.extend(v1)
codes.extend(c1)
-
+ try:
patch = PathPatch(
Path(vertices, codes),
color=properties.color,
@@ -170,6 +172,11 @@ class MatplotlibBackend(Backend):
hatch=hatch,
zorder=self._get_z(),
)
+ except ValueError as e:
+ logger.info(
+ f"ignored matplotlib error in draw_filled_paths(): {str(e)}"
+ )
+ else:
self.ax.add_patch(patch)
def draw_filled_polygon(
@@ -206,14 +213,17 @@ class MatplotlibBackend(Backend):
)
@ transform,
)
- self.ax.add_patch(
- PathPatch(
+ try:
+ patch = PathPatch(
transformed_path,
facecolor=properties.color,
linewidth=0,
zorder=self._get_z(),
)
- )
+ except ValueError as e:
+ logger.info(f"ignored matplotlib error in draw_text(): {str(e)}")
+ else:
+ self.ax.add_patch(patch)
def get_font_properties(
self, font: Optional[fonts.FontFace]
@@ -559,6 +569,7 @@ class InternalLineRenderer(MatplotlibLineRenderer):
def draw_path(self, path, properties: Properties, z: float):
vertices, codes = _get_path_patch_data(path)
+ try:
patch = PathPatch(
Path(vertices, codes),
linewidth="solid"
@@ -569,6 +580,9 @@ class InternalLineRenderer(MatplotlibLineRenderer):
color=properties.color,
zorder=z,
)
+ except ValueError as e:
+ logger.info(f"ignored matplotlib error: {str(e)}")
+ else:
self.ax.add_patch(patch)
@property
@@ -638,6 +652,7 @@ class EzdxfLineRenderer(MatplotlibLineRenderer):
color = properties.color
if len(pattern) < 2:
vertices, codes = _get_path_patch_data(path)
+ try:
patch = PathPatch(
Path(vertices, codes),
linewidth=lineweight,
@@ -645,6 +660,11 @@ class EzdxfLineRenderer(MatplotlibLineRenderer):
fill=False,
zorder=z,
)
+ except ValueError as e:
+ logger.info(
+ f"ignored matplotlib error in draw_path(): {str(e)}"
+ )
+ else:
self.ax.add_patch(patch)
else:
renderer = EzdxfLineTypeRenderer(pattern)
