After copying a contour plot from MATLAB into Illustrator, I am stuck with thousands of short unconnected paths (see image below). This makes for a very slow performance and very large file size.

Directly selecting everything and using the simplify tool does not work, since the paths need to be joined first somehow.

I could manually trace them with the lasso tool, join them into one path, and then use the simplify tool. This is however very cumbersome, given the number of contour lines and their shape.

I would like to know if someone knows a (semi-)automatic way of joining all these small paths into large continuous paths so I can use the simplify tool a posteriori.


contours after importing from MATLAB

  • Btw this is one of the reasons why i use mathematica. – joojaa Mar 9 '20 at 16:35
  • Did you try to connect them using Ctrl+J before? – LeoNas Mar 9 '20 at 17:27
  • Also, did you try to export the selection to eps and open it in Illustrator? – LeoNas Mar 9 '20 at 17:31
  • Have you tried selecting all and joining? Illustrator can be smart enough to join multiple paths in a selection based on where anchor points fall. Sometimes works, sometimes doesn't. – Scott Mar 9 '20 at 21:28

I guess you have tried to select all & press Ctrl+J to join the line segments and the result was a bizarre mess because tens of randomly crossing new line segments were generated.

As another approach draw horizontal closing lines to the top and bottom edges, fill areas with the Shape Builder. Select proper new strokes. Fill only every 2nd area. An example:

enter image description here

In the left the magenta curves can be combined of numerous line segments. The black lines are drawn to cross them so that closed areas are formed.

All is selected. The Shape Builder tool is clicked, no stroke+blue fill is set, half of the areas are filled

The generated compound paths are released, every group is ungrouped, no fill + green stroke is set, every horizontal line segment is selected with the direct selection tool one by one and deleted.

Releasing compound paths and ungrouping was repeated (after selecting all) until they became greyed in Object > Ungroup and Object > Compound Path > Release

The green curves are continuous, they can be simplified if that's needed.

  • Thanks for your detailed answer. Although a valid procedure, in practice this is undoable. Every time I fill one of the areas, the shape builder takes about 45 minutes to finish that task (on a mid-2015 MacBook Pro with 16GB RAM)... At the end I found an intermediate solution in which I export the original file to a high-res png, then open this with illustrator and use the image tracer tool to get a simplified version of the contour plots. Works ok but requires quite a bit of tweaking. Anyhow, MATLAB really does a shitty job rendering the contour plot as a collection of 100000 short lines... – wrsc Mar 13 '20 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.