Fix conversion of matplotlib contour lines - #5770
robertoffmoura wants to merge 5 commits into
Conversation
camdecoster
left a comment
There was a problem hiding this comment.
This looks good and seems like a fine solution. I added a few comments/questions about potential improvements.
Could you please add a changelog entry?
There was a problem hiding this comment.
Could you please add a test for the None separators as described in the PR description?
| def per_path(colors, i, default): | ||
| if isinstance(colors, str): | ||
| return colors | ||
| if colors is None: | ||
| return default | ||
| try: | ||
| n = len(colors) | ||
| except TypeError: | ||
| return colors | ||
| return colors[i % n] if n else default |
There was a problem hiding this comment.
This helper function looks like the same one from _draw_filled_path_collection. Could you move it up a level and reuse it in both locations?
| line=go.scatter.Line( | ||
| color=_export_color(edgecolor), width=linewidth | ||
| ), |
There was a problem hiding this comment.
Will this handle dash styles?
What about turning off legend display? I think that came up in another PR.
| "collections linked to 'data' coordinates" | ||
| ) | ||
|
|
||
| def _draw_line_collection(self, props): |
There was a problem hiding this comment.
This function currently draws one trace per path. What do you think of updating it to group consecutive same-style lines together into one trace? That would cut down on the number of traces (and make a legend less noisy).
mpl_to_plotlydoesn't render contour lines correctly. Matplotlib packs each contour level into a single path containing several disjoint subpaths, so the converted figure connects them with segments that shouldn't exist, and closed rings are left open because theCLOSEPOLYvertex is dropped on export:Fix: path collections with no face colors (line collections, which is what
ax.contourproduces) are now drawn as line traces instead of filled polygons:None, so plotly does not connect themZcode have their first vertex appended to close the ringC,S) consume the correct number of vertices while parsingSnippet to reproduce: