[Matplotlib-devel] What is draw_path's transform's destination?

Rob McDonald rob.a.mcdonald at gmail.com
Sun Mar 31 01:30:26 EDT 2019

On Sat, Mar 30, 2019 at 11:51 PM Rob McDonald <rob.a.mcdonald at gmail.com>

> Unfortunately, naively passing path_effects=[HatchedStroke()] to a
> plt.contour() call doesn't 'just work'.  Is there a way to tell contour
> lines to be drawn with a different path effect?
OK -- so I made some progress on this...

cp = plt.contour(x, y, z, colors=('k',), )
plt.setp(cp.collections, path_effects=[HatchedStroke()])

By and large works.  However, some of the hatches appear 'off' the lines.
I believe this is because some of the contour Path's might be generated as
Bezier curves (not simple polylines).  I need to interpolate along the path
to generate hatches, but I don't have a full renderer -- and
Path.interpolate doesn't do curves.  I currently do the following to get to

newpath = tpath.cleaned()
polys = newpath.to_polygons(closed_only=False)

Which generally works, but the default settings (deep inside agg from what
I can tell (agg_curves.cpp etc.)) produce very coarse approximations that
are rather unsatisfying.

Is there a better way to get a polyline from an arbitrary Path (that may
include Bezier curves)?  Someone has to have implemented a compound path
evaluation routine...

Alternately, is there a way to force contour to generate straight-line
segments -- forcing the user to bump up the grid resolution if they want
smooth curves?   Actually, that doesn't work.  I currently have an example
with very fine resolution -- it appears that something in the Contour Path
hierarchy is being clever and replacing the polyline segments with a smooth
Bezier curve.  Possibly via a simplify call -- if there isn't a way to
evaluate the true Path in draw_path, then perhaps there is a way to turn
off the simplify step contour is doing...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20190331/b5c149d9/attachment.html>

More information about the Matplotlib-devel mailing list