-
Notifications
You must be signed in to change notification settings - Fork 0
Created fix for handling large jumps in plotted data. Reworked patch … #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
5074f94
011ded9
991eb37
0e030ad
13e2a19
28f843d
eea2b0d
f973c50
1fcd5e2
0660a7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,8 +140,19 @@ def _clip_mpl(self, gc, vertices, obj): | |
| line = LineString(vertices) | ||
| try: | ||
| intersection = line.intersection(cliprect) | ||
| except: | ||
| intersection = Polygon() | ||
| except Exception: | ||
| # Fix plotted values with large gaps/jumps crashing the intersection function | ||
| gap_threshold = 50 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's a good idea to use a hard coded value here. If we have plots ranging between 0 and 2000, for example the pore pressure in a CPT, a gap threshold of 50 is quite small. |
||
| smoothed_vertices = [vertices[0]] # Start with the first point | ||
| for i in range(1, len(vertices)): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use np.diff to compute this more effectively, and filter using np.where. |
||
| if ( | ||
| abs(vertices[i][0] - vertices[i - 1][0]) <= gap_threshold | ||
| and abs(vertices[i][1] - vertices[i - 1][1]) | ||
| <= gap_threshold | ||
| ): | ||
| smoothed_vertices.append(vertices[i]) | ||
| line = LineString(smoothed_vertices) | ||
| intersection = line.intersection(cliprect) | ||
|
|
||
| # Check if intersection is a multi-part geometry | ||
| if intersection.is_empty: | ||
|
|
@@ -323,17 +334,15 @@ def draw_path_collection( | |
| urls, | ||
| offset_position, | ||
| ): | ||
| if self._groupd[-1] == "PolyCollection": | ||
| # Behandle PolyCollection som en samling av 'patch'-objekter | ||
| for path in paths: | ||
| # Kombiner master_transform med path_transform for hver path | ||
| for i, path in enumerate(paths): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Has this been reverted to an old version of the code?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for this change?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I tried to figure out where the failure happend, I tried some different approaches and that we didnt handle all_transforms was one thing I was looking into.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I figured out it actually fixed a bug as well! |
||
| if all_transforms: | ||
| combined_transform = master_transform + all_transforms[i] | ||
| else: | ||
| combined_transform = master_transform | ||
| # Her kan du velge å bruke eller tilpasse rgbFace basert på facecolors, hvis det er relevant | ||
| if facecolors.size: | ||
| rgbFace = facecolors[0] if facecolors is not None else None | ||
| else: | ||
| rgbFace = None | ||
| self._draw_mpl_patch(gc, path, combined_transform, rgbFace) | ||
| facecolor = facecolors[i] if i < len(facecolors) else None | ||
| edgecolor = edgecolors[i] if i < len(edgecolors) else None | ||
| # Draw each path as a filled patch | ||
| self._draw_mpl_patch(gc, path, combined_transform, rgbFace=facecolor) | ||
|
|
||
| def draw_path(self, gc, path, transform, rgbFace=None): | ||
| # print('\nEntered ###DRAW_PATH###') | ||
|
|
@@ -352,7 +361,6 @@ def draw_path(self, gc, path, transform, rgbFace=None): | |
| elif self._groupd[-1] == "line2d": | ||
| line = self._draw_mpl_line2d(gc, path, transform) | ||
|
|
||
| # Note if this is used then tick marks and lines with markers go through this function | ||
| def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None): | ||
| # print('\nEntered ###DRAW_MARKERS###') | ||
| # print('\t', self._groupd) | ||
|
|
@@ -479,6 +487,21 @@ def new_gc(self): | |
| def points_to_pixels(self, points): | ||
| return points / 72.0 * self.dpi | ||
|
|
||
| def draw_quad_mesh( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for this change? Do we need it?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I tried to figure out where the failure happend, I tried some different approaches and figured out that we didnt handle quad mesh, so I set up some of the entities we didnt handle to see what wass passed to them. |
||
| self, | ||
| gc, | ||
| master_transform, | ||
| meshWidth, | ||
| meshHeight, | ||
| coordinates, | ||
| offsets, | ||
| offsetTrans, | ||
| facecolors, | ||
| antialiased, | ||
| edgecolors, | ||
| ): | ||
| pass | ||
|
|
||
|
|
||
| class FigureCanvasDxf(FigureCanvasBase): | ||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we catch a more specific Exception here? Generally, it is considered bad practice to have try/except without specifying the exact exception you are expecting.